]> git.lyx.org Git - lyx.git/blob - src/BaseClassList.h
baseclasslist --> BaseClassList singleton. Prep for further type safety.
[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 /// Index into BaseClassList. Basically a 'strong typedef'.
30 class BaseClassIndex {
31 public:
32         ///
33         typedef size_t   base_type;
34         ///
35         BaseClassIndex(base_type t) { data_ = t; }
36         ///
37         operator base_type() const { return data_; }
38         ///
39 private:
40         base_type data_;
41 };
42
43 /// A list of base document classes (*.layout files).
44 /// This is a singleton class. The sole instance is accessed
45 /// via BaseClassList::get()
46 class BaseClassList {
47 public:
48         ///
49         BaseClassList() {}
50         /// \return The sole instance of this class.
51         static BaseClassList & get();
52         ///
53         typedef std::vector<TextClass> ClassList;
54         ///
55         typedef ClassList::const_iterator const_iterator;
56         ///
57         const_iterator begin() const { return classlist_.begin(); }
58         ///
59         const_iterator end() const { return classlist_.end(); }
60         ///
61         bool empty() const { return classlist_.empty(); }
62
63         /// Gets textclass number from name, -1 if textclass name does not exist
64         std::pair<bool, BaseClassIndex> const
65                 numberOfClass(std::string const & textclass) const;
66
67         ///
68         TextClass const & operator[](BaseClassIndex textclass) const;
69
70         /// Read textclass list.  Returns false if this fails.
71         bool read();
72         
73         /// Clears the textclass so as to force it to be reloaded
74         void reset(BaseClassIndex const textclass);
75
76         /// add a textclass from user local directory.
77         /// Return ture/false, and textclass number
78         std::pair<bool, BaseClassIndex> const
79                 addTextClass(std::string const & textclass, std::string const & path);
80
81 private:
82         /// noncopyable
83         BaseClassList(BaseClassList const &);
84         /// nonassignable
85         void operator=(BaseClassList const &);
86
87         ///
88         mutable ClassList classlist_;
89 };
90
91 ///
92 BaseClassIndex defaultBaseclass();
93
94
95 } // namespace lyx
96
97 #endif