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