]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
f50f6ea4514cd760977a1d31a49148e13fd1b5f9
[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 tex_class_avail_; }
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                         std::string const & prerequisites = std::string(),
83                         bool texclassavail = false);
84         /// The only class that should create a LayoutFile is
85         /// LayoutFileList, which calls the private constructor.
86         friend class LayoutFileList;
87         /// can't create empty LayoutFile
88         LayoutFile() {};
89 };
90
91
92 /// A list of base document classes (*.layout files).
93 /// This is a singleton class. The sole instance is accessed
94 /// via LayoutFileList::get()
95 class LayoutFileList {
96 public:
97         ///
98         LayoutFileList() {}
99         ///
100         ~LayoutFileList();
101         /// \return The sole instance of this class.
102         static LayoutFileList & get();
103         ///
104         bool empty() const { return classmap_.empty(); }
105         ///
106         bool haveClass(std::string const & classname) const;
107         /// Note that this will assert if we don't have classname, so
108         /// check via haveClass() first.
109         LayoutFile const & operator[](std::string const & classname) const;
110         /// Note that this will assert if we don't have classname, so
111         /// check via haveClass() first.
112         LayoutFile & operator[](std::string const & classname);
113         /// Read textclass list. Returns false if this fails.
114         bool read();
115         /// Clears the textclass so as to force it to be reloaded
116         void reset(LayoutFileIndex const & tc);
117
118         /// Add a default textclass with all standard layouts.
119         /// Note that this will over-write any information we may have
120         /// gotten from textclass.lst about this class.
121         LayoutFileIndex addEmptyClass(std::string const & textclass);
122
123         /// add a textclass from user local directory.
124         /// \return the identifier for the loaded file, or else an
125         /// empty string if no file was loaded.
126         LayoutFileIndex
127                 addLocalLayout(std::string const & textclass, std::string const & path);
128         /// a list of the available classes
129         std::vector<LayoutFileIndex> classList() const;
130
131         ///
132         bool load(std::string const & name, std::string const & buf_path);
133
134 private:
135         ///
136         typedef std::map<std::string, LayoutFile *> ClassMap;
137         /// noncopyable
138         LayoutFileList(LayoutFileList const &);
139         /// nonassignable
140         void operator=(LayoutFileList const &);
141         ///
142         mutable ClassMap classmap_; //FIXME
143 };
144
145 ///
146 LayoutFileIndex defaultBaseclass();
147
148
149 } // namespace lyx
150
151 #endif