]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
847b469435fc9ed99ac90a016e7474f8fe4253de
[lyx.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 <boost/noncopyable.hpp>
22
23 #include <set>
24 #include <string>
25 #include <vector>
26
27
28 namespace lyx {
29
30 class Layout;
31
32 /// Reads the style files
33 extern bool LyXSetStyle();
34
35
36 /// Index into LayoutFileList. Basically a 'strong typedef'.
37 class LayoutFileIndex {
38 public:
39         ///
40         typedef std::string base_type;
41         ///
42         LayoutFileIndex(base_type t) { data_ = t; }
43         ///
44         operator base_type() const { return data_; }
45         ///
46         bool empty() const { return data_.empty(); }
47 private:
48         base_type data_;
49 };
50
51 /// This class amounts to little more than a `strong typedef'.
52 /// 
53 /// A LayoutFile represents the layout information that is 
54 /// contained in a *.layout file.
55 /// 
56 /// No document- (that is, Buffer-) specific information should 
57 /// be placed in these objects. They are used as the basis for 
58 /// constructing DocumentClass objects, which are what represent
59 /// the layout information associated with a Buffer. (This is also 
60 /// a subclass of TextClass, implemented in TextClass.{h,cpp}.)
61 /// Buffer-specific information should therefore be placed in a
62 /// DocumentClass object.
63 /// 
64 class LayoutFile : public TextClass, boost::noncopyable {
65 public:
66         /// check whether the TeX class is available
67         bool isTeXClassAvailable() const { return texClassAvail_; }
68         ///
69         LayoutModuleList const & defaultModules() const 
70                         { return default_modules_; }
71         ///
72         LayoutModuleList const & providedModules() const 
73                         { return provided_modules_; }
74         ///
75         LayoutModuleList const & excludedModules() const 
76                         { return excluded_modules_; }
77 private:
78         /// Construct a layout with default values. Actual values loaded later.
79         explicit LayoutFile(std::string const & filename,
80                         std::string const & className = std::string(),
81                         std::string const & description = std::string(),
82                         bool texClassAvail = false);
83         /// The only class that should create a LayoutFile is
84         /// LayoutFileList, which calls the private constructor.
85         friend class LayoutFileList;
86         /// can't create empty LayoutFile
87         LayoutFile() {};
88 };
89
90
91 /// A list of base document classes (*.layout files).
92 /// This is a singleton class. The sole instance is accessed
93 /// via LayoutFileList::get()
94 class LayoutFileList {
95 public:
96         ///
97         LayoutFileList() {}
98         ///
99         ~LayoutFileList();
100         /// \return The sole instance of this class.
101         static LayoutFileList & get();
102         ///
103         bool empty() const { return classmap_.empty(); }
104         ///
105         bool haveClass(std::string const & classname) const;
106         /// Note that this will assert if we don't have classname, so
107         /// check via haveClass() first.
108         LayoutFile const & operator[](std::string const & classname) const;
109         /// Note that this will assert if we don't have classname, so
110         /// check via haveClass() first.
111         LayoutFile & operator[](std::string const & classname);
112         /// Read textclass list. Returns false if this fails.
113         bool read();
114         /// Clears the textclass so as to force it to be reloaded
115         void reset(LayoutFileIndex const & tc);
116
117         /// add a default textclass with all standard layouts.
118         LayoutFileIndex addEmptyClass(std::string const & textclass);
119
120         /// add a textclass from user local directory.
121         /// \return the identifier for the loaded file, or else an
122         /// empty string if no file was loaded.
123         LayoutFileIndex
124                 addLocalLayout(std::string const & textclass, std::string const & path);
125         /// a list of the available classes
126         std::vector<LayoutFileIndex> classList() const;
127 private:
128         ///
129         typedef std::map<std::string, LayoutFile *> ClassMap;
130         /// noncopyable
131         LayoutFileList(LayoutFileList const &);
132         /// nonassignable
133         void operator=(LayoutFileList const &);
134         ///
135         mutable ClassMap classmap_; //FIXME
136 };
137
138 ///
139 LayoutFileIndex defaultBaseclass();
140
141
142 } // namespace lyx
143
144 #endif