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