]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
Update my email and status.
[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 /// Index into LayoutFileList. Basically a 'strong typedef'.
33 class LayoutFileIndex {
34 public:
35         ///
36         typedef std::string base_type;
37         ///
38         LayoutFileIndex(base_type t) { data_ = t; }
39         ///
40         operator base_type() const { return data_; }
41         ///
42         bool empty() const { return data_.empty(); }
43 private:
44         base_type data_;
45 };
46
47 /// This class amounts to little more than a `strong typedef'.
48 /// 
49 /// A LayoutFile represents the layout information that is 
50 /// contained in a *.layout file.
51 /// 
52 /// No document- (that is, Buffer-) specific information should 
53 /// be placed in these objects. They are used as the basis for 
54 /// constructing DocumentClass objects, which are what represent
55 /// the layout information associated with a Buffer. (This is also 
56 /// a subclass of TextClass, implemented in TextClass.{h,cpp}.)
57 /// Buffer-specific information should therefore be placed in a
58 /// DocumentClass object.
59 /// 
60 class LayoutFile : public TextClass, boost::noncopyable {
61 public:
62         /// check whether the TeX class is available
63         bool isTeXClassAvailable() const { return tex_class_avail_; }
64         ///
65         LayoutModuleList const & defaultModules() const 
66                         { return default_modules_; }
67         ///
68         LayoutModuleList const & providedModules() const 
69                         { return provided_modules_; }
70         ///
71         LayoutModuleList 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                         std::string const & prerequisites = std::string(),
79                         std::string const & category = std::string(),
80                         bool texclassavail = false);
81         /// The only class that should create a LayoutFile is
82         /// LayoutFileList, which calls the private constructor.
83         friend class LayoutFileList;
84         /// can't create empty LayoutFile
85         LayoutFile() {};
86 };
87
88
89 /// A list of base document classes (*.layout files).
90 /// This is a singleton class. The sole instance is accessed
91 /// via LayoutFileList::get()
92 class LayoutFileList {
93 public:
94         ///
95         LayoutFileList() {}
96         ///
97         ~LayoutFileList();
98         /// \return The sole instance of this class.
99         static LayoutFileList & get();
100         ///
101         bool empty() const { return classmap_.empty(); }
102         ///
103         bool haveClass(std::string const & classname) const;
104         /// Note that this will assert if we don't have classname, so
105         /// check via haveClass() first.
106         LayoutFile const & operator[](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 & operator[](std::string const & classname);
110         /// Read textclass list. Returns false if this fails.
111         bool read();
112         /// Clears the textclass so as to force it to be reloaded
113         void reset(LayoutFileIndex const & tc);
114
115         /// Add a default textclass with all standard layouts.
116         /// Note that this will over-write any information we may have
117         /// gotten from textclass.lst about this class.
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
128         ///
129         bool load(std::string const & name, std::string const & buf_path);
130
131 private:
132         ///
133         typedef std::map<std::string, LayoutFile *> ClassMap;
134         /// noncopyable
135         LayoutFileList(LayoutFileList const &);
136         /// nonassignable
137         void operator=(LayoutFileList const &);
138         ///
139         mutable ClassMap classmap_; //FIXME
140 };
141
142 ///
143 LayoutFileIndex defaultBaseclass();
144
145
146 } // namespace lyx
147
148 #endif