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