]> git.lyx.org Git - lyx.git/blob - src/converter.h
* Painter.h:
[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 namespace lyx {
23
24
25 class Buffer;
26 class ErrorList;
27 class Format;
28 class Formats;
29 class OutputParams;
30
31
32 ///
33 class Converter {
34 public:
35         ///
36         Converter(std::string const & f, std::string const & t, std::string const & c,
37                   std::string const & l);
38         ///
39         void readFlags();
40         ///
41         std::string from;
42         ///
43         std::string to;
44         ///
45         std::string command;
46         ///
47         std::string flags;
48         ///
49         Format const * From;
50         ///
51         Format const * To;
52
53         /// The converter is latex or its derivatives
54         bool latex;
55         /// The converter is xml
56         bool xml;
57         /// Do we need to run the converter in the original directory?
58         bool original_dir;
59         /// This converter needs the .aux files
60         bool need_aux;
61         /// If the converter put the result in a directory, then result_dir
62         /// is the name of the directory
63         std::string result_dir;
64         /// If the converter put the result in a directory, then result_file
65         /// is the name of the main file in that directory
66         std::string result_file;
67         /// Command to convert the program output to a LaTeX log file format
68         std::string parselog;
69 };
70
71
72 ///
73 class Converters {
74 public:
75         ///
76         typedef std::vector<int> EdgePath; // to be removed SOON
77         ///
78         typedef std::vector<Converter> ConverterList;
79         ///
80         typedef ConverterList::const_iterator const_iterator;
81         ///
82         Converter const & get(int i) const {
83                 return converterlist_[i];
84         }
85         ///
86         Converter const * getConverter(std::string const & from,
87                                        std::string const & to) const;
88         ///
89         int getNumber(std::string const & from, std::string const & to) const;
90         ///
91         void add(std::string const & from, std::string const & to,
92                  std::string const & command, std::string const & flags);
93         //
94         void erase(std::string const & from, std::string const & to);
95         ///
96         void sort();
97         ///
98         std::vector<Format const *> const
99         getReachableTo(std::string const & target, bool clear_visited);
100         ///
101         std::vector<Format const *> const
102         getReachable(std::string const & from, bool only_viewable,
103                      bool clear_visited);
104         /// Does a conversion path from format \p from to format \p to exist?
105         bool isReachable(std::string const & from, std::string const & to);
106         ///
107         Graph::EdgePath const getPath(std::string const & from, std::string const & to);
108         ///
109         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
110         ///
111         bool convert(Buffer const * buffer,
112                      std::string const & from_file, std::string const & to_file_base,
113                      std::string const & from_format, std::string const & to_format,
114                      std::string & to_file, ErrorList & errorList,
115                          bool try_default = false);
116         ///
117         bool convert(Buffer const * buffer,
118                      std::string const & from_file, std::string const & to_file_base,
119                      std::string const & from_format, std::string const & to_format,
120                          ErrorList & errorList, bool try_default = false);
121         ///
122         void update(Formats const & formats);
123         ///
124         void updateLast(Formats const & formats);
125         ///
126         bool formatIsUsed(std::string const & format);
127         ///
128         const_iterator begin() const {
129                 return converterlist_.begin();
130         }
131         const_iterator end() const {
132                 return converterlist_.end();
133         }
134         ///
135         void buildGraph();
136 private:
137         ///
138         std::vector<Format const *> const
139         intToFormat(std::vector<int> const & input);
140         ///
141         bool scanLog(Buffer const & buffer, std::string const & command,
142                      std::string const & filename, ErrorList & errorList);
143         ///
144         bool runLaTeX(Buffer const & buffer, std::string const & command,
145                       OutputParams const &, ErrorList & errorList);
146         ///
147         ConverterList converterlist_;
148         ///
149         std::string latex_command_;
150         /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
151         /// this method moves each /path/file*.ext file to /path2/file2*.ext2
152         bool move(std::string const & fmt,
153                   std::string const & from, std::string const & to,
154                   bool copy);
155         ///
156         Graph G_;
157 };
158
159 extern Converters converters;
160
161 extern Converters system_converters;
162
163
164 } // namespace lyx
165
166 #endif //CONVERTER_H