]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
976a7dd88103751c4bf99bc578561269583ca998
[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         std::list<std::string> const & providedModules() const 
71                         { return provided_modules_; }
72         std::list<std::string> const & excludedModules() const 
73                         { return excluded_modules_; }
74 private:
75         /// Construct a layout with default values. Actual values loaded later.
76         explicit LayoutFile(std::string const & filename,
77                         std::string const & className = std::string(),
78                         std::string const & description = std::string(),
79                         bool texClassAvail = false);
80         /// The only class that should create a LayoutFile is
81         /// LayoutFileList, which calls the private constructor.
82         friend class LayoutFileList;
83         /// can't create empty LayoutFile
84         LayoutFile() {};
85 };
86
87
88 /// A list of base document classes (*.layout files).
89 /// This is a singleton class. The sole instance is accessed
90 /// via LayoutFileList::get()
91 class LayoutFileList {
92 public:
93         ///
94         LayoutFileList() {}
95         ~LayoutFileList();
96         /// \return The sole instance of this class.
97         static LayoutFileList & get();
98         ///
99         bool empty() const { return classmap_.empty(); }
100         ///
101         bool haveClass(std::string const & classname) const;
102         ///
103         LayoutFile const & operator[](std::string const & classname) const;
104         ///
105         LayoutFile & operator[](std::string const & classname);
106         /// Read textclass list. Returns false if this fails.
107         bool read();
108         /// Clears the textclass so as to force it to be reloaded
109         void reset(LayoutFileIndex const & tc);
110
111         /// add a default textclass with all standard layouts.
112         LayoutFileIndex addEmptyClass(std::string const & textclass);
113
114         /// add a textclass from user local directory.
115         /// \return the identifier for the loaded file, or else an
116         /// empty string if no file was loaded.
117         LayoutFileIndex
118                 addLocalLayout(std::string const & textclass, std::string const & path);
119         /// a list of the available classes
120         std::vector<LayoutFileIndex> classList() const;
121 private:
122         ///
123         typedef std::map<std::string, LayoutFile *> ClassMap;
124         /// noncopyable
125         LayoutFileList(LayoutFileList const &);
126         /// nonassignable
127         void operator=(LayoutFileList const &);
128         ///
129         mutable ClassMap classmap_; //FIXME
130 };
131
132 ///
133 LayoutFileIndex defaultBaseclass();
134
135
136 } // namespace lyx
137
138 #endif