]> git.lyx.org Git - lyx.git/blob - src/BaseClassList.h
do what the FIXME suggested
[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 private:
41         base_type data_;
42 };
43
44 /// This class amounts to little more than a `strong typedef'.
45 /// A LayoutFile represents the layout information that is 
46 /// contained in a *.layout file.
47 class LayoutFile : public TextClass {
48 public:
49         /// This should never be used, but it has to be provided for
50         /// std::map operator[] to work. Something like:
51         ///   mapthingy[stuff] = otherthing
52         /// creates an empty object before doing the assignment.
53         LayoutFile() {}
54         /// check whether the TeX class is available
55         bool isTeXClassAvailable() const { return texClassAvail_; }
56 private:
57         /// Construct a layout with default values. Actual values loaded later.
58         explicit LayoutFile(std::string const &,
59                                  std::string const & = std::string(),
60                                  std::string const & = std::string(),
61                                  bool texClassAvail = false);
62         /// The only class that should create a LayoutFile is
63         /// BaseClassList, which calls the private constructor.
64         friend class BaseClassList;
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 BaseClassList::get()
71 class BaseClassList {
72 public:
73         ///
74         BaseClassList() {}
75         /// \return The sole instance of this class.
76         static BaseClassList & 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         /// add a textclass from user local directory.
90         /// \return the identifier for the loaded file, or else an
91         /// empty string if no file was loaded.
92         LayoutFileIndex
93                 addLayoutFile(std::string const & textclass, std::string const & path);
94         /// a list of the available classes
95         std::vector<LayoutFileIndex> classList() const;
96         /// 
97         static std::string const localPrefix;
98 private:
99         ///
100         typedef std::map<std::string, LayoutFile> ClassMap;
101         /// noncopyable
102         BaseClassList(BaseClassList const &);
103         /// nonassignable
104         void operator=(BaseClassList const &);
105         ///
106         mutable ClassMap classmap_; //FIXME
107 };
108
109 ///
110 LayoutFileIndex defaultBaseclass();
111
112
113 } // namespace lyx
114
115 #endif