]> git.lyx.org Git - lyx.git/blob - src/Converter.h
Rename .C ==> .cpp for files in src/support, part two
[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 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 converter is xml
57         bool xml;
58         /// Do we need to run the converter in the original directory?
59         bool original_dir;
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<int> EdgePath; // to be removed SOON
78         ///
79         typedef std::vector<Converter> ConverterList;
80         ///
81         typedef ConverterList::const_iterator const_iterator;
82         ///
83         Converter const & get(int i) const {
84                 return converterlist_[i];
85         }
86         ///
87         Converter const * getConverter(std::string const & from,
88                                        std::string const & to) const;
89         ///
90         int getNumber(std::string const & from, std::string const & to) const;
91         ///
92         void add(std::string const & from, std::string const & to,
93                  std::string const & command, std::string const & flags);
94         //
95         void erase(std::string const & from, std::string const & to);
96         ///
97         void sort();
98         ///
99         std::vector<Format const *> const
100         getReachableTo(std::string const & target, bool clear_visited);
101         ///
102         std::vector<Format const *> const
103         getReachable(std::string const & from, bool only_viewable,
104                      bool clear_visited);
105         /// Does a conversion path from format \p from to format \p to exist?
106         bool isReachable(std::string const & from, std::string const & to);
107         ///
108         Graph::EdgePath const getPath(std::string const & from, std::string const & to);
109         ///
110         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
111         /// Flags for converting files
112         enum ConversionFlags {
113                 /// No special flags
114                 none = 0,
115                 /// Use the default converter if no converter is defined
116                 try_default = 1 << 0,
117                 /// Get the converted file from cache if possible
118                 try_cache = 1 << 1
119         };
120         ///
121         bool convert(Buffer const * buffer,
122                      support::FileName const & from_file, support::FileName const & to_file,
123                      support::FileName const & orig_from,
124                      std::string const & from_format, std::string const & to_format,
125                      ErrorList & errorList, int conversionflags = none);
126         ///
127         void update(Formats const & formats);
128         ///
129         void updateLast(Formats const & formats);
130         ///
131         bool formatIsUsed(std::string const & format);
132         ///
133         const_iterator begin() const {
134                 return converterlist_.begin();
135         }
136         const_iterator end() const {
137                 return converterlist_.end();
138         }
139         ///
140         void buildGraph();
141 private:
142         ///
143         std::vector<Format const *> const
144         intToFormat(std::vector<int> const & input);
145         ///
146         bool scanLog(Buffer const & buffer, std::string const & command,
147                      support::FileName const & filename, ErrorList & errorList);
148         ///
149         bool runLaTeX(Buffer const & buffer, std::string const & command,
150                       OutputParams const &, ErrorList & errorList);
151         ///
152         ConverterList converterlist_;
153         ///
154         std::string latex_command_;
155         /// If \p from = /path/file.ext and \p to = /path2/file2.ext2 then
156         /// this method moves each /path/file*.ext file to /path2/file2*.ext2
157         bool move(std::string const & fmt,
158                   support::FileName const & from, support::FileName const & to,
159                   bool copy);
160         ///
161         Graph G_;
162 };
163
164 /// The global instance.
165 /// Implementation is in LyX.cpp.
166 extern Converters & theConverters();
167
168 /// The global copy after reading lyxrc.defaults.
169 /// Implementation is in LyX.cpp.
170 extern Converters & theSystemConverters();
171
172 } // namespace lyx
173
174 #endif //CONVERTER_H