]> git.lyx.org Git - lyx.git/blob - src/format.h
do not define boost::throw_exceptions if we are compiling with exceptions
[lyx.git] / src / format.h
1 // -*- C++ -*-
2 /**
3  * \file format.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 FORMAT_H
13 #define FORMAT_H
14
15 #include <vector>
16 #include <string>
17
18 class Buffer;
19
20 class Format {
21 public:
22         ///
23         Format(std::string const & n, std::string const & e, std::string const & p,
24                std::string const & s, std::string const & v, std::string const & ed);
25         ///
26         bool dummy() const;
27         ///
28         bool isChildFormat() const;
29         ///
30         std::string const parentFormat() const;
31         ///
32         std::string const & name() const {
33                 return name_;
34         }
35         ///
36         std::string const & extension() const {
37                 return extension_;
38         }
39         ///
40         std::string const & prettyname() const {
41                 return prettyname_;
42         }
43         ///
44         std::string const & shortcut() const {
45                 return shortcut_;
46         }
47         ///
48         std::string const & viewer() const {
49                 return viewer_;
50         }
51         ///
52         void setViewer(std::string const & v) {
53                 viewer_ = v;
54         }
55         ///
56         std::string const & editor() const {
57                 return editor_;
58         }
59 private:
60         std::string name_;
61         ///
62         std::string extension_;
63         ///
64         std::string prettyname_;
65         ///
66         std::string shortcut_;
67         ///
68         std::string viewer_;
69         ///
70         std::string editor_;
71 };
72
73
74 bool operator<(Format const & a, Format const & b);
75
76 ///
77 class Formats {
78 public:
79         ///
80         typedef std::vector<Format> FormatList;
81         ///
82         typedef FormatList::const_iterator const_iterator;
83         ///
84         Format const & get(FormatList::size_type i) const {
85                 return formatlist[i];
86         }
87         /// \returns format named \p name if it exists, otherwise 0
88         Format const * getFormat(std::string const & name) const;
89         /*!
90          * Get the format of \p filename from file contents or, if this
91          * fails, from file extension.
92          * \returns file format if it could be found, otherwise an empty
93          * string.
94          */
95         std::string getFormatFromFile(std::string const & filename) const;
96         ///
97         int getNumber(std::string const & name) const;
98         ///
99         void add(std::string const & name);
100         ///
101         void add(std::string const & name, std::string const & extension,
102                  std::string const & prettyname, std::string const & shortcut,
103                  std::string const & viewer, std::string const & editor);
104         ///
105         void erase(std::string const & name);
106         ///
107         void sort();
108         ///
109         void setViewer(std::string const & name, std::string const & command);
110         ///
111         bool view(Buffer const & buffer, std::string const & filename,
112                   std::string const & format_name) const;
113         ///
114         bool edit(Buffer const & buffer, std::string const & filename,
115                   std::string const & format_name) const;
116         ///
117         std::string const prettyName(std::string const & name) const;
118         ///
119         std::string const extension(std::string const & name) const;
120         ///
121         const_iterator begin() const {
122                 return formatlist.begin();
123         }
124         ///
125         const_iterator end() const {
126                 return formatlist.end();
127         }
128         ///
129         FormatList::size_type size() const {
130                 return formatlist.size();
131         }
132 private:
133         ///
134         FormatList formatlist;
135 };
136
137 extern Formats formats;
138
139 extern Formats system_formats;
140
141 #endif //FORMAT_H