]> git.lyx.org Git - lyx.git/blob - src/converter.h
801b4c3cbf542a2545324cd383974dfe110ee740
[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         /// Do we need to run the converter in the original directory?
52         bool original_dir;
53         /// This converter needs the .aux files
54         bool need_aux;
55         /// If the converter put the result in a directory, then result_dir
56         /// is the name of the directory
57         std::string result_dir;
58         /// If the converter put the result in a directory, then result_file
59         /// is the name of the main file in that directory
60         std::string result_file;
61         /// Command to convert the program output to a LaTeX log file format
62         std::string parselog;
63 };
64
65
66 ///
67 class Converters {
68 public:
69         ///
70         typedef std::vector<int> EdgePath; // to be removed SOON
71         ///
72         typedef std::vector<Converter> ConverterList;
73         ///
74         typedef ConverterList::const_iterator const_iterator;
75         ///
76         Converter const & get(int i) const {
77                 return converterlist_[i];
78         }
79         ///
80         Converter const * getConverter(std::string const & from, std::string const & to);
81         ///
82         int getNumber(std::string const & from, std::string const & to);
83         ///
84         void add(std::string const & from, std::string const & to,
85                  std::string const & command, std::string const & flags);
86         //
87         void erase(std::string const & from, std::string const & to);
88         ///
89         void sort();
90         ///
91         std::vector<Format const *> const
92         getReachableTo(std::string const & target, bool clear_visited);
93         ///
94         std::vector<Format const *> const
95         getReachable(std::string const & from, bool only_viewable,
96                      bool clear_visited);
97         ///
98         bool isReachable(std::string const & from, std::string const & to);
99         ///
100         Graph::EdgePath const getPath(std::string const & from, std::string const & to);
101         ///
102         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
103         ///
104         bool convert(Buffer const * buffer,
105                      std::string const & from_file, std::string const & to_file_base,
106                      std::string const & from_format, std::string const & to_format,
107                      std::string & to_file);
108         ///
109         bool convert(Buffer const * buffer,
110                      std::string const & from_file, std::string const & to_file_base,
111                      std::string const & from_format, std::string const & to_format);
112         ///
113         void update(Formats const & formats);
114         ///
115         void updateLast(Formats const & formats);
116         ///
117         bool formatIsUsed(std::string const & format);
118         ///
119         const_iterator begin() const {
120                 return converterlist_.begin();
121         }
122         const_iterator end() const {
123                 return converterlist_.end();
124         }
125         ///
126         void buildGraph();
127 private:
128         ///
129         std::vector<Format const *> const
130         intToFormat(std::vector<int> const & input);
131         ///
132         bool scanLog(Buffer const & buffer, std::string const & command,
133                      std::string const & filename);
134         ///
135         bool runLaTeX(Buffer const & buffer, std::string const & command,
136                       OutputParams const &);
137         ///
138         ConverterList converterlist_;
139         ///
140         std::string latex_command_;
141         ///
142         bool move(std::string const & from, std::string const & to, bool copy);
143         ///
144         Graph G_;
145 };
146
147 extern Converters converters;
148
149 extern Converters system_converters;
150
151 #endif //CONVERTER_H