]> git.lyx.org Git - lyx.git/blob - src/Converter.h
Fix compiler warnings spotted by Uwe
[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 #include "support/trivstring.h"
18
19 #include <vector>
20 #include <set>
21 #include <string>
22
23
24 namespace lyx {
25
26 namespace support { class FileName; }
27
28 class Buffer;
29 class ErrorList;
30 class Format;
31 class Formats;
32
33 typedef std::vector<Format const *> FormatList;
34
35
36 ///
37 class Converter {
38 public:
39         ///
40         Converter(std::string const & f, std::string const & t, std::string const & c,
41                   std::string const & l);
42         ///
43         void readFlags();
44         ///
45         std::string const from() const { return from_; }
46         ///
47         std::string const to() const { return to_; }
48         ///
49         std::string const command() const { return command_; }
50         ///
51         void setCommand(std::string const & command) { command_ = command; }
52         ///
53         std::string const flags() const { return flags_; }
54         ///
55         void setFlags(std::string const & flags) { flags_ = flags; }
56         ///
57         Format const * From() const { return From_; }
58         ///
59         void setFrom(Format const * From) { From_ = From; }
60         ///
61         void setTo(Format const * To) { To_ = To; }
62         ///
63         Format const * To() const { return To_; }
64         ///
65         bool latex() const { return latex_; }
66         ///
67         std::string const latex_flavor() const { return latex_flavor_; }
68         ///
69         bool xml() const { return xml_; }
70         ///
71         bool need_aux() const { return need_aux_; }
72         ///
73         bool nice() const { return nice_; }
74         ///
75         std::string const result_dir() const { return result_dir_; }
76         ///
77         std::string const result_file() const { return result_file_; }
78         ///
79         std::string const parselog() const { return parselog_; }
80 private:
81         ///
82         trivstring from_;
83         ///
84         trivstring to_;
85         ///
86         trivstring command_;
87         ///
88         trivstring flags_;
89         ///
90         Format const * From_;
91         ///
92         Format const * To_;
93
94         /// The converter is latex or its derivatives
95         bool latex_;
96         /// The latex derivate
97         trivstring latex_flavor_;
98         /// The converter is xml
99         bool xml_;
100         /// This converter needs the .aux files
101         bool need_aux_;
102         /// we need a "nice" file from the backend, c.f. OutputParams.nice.
103         bool nice_;
104         /// If the converter put the result in a directory, then result_dir
105         /// is the name of the directory
106         trivstring result_dir_;
107         /// If the converter put the result in a directory, then result_file
108         /// is the name of the main file in that directory
109         trivstring result_file_;
110         /// Command to convert the program output to a LaTeX log file format
111         trivstring parselog_;
112 };
113
114
115 ///
116 class Converters {
117 public:
118         ///
119         typedef std::vector<Converter> ConverterList;
120         ///
121         typedef ConverterList::const_iterator const_iterator;
122
123         ///
124         Converter const & get(int i) const { return converterlist_[i]; }
125         ///
126         Converter const * getConverter(std::string const & from,
127                                        std::string const & to) const;
128         ///
129         int getNumber(std::string const & from, std::string const & to) const;
130         ///
131         void add(std::string const & from, std::string const & to,
132                  std::string const & command, std::string const & flags);
133         //
134         void erase(std::string const & from, std::string const & to);
135         ///
136         FormatList const 
137                 getReachableTo(std::string const & target, bool clear_visited);
138         ///
139         FormatList const
140                 getReachable(std::string const & from, bool only_viewable,
141                     bool clear_visited,
142                     std::set<std::string> const & excludes = std::set<std::string>());
143
144         FormatList importableFormats();
145         FormatList exportableFormats(bool only_viewable);
146
147         std::vector<std::string> loaders() const;
148         std::vector<std::string> savers() const;
149
150         /// Does a conversion path from format \p from to format \p to exist?
151         bool isReachable(std::string const & from, std::string const & to);
152         ///
153         Graph::EdgePath getPath(std::string const & from, std::string const & to);
154         ///
155         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path,
156                                        Buffer const * buffer = 0);
157         /// Flags for converting files
158         enum ConversionFlags {
159                 /// No special flags
160                 none = 0,
161                 /// Use the default converter if no converter is defined
162                 try_default = 1 << 0,
163                 /// Get the converted file from cache if possible
164                 try_cache = 1 << 1
165         };
166         ///
167         bool convert(Buffer const * buffer,
168                      support::FileName const & from_file, support::FileName const & to_file,
169                      support::FileName const & orig_from,
170                      std::string const & from_format, std::string const & to_format,
171                      ErrorList & errorList, int conversionflags = none);
172         ///
173         void update(Formats const & formats);
174         ///
175         void updateLast(Formats const & formats);
176         ///
177         bool formatIsUsed(std::string const & format);
178         ///
179         const_iterator begin() const { return converterlist_.begin(); }
180         ///
181         const_iterator end() const { return converterlist_.end(); }
182         ///
183         void buildGraph();
184 private:
185         ///
186         FormatList const
187         intToFormat(std::vector<int> const & input);
188         ///
189         bool scanLog(Buffer const & buffer, std::string const & command,
190                      support::FileName const & filename, ErrorList & errorList);
191         ///
192         bool runLaTeX(Buffer const & buffer, std::string const & command,
193                       OutputParams const &, ErrorList & errorList);
194         ///
195         ConverterList converterlist_;
196         ///
197         trivstring latex_command_;
198         ///
199         trivstring dvilualatex_command_;
200         ///
201         trivstring lualatex_command_;
202         ///
203         trivstring pdflatex_command_;
204         ///
205         trivstring xelatex_command_;
206         /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
207         /// this method moves each /path/file*.ext file to /path2/file2*.ext2
208         bool move(std::string const & fmt,
209                   support::FileName const & from, support::FileName const & to,
210                   bool copy);
211         ///
212         Graph G_;
213 };
214
215 /// The global instance.
216 /// Implementation is in LyX.cpp.
217 extern Converters & theConverters();
218
219 /// The global copy after reading lyxrc.defaults.
220 /// Implementation is in LyX.cpp.
221 extern Converters & theSystemConverters();
222
223 } // namespace lyx
224
225 #endif //CONVERTER_H