]> git.lyx.org Git - lyx.git/blob - src/converter.h
The Movers patch.
[lyx.git] / src / converter.h
1 // -*- C++ -*-
2 /**
3  * \file converter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Dekel Tsur
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef CONVERTER_H
13 #define CONVERTER_H
14
15 #include "graph.h"
16 #include "outputparams.h"
17
18 #include <vector>
19 #include <string>
20
21
22 class Buffer;
23 class Format;
24 class Formats;
25 class OutputParams;
26
27
28 ///
29 class Converter {
30 public:
31         ///
32         Converter(std::string const & f, std::string const & t, std::string const & c,
33                   std::string const & l);
34         ///
35         void readFlags();
36         ///
37         std::string from;
38         ///
39         std::string to;
40         ///
41         std::string command;
42         ///
43         std::string flags;
44         ///
45         Format const * From;
46         ///
47         Format const * To;
48
49         /// The converter is latex or its derivatives
50         bool latex;
51         /// The converter is xml
52         bool xml;
53         /// Do we need to run the converter in the original directory?
54         bool original_dir;
55         /// This converter needs the .aux files
56         bool need_aux;
57         /// If the converter put the result in a directory, then result_dir
58         /// is the name of the directory
59         std::string result_dir;
60         /// If the converter put the result in a directory, then result_file
61         /// is the name of the main file in that directory
62         std::string result_file;
63         /// Command to convert the program output to a LaTeX log file format
64         std::string parselog;
65 };
66
67
68 ///
69 class Converters {
70 public:
71         ///
72         typedef std::vector<int> EdgePath; // to be removed SOON
73         ///
74         typedef std::vector<Converter> ConverterList;
75         ///
76         typedef ConverterList::const_iterator const_iterator;
77         ///
78         Converter const & get(int i) const {
79                 return converterlist_[i];
80         }
81         ///
82         Converter const * getConverter(std::string const & from,
83                                        std::string const & to) const;
84         ///
85         int getNumber(std::string const & from, std::string const & to) const;
86         ///
87         void add(std::string const & from, std::string const & to,
88                  std::string const & command, std::string const & flags);
89         //
90         void erase(std::string const & from, std::string const & to);
91         ///
92         void sort();
93         ///
94         std::vector<Format const *> const
95         getReachableTo(std::string const & target, bool clear_visited);
96         ///
97         std::vector<Format const *> const
98         getReachable(std::string const & from, bool only_viewable,
99                      bool clear_visited);
100         ///
101         bool isReachable(std::string const & from, std::string const & to);
102         ///
103         Graph::EdgePath const getPath(std::string const & from, std::string const & to);
104         ///
105         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
106         ///
107         bool convert(Buffer const * buffer,
108                      std::string const & from_file, std::string const & to_file_base,
109                      std::string const & from_format, std::string const & to_format,
110                      std::string & to_file);
111         ///
112         bool convert(Buffer const * buffer,
113                      std::string const & from_file, std::string const & to_file_base,
114                      std::string const & from_format, std::string const & to_format);
115         ///
116         void update(Formats const & formats);
117         ///
118         void updateLast(Formats const & formats);
119         ///
120         bool formatIsUsed(std::string const & format);
121         ///
122         const_iterator begin() const {
123                 return converterlist_.begin();
124         }
125         const_iterator end() const {
126                 return converterlist_.end();
127         }
128         ///
129         void buildGraph();
130 private:
131         ///
132         std::vector<Format const *> const
133         intToFormat(std::vector<int> const & input);
134         ///
135         bool scanLog(Buffer const & buffer, std::string const & command,
136                      std::string const & filename);
137         ///
138         bool runLaTeX(Buffer const & buffer, std::string const & command,
139                       OutputParams const &);
140         ///
141         ConverterList converterlist_;
142         ///
143         std::string latex_command_;
144         ///
145         bool move(std::string const & fmt,
146                   std::string const & from, std::string const & to,
147                   bool copy);
148         ///
149         Graph G_;
150 };
151
152 extern Converters converters;
153
154 extern Converters system_converters;
155
156 #endif //CONVERTER_H