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