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