]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
* Doxy: polish html output.
[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  * TocBackend mainly used in toc.[Ch]
14  */
15
16 #ifndef TOC_BACKEND_H
17 #define TOC_BACKEND_H
18
19 #include <map>
20 #include <vector>
21 #include <string>
22
23 #include "ParIterator.h"
24
25 #include "support/strfwd.h"
26
27
28 namespace lyx {
29
30 class Buffer;
31 class FuncRequest;
32
33 ///
34 /**
35 */
36 class TocItem
37 {
38         friend class TocBackend;
39
40 public:
41         /// Default constructor for STL containers.
42         TocItem() {}
43         ///
44         TocItem(ParConstIterator const & par_it,
45                 int depth,
46                 docstring const & s
47                 );
48         ///
49         ~TocItem() {}
50         ///
51         int id() const;
52         ///
53         int depth() const;
54         ///
55         docstring const & str() const;
56         ///
57         docstring const asString() const;
58
59         /// the action corresponding to the goTo above
60         FuncRequest action() const;
61
62 protected:
63         /// Current position of item.
64         ParConstIterator par_it_;
65
66         /// nesting depth
67         int depth_;
68
69         /// Full item string
70         docstring str_;
71 };
72
73
74 ///
75 typedef std::vector<TocItem> Toc;
76 typedef Toc::const_iterator TocIterator;
77
78 /// The ToC list.
79 /// A class and no typedef because we want to forward declare it.
80 class TocList : public std::map<std::string, Toc> {};
81
82
83 ///
84 /**
85 */
86 class TocBackend
87 {
88 public:
89         ///
90         TocBackend(Buffer const * buffer = NULL): buffer_(buffer) {}
91         ///
92         ~TocBackend() {}
93         ///
94         void setBuffer(Buffer const * buffer)
95         { buffer_ = buffer; }
96         ///
97         void update();
98         ///
99         void updateItem(ParConstIterator const & pit);
100
101         ///
102         TocList const & tocs() const
103         { return tocs_; }
104
105         ///
106         Toc const & toc(std::string const & type) const;
107         /// Return the first Toc Item before the cursor
108         TocIterator const item(
109                 std::string const & type, ///< Type of Toc.
110                 ParConstIterator const & ///< The cursor location in the document.
111                 ) const;
112
113         void writePlaintextTocList(std::string const & type, odocstream & os) const;
114
115 private:
116         ///
117         TocList tocs_;
118         ///
119         Buffer const * buffer_;
120
121 }; // TocBackend
122
123 inline
124 bool operator==(TocItem const & a, TocItem const & b)
125 {
126         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
127 }
128
129
130 inline
131 bool operator!=(TocItem const & a, TocItem const & b)
132 {
133         return !(a == b);
134 }
135
136
137 } // namespace lyx
138
139 #endif // TOC_BACKEND_H