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