]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
Natbib authoryear uses (Ref1; Ref2) by default.
[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 <string>
24 #include <vector>
25
26
27 namespace lyx {
28
29 class Layout;
30
31 /// Index into LayoutFileList. Basically a 'strong typedef'.
32 class LayoutFileIndex {
33 public:
34         ///
35         typedef std::string base_type;
36         ///
37         LayoutFileIndex(base_type t) { data_ = t; }
38         ///
39         operator base_type() const { return data_; }
40         ///
41         bool empty() const { return data_.empty(); }
42 private:
43         base_type data_;
44 };
45
46 /// This class amounts to little more than a `strong typedef'.
47 /// 
48 /// A LayoutFile represents the layout information that is 
49 /// contained in a *.layout file.
50 /// 
51 /// No document- (that is, Buffer-) specific information should 
52 /// be placed in these objects. They are used as the basis for 
53 /// constructing DocumentClass objects, which are what represent
54 /// the layout information associated with a Buffer. (This is also 
55 /// a subclass of TextClass, implemented in TextClass.{h,cpp}.)
56 /// Buffer-specific information should therefore be placed in a
57 /// DocumentClass object.
58 /// 
59 class LayoutFile : public TextClass, boost::noncopyable {
60 public:
61         /// check whether the TeX class is available
62         bool isTeXClassAvailable() const { return tex_class_avail_; }
63         ///
64         LayoutModuleList const & defaultModules() const 
65                         { return default_modules_; }
66         ///
67         LayoutModuleList const & providedModules() const 
68                         { return provided_modules_; }
69         ///
70         LayoutModuleList const & excludedModules() const 
71                         { return excluded_modules_; }
72 private:
73         /// Construct a layout with default values. Actual values loaded later.
74         explicit LayoutFile(std::string const & filename,
75                         std::string const & className = std::string(),
76                         std::string const & description = std::string(),
77                         std::string const & prerequisites = std::string(),
78                         std::string const & category = 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         ///
96         ~LayoutFileList();
97         /// \return The sole instance of this class.
98         static LayoutFileList & get();
99         ///
100         bool empty() const { return classmap_.empty(); }
101         ///
102         bool haveClass(std::string const & classname) const;
103         /// Note that this will assert if we don't have classname, so
104         /// check via haveClass() first.
105         LayoutFile const & operator[](std::string const & classname) const;
106         /// Note that this will assert if we don't have classname, so
107         /// check via haveClass() first.
108         LayoutFile & operator[](std::string const & classname);
109         /// Read textclass list. Returns false if this fails.
110         bool read();
111         /// Clears the textclass so as to force it to be reloaded
112         void reset(LayoutFileIndex const & tc);
113
114         /// Add a default textclass with all standard layouts.
115         /// Note that this will over-write any information we may have
116         /// gotten from textclass.lst about this class.
117         LayoutFileIndex addEmptyClass(std::string const & textclass);
118
119         /// add a textclass from user local directory.
120         /// \return the identifier for the loaded file, or else an
121         /// empty string if no file was loaded.
122         LayoutFileIndex
123                 addLocalLayout(std::string const & textclass, std::string const & path);
124         /// a list of the available classes
125         std::vector<LayoutFileIndex> classList() const;
126
127         ///
128         bool load(std::string const & name, std::string const & buf_path);
129
130 private:
131         ///
132         typedef std::map<std::string, LayoutFile *> ClassMap;
133         /// noncopyable
134         LayoutFileList(LayoutFileList const &);
135         /// nonassignable
136         void operator=(LayoutFileList const &);
137         ///
138         mutable ClassMap classmap_; //FIXME
139 };
140
141 ///
142 LayoutFileIndex defaultBaseclass();
143
144
145 } // namespace lyx
146
147 #endif