]> git.lyx.org Git - features.git/blob - src/TocBackend.h
* Menu:
[features.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 class Toc : public std::vector<TocItem> {};
74
75 typedef Toc::const_iterator TocIterator;
76
77 /// The ToC list.
78 /// A class and no typedef because we want to forward declare it.
79 class TocList : public std::map<std::string, Toc> {};
80
81
82 ///
83 /**
84 */
85 class TocBackend
86 {
87 public:
88         ///
89         TocBackend(Buffer const * buffer) : buffer_(buffer) {}
90         ///
91         void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
92         ///
93         void update();
94         ///
95         void updateItem(ParConstIterator const & pit);
96
97         ///
98         TocList const & tocs() const { return tocs_; }
99         TocList & tocs() { return tocs_; }
100
101         ///
102         Toc const & toc(std::string const & type) const;
103         Toc & toc(std::string const & type);
104
105         /// Return the first Toc Item before the cursor
106         TocIterator item(
107                 std::string const & type, ///< Type of Toc.
108                 ParConstIterator const & ///< The cursor location in the document.
109         ) const;
110
111         ///
112         void writePlaintextTocList(std::string const & type, odocstream & os) const;
113
114 private:
115         ///
116         TocList tocs_;
117         ///
118         Buffer const * buffer_;
119 }; // TocBackend
120
121 inline bool operator==(TocItem const & a, TocItem const & b)
122 {
123         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
124 }
125
126
127 inline bool operator!=(TocItem const & a, TocItem const & b)
128 {
129         return !(a == b);
130 }
131
132
133 } // namespace lyx
134
135 #endif // TOC_BACKEND_H