]> git.lyx.org Git - lyx.git/blob - src/LayoutFile.h
e23d214bd0cec33d5d88a4ec4f9d596334b44ede
[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 /// A LayoutFile represents the layout information that is 
49 /// contained in a *.layout file.
50 class LayoutFile : public TextClass, boost::noncopyable {
51 public:
52         /// check whether the TeX class is available
53         bool isTeXClassAvailable() const { return texClassAvail_; }
54 private:
55         /// Construct a layout with default values. Actual values loaded later.
56         explicit LayoutFile(std::string const & filename,
57                         std::string const & className = std::string(),
58                         std::string const & description = std::string(),
59                         bool texClassAvail = false);
60         /// The only class that should create a LayoutFile is
61         /// LayoutFileList, which calls the private constructor.
62         friend class LayoutFileList;
63         /// can't create empty LayoutFile
64         LayoutFile() {};
65 };
66
67
68 /// A list of base document classes (*.layout files).
69 /// This is a singleton class. The sole instance is accessed
70 /// via LayoutFileList::get()
71 class LayoutFileList {
72 public:
73         ///
74         LayoutFileList() {}
75         /// \return The sole instance of this class.
76         static LayoutFileList & get();
77         ///
78         bool empty() const { return classmap_.empty(); }
79         ///
80         bool haveClass(std::string const & classname) const;
81         ///
82         LayoutFile const & operator[](std::string const & classname) const;
83         ///
84         LayoutFile & operator[](std::string const & classname);
85         /// Read textclass list. Returns false if this fails.
86         bool read();
87         /// Clears the textclass so as to force it to be reloaded
88         void reset(LayoutFileIndex const & tc);
89
90         enum Layout_Type {
91                 System,
92                 Local,
93                 Embedded
94         };
95         
96         /// add a textclass from user local directory.
97         /// \return the identifier for the loaded file, or else an
98         /// empty string if no file was loaded.
99         LayoutFileIndex
100                 addLayoutFile(std::string const & textclass, std::string const & path,
101                         Layout_Type type);
102         /// a list of the available classes
103         std::vector<LayoutFileIndex> classList() const;
104         /// 
105         static std::string const localPrefix;
106         static std::string const embeddedPrefix;
107 private:
108         ///
109         typedef std::map<std::string, LayoutFile *> ClassMap;
110         /// noncopyable
111         LayoutFileList(LayoutFileList const &);
112         /// nonassignable
113         void operator=(LayoutFileList const &);
114         ///
115         mutable ClassMap classmap_; //FIXME
116 };
117
118 ///
119 LayoutFileIndex defaultBaseclass();
120
121
122 } // namespace lyx
123
124 #endif