]> git.lyx.org Git - features.git/blob - src/LayoutFile.h
fe865322667ed83b3500ba7af7d1a13aaaf0f781
[features.git] / src / LayoutFile.h
1 // -*- C++ -*-
2 /**
3  * \file LayoutFile.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Richard Heck (typedefs and such)
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef BASECLASSLIST_H
14 #define BASECLASSLIST_H
15
16 #include "LayoutModuleList.h"
17 #include "TextClass.h"
18
19 #include "support/strfwd.h"
20
21 #include <string>
22 #include <vector>
23
24
25 namespace lyx {
26
27 /// Index into LayoutFileList. Basically a 'strong typedef'.
28 class LayoutFileIndex {
29 public:
30         ///
31         typedef std::string base_type;
32         ///
33         LayoutFileIndex(base_type const & t) : data_(t) { }
34         ///
35         operator base_type() const { return data_; }
36         ///
37         bool empty() const { return data_.empty(); }
38 private:
39         base_type data_;
40 };
41
42 /// This class amounts to little more than a `strong typedef'.
43 ///
44 /// A LayoutFile represents the layout information that is
45 /// contained in a *.layout file.
46 ///
47 /// No document- (that is, Buffer-) specific information should
48 /// be placed in these objects. They are used as the basis for
49 /// constructing DocumentClass objects, which are what represent
50 /// the layout information associated with a Buffer. (This is also
51 /// a subclass of TextClass, implemented in TextClass.{h,cpp}.)
52 /// Buffer-specific information should therefore be placed in a
53 /// DocumentClass object.
54 ///
55 class LayoutFile : public TextClass {
56 public:
57         /// check whether the TeX class is available
58         bool isTeXClassAvailable() const { return tex_class_avail_; }
59         ///
60         LayoutModuleList const & defaultModules() const
61                         { return default_modules_; }
62         ///
63         LayoutModuleList const & providedModules() const
64                         { return provided_modules_; }
65         ///
66         LayoutModuleList const & excludedModules() const
67                         { return excluded_modules_; }
68 private:
69         /// noncopyable
70         LayoutFile(LayoutFile const &);
71         void operator=(LayoutFile const &);
72         /// Construct a layout with default values. Actual values loaded later.
73         explicit LayoutFile(std::string const & filename,
74                         std::string const & className = std::string(),
75                         std::string const & description = std::string(),
76                         std::string const & prerequisites = std::string(),
77                         std::string const & category = std::string(),
78                         bool texclassavail = false);
79         /// The only class that should create a LayoutFile is
80         /// LayoutFileList, which calls the private constructor.
81         friend class LayoutFileList;
82         /// can't create empty LayoutFile
83         LayoutFile() {}
84 };
85
86
87 /// A list of base document classes (*.layout files).
88 /// This is a singleton class. The sole instance is accessed
89 /// via LayoutFileList::get()
90 class LayoutFileList {
91 public:
92         ///
93         ~LayoutFileList();
94         /// \return The sole instance of this class.
95         static LayoutFileList & get();
96         ///
97         bool empty() const { return classmap_.empty(); }
98         ///
99         bool haveClass(std::string const & classname) const;
100         /// Note that this will assert if we don't have classname, so
101         /// check via haveClass() first.
102         LayoutFile const & operator[](std::string const & classname) const;
103         /// Note that this will assert if we don't have classname, so
104         /// check via haveClass() first.
105         LayoutFile & operator[](std::string const & classname);
106         /// Read textclass list. Returns false if this fails.
107         bool read();
108         /// Clears the textclass so as to force it to be reloaded
109         void reset(LayoutFileIndex const & tc);
110
111         /// Add a default textclass with all standard layouts.
112         /// Note that this will over-write any information we may have
113         /// gotten from textclass.lst about this class.
114         LayoutFileIndex addEmptyClass(std::string const & textclass);
115
116         /// add a textclass from user local directory.
117         /// \return the identifier for the loaded file, or else an
118         /// empty string if no file was loaded.
119         LayoutFileIndex addLocalLayout(std::string const & textclass,
120                                        std::string const & path,
121                                        std::string const & oldpath = empty_string());
122         /// a list of the available classes
123         std::vector<LayoutFileIndex> classList() const;
124
125         ///
126         bool load(std::string const & name, std::string const & buf_path);
127
128 private:
129         ///
130         LayoutFileList() {}
131         ///
132         typedef std::map<std::string, LayoutFile *> ClassMap;
133         /// noncopyable
134         LayoutFileList(LayoutFileList const &);
135         /// nonassignable
136         void operator=(LayoutFileList const &);
137         ///
138         mutable ClassMap classmap_; //FIXME
139 };
140
141 ///
142 LayoutFileIndex defaultBaseclass();
143
144
145 } // namespace lyx
146
147 #endif