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