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