]> git.lyx.org Git - lyx.git/blob - src/BaseClassList.h
Abdel is right.
[lyx.git] / src / BaseClassList.h
1 // -*- C++ -*-
2 /**
3  * \file BaseClassList.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 <vector>
20
21
22 namespace lyx {
23
24 class Layout;
25
26 /// Reads the style files
27 extern bool LyXSetStyle();
28
29
30 /// Index into BaseClassList. Basically a 'strong typedef'.
31 class LayoutFileIndex {
32 public:
33         ///
34         typedef std::string base_type;
35         ///
36         LayoutFileIndex(base_type t) { data_ = t; }
37         ///
38         operator base_type() const { return data_; }
39         ///
40         bool empty() const { return data_.empty(); }
41 private:
42         base_type data_;
43 };
44
45 /// This class amounts to little more than a `strong typedef'.
46 /// A LayoutFile represents the layout information that is 
47 /// contained in a *.layout file.
48 class LayoutFile : public TextClass {
49 public:
50         /// This should never be used, but it has to be provided for
51         /// std::map operator[] to work. Something like:
52         ///   mapthingy[stuff] = otherthing
53         /// creates an empty object before doing the assignment.
54         LayoutFile() {}
55         /// check whether the TeX class is available
56         bool isTeXClassAvailable() const { return texClassAvail_; }
57 private:
58         /// Construct a layout with default values. Actual values loaded later.
59         explicit LayoutFile(std::string const &,
60                                  std::string const & = std::string(),
61                                  std::string const & = std::string(),
62                                  bool texClassAvail = false);
63         /// The only class that should create a LayoutFile is
64         /// BaseClassList, which calls the private constructor.
65         friend class BaseClassList;
66 };
67
68
69 /// A list of base document classes (*.layout files).
70 /// This is a singleton class. The sole instance is accessed
71 /// via BaseClassList::get()
72 class BaseClassList {
73 public:
74         ///
75         BaseClassList() {}
76         /// \return The sole instance of this class.
77         static BaseClassList & get();
78         ///
79         bool empty() const { return classmap_.empty(); }
80         ///
81         bool haveClass(std::string const & classname) const;
82         ///
83         LayoutFile const & operator[](std::string const & classname) const;
84         ///
85         LayoutFile & operator[](std::string const & classname);
86         /// Read textclass list. Returns false if this fails.
87         bool read();
88         /// Clears the textclass so as to force it to be reloaded
89         void reset(LayoutFileIndex const & tc);
90         /// add a textclass from user local directory.
91         /// \return the identifier for the loaded file, or else an
92         /// empty string if no file was loaded.
93         LayoutFileIndex
94                 addLayoutFile(std::string const & textclass, std::string const & path);
95         /// a list of the available classes
96         std::vector<LayoutFileIndex> classList() const;
97         /// 
98         static std::string const localPrefix;
99 private:
100         ///
101         typedef std::map<std::string, LayoutFile> ClassMap;
102         /// noncopyable
103         BaseClassList(BaseClassList const &);
104         /// nonassignable
105         void operator=(BaseClassList const &);
106         ///
107         mutable ClassMap classmap_; //FIXME
108 };
109
110 ///
111 LayoutFileIndex defaultBaseclass();
112
113
114 } // namespace lyx
115
116 #endif