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