]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
* GuiView.cpp:
[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 <vector>
22
23
24 namespace lyx {
25
26 class Layout;
27
28 /// Reads the style files
29 extern bool LyXSetStyle();
30
31
32 /// Index into LayoutFileList. Basically a 'strong typedef'.
33 class LayoutFileIndex {
34 public:
35         ///
36         typedef std::string base_type;
37         ///
38         LayoutFileIndex(base_type t) { data_ = t; }
39         ///
40         operator base_type() const { return data_; }
41         ///
42         bool empty() const { return data_.empty(); }
43 private:
44         base_type data_;
45 };
46
47 /// This class amounts to little more than a `strong typedef'.
48 /// 
49 /// A LayoutFile represents the layout information that is 
50 /// contained in a *.layout file.
51 /// 
52 /// No document- (that is, Buffer-) specific information should 
53 /// be placed in these objects. They are used as the basis for 
54 /// constructing DocumentClass objects, which are what represent
55 /// the layout information associated with a Buffer. (This is also 
56 /// a subclass of TextClass, implemented in TextClass.{h,cpp}.)
57 /// Buffer-specific information should therefore be placed in a
58 /// DocumentClass object.
59 /// 
60 class LayoutFile : public TextClass, boost::noncopyable {
61 public:
62         /// check whether the TeX class is available
63         bool isTeXClassAvailable() const { return texClassAvail_; }
64 private:
65         /// Construct a layout with default values. Actual values loaded later.
66         explicit LayoutFile(std::string const & filename,
67                         std::string const & className = std::string(),
68                         std::string const & description = std::string(),
69                         bool texClassAvail = false);
70         /// The only class that should create a LayoutFile is
71         /// LayoutFileList, which calls the private constructor.
72         friend class LayoutFileList;
73         /// can't create empty LayoutFile
74         LayoutFile() {};
75 };
76
77
78 /// A list of base document classes (*.layout files).
79 /// This is a singleton class. The sole instance is accessed
80 /// via LayoutFileList::get()
81 class LayoutFileList {
82 public:
83         ///
84         LayoutFileList() {}
85         ~LayoutFileList();
86         /// \return The sole instance of this class.
87         static LayoutFileList & get();
88         ///
89         bool empty() const { return classmap_.empty(); }
90         ///
91         bool haveClass(std::string const & classname) const;
92         ///
93         LayoutFile const & operator[](std::string const & classname) const;
94         ///
95         LayoutFile & operator[](std::string const & classname);
96         /// Read textclass list. Returns false if this fails.
97         bool read();
98         /// Clears the textclass so as to force it to be reloaded
99         void reset(LayoutFileIndex const & tc);
100
101         /// add a default textclass with all standard layouts.
102         LayoutFileIndex addEmptyClass(std::string const & textclass);
103
104         /// add a textclass from user local directory.
105         /// \return the identifier for the loaded file, or else an
106         /// empty string if no file was loaded.
107         LayoutFileIndex
108                 addLocalLayout(std::string const & textclass, std::string const & path);
109         /// a list of the available classes
110         std::vector<LayoutFileIndex> classList() const;
111 private:
112         ///
113         typedef std::map<std::string, LayoutFile *> ClassMap;
114         /// noncopyable
115         LayoutFileList(LayoutFileList const &);
116         /// nonassignable
117         void operator=(LayoutFileList const &);
118         ///
119         mutable ClassMap classmap_; //FIXME
120 };
121
122 ///
123 LayoutFileIndex defaultBaseclass();
124
125
126 } // namespace lyx
127
128 #endif