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