]> git.lyx.org Git - lyx.git/blob - src/converter.h
more cursor dispatch
[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,
81                                        std::string const & to) const;
82         ///
83         int getNumber(std::string const & from, std::string const & to) const;
84         ///
85         void add(std::string const & from, std::string const & to,
86                  std::string const & command, std::string const & flags);
87         //
88         void erase(std::string const & from, std::string const & to);
89         ///
90         void sort();
91         ///
92         std::vector<Format const *> const
93         getReachableTo(std::string const & target, bool clear_visited);
94         ///
95         std::vector<Format const *> const
96         getReachable(std::string const & from, bool only_viewable,
97                      bool clear_visited);
98         ///
99         bool isReachable(std::string const & from, std::string const & to);
100         ///
101         Graph::EdgePath const getPath(std::string const & from, std::string const & to);
102         ///
103         OutputParams::FLAVOR getFlavor(Graph::EdgePath const & path);
104         ///
105         bool convert(Buffer const * buffer,
106                      std::string const & from_file, std::string const & to_file_base,
107                      std::string const & from_format, std::string const & to_format,
108                      std::string & to_file);
109         ///
110         bool convert(Buffer const * buffer,
111                      std::string const & from_file, std::string const & to_file_base,
112                      std::string const & from_format, std::string const & to_format);
113         ///
114         void update(Formats const & formats);
115         ///
116         void updateLast(Formats const & formats);
117         ///
118         bool formatIsUsed(std::string const & format);
119         ///
120         const_iterator begin() const {
121                 return converterlist_.begin();
122         }
123         const_iterator end() const {
124                 return converterlist_.end();
125         }
126         ///
127         void buildGraph();
128 private:
129         ///
130         std::vector<Format const *> const
131         intToFormat(std::vector<int> const & input);
132         ///
133         bool scanLog(Buffer const & buffer, std::string const & command,
134                      std::string const & filename);
135         ///
136         bool runLaTeX(Buffer const & buffer, std::string const & command,
137                       OutputParams const &);
138         ///
139         ConverterList converterlist_;
140         ///
141         std::string latex_command_;
142         ///
143         bool move(std::string const & from, std::string const & to, bool copy);
144         ///
145         Graph G_;
146 };
147
148 extern Converters converters;
149
150 extern Converters system_converters;
151
152 #endif //CONVERTER_H