]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
Add empty InsetLayout for undefined cases. Should avoid possible bugs caused by empty...
[lyx.git] / src / TocBackend.h
1 // -*- C++ -*-
2 /**
3  * \file TocBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef TOC_BACKEND_H
15 #define TOC_BACKEND_H
16
17 #include "ParIterator.h"
18
19 #include "support/strfwd.h"
20
21 #include <map>
22 #include <vector>
23 #include <string>
24
25
26 namespace lyx {
27
28 class Buffer;
29 class FuncRequest;
30
31 ///
32 /**
33 */
34 class TocItem
35 {
36         friend class TocBackend;
37
38 public:
39         /// Default constructor for STL containers.
40         TocItem() {}
41         ///
42         TocItem(ParConstIterator const & par_it,
43                 int depth,
44                 docstring const & s
45                 );
46         ///
47         ~TocItem() {}
48         ///
49         int id() const;
50         ///
51         int depth() const;
52         ///
53         docstring const & str() const;
54         ///
55         docstring const asString() const;
56
57         /// the action corresponding to the goTo above
58         FuncRequest action() const;
59
60 protected:
61         /// Current position of item.
62         ParConstIterator par_it_;
63
64         /// nesting depth
65         int depth_;
66
67         /// Full item string
68         docstring str_;
69 };
70
71
72 ///
73 typedef std::vector<TocItem> Toc;
74 typedef Toc::const_iterator TocIterator;
75
76 /// The ToC list.
77 /// A class and no typedef because we want to forward declare it.
78 class TocList : public std::map<std::string, Toc> {};
79
80
81 ///
82 /**
83 */
84 class TocBackend
85 {
86 public:
87         ///
88         TocBackend(Buffer const * buffer = NULL) : buffer_(buffer) {}
89         ///
90         void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
91         ///
92         void update();
93         ///
94         void updateItem(ParConstIterator const & pit);
95
96         ///
97         TocList const & tocs() const { return tocs_; }
98         TocList & tocs() { return tocs_; }
99
100         ///
101         Toc const & toc(std::string const & type) const;
102         Toc & toc(std::string const & type);
103
104         /// Return the first Toc Item before the cursor
105         TocIterator item(
106                 std::string const & type, ///< Type of Toc.
107                 ParConstIterator const & ///< The cursor location in the document.
108         ) const;
109
110         ///
111         void writePlaintextTocList(std::string const & type, odocstream & os) const;
112
113 private:
114         ///
115         TocList tocs_;
116         ///
117         Buffer const * buffer_;
118 }; // TocBackend
119
120 inline bool operator==(TocItem const & a, TocItem const & b)
121 {
122         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
123 }
124
125
126 inline bool operator!=(TocItem const & a, TocItem const & b)
127 {
128         return !(a == b);
129 }
130
131
132 } // namespace lyx
133
134 #endif // TOC_BACKEND_H