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