]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
remove redundant lyxerr.debugging checks; macro LYXERR already checks whether the...
[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/docstream.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         ///
42         TocItem(ParConstIterator const & par_it = ParConstIterator(),
43                 int d = -1,
44                 docstring const & s = docstring());
45         ///
46         ~TocItem() {}
47         ///
48         bool const isValid() const;
49         ///
50         int const id() const;
51         ///
52         int const depth() const;
53         ///
54         docstring const & str() const;
55         ///
56         docstring const asString() const;
57
58         /// the action corresponding to the goTo above
59         FuncRequest action() const;
60         
61 protected:
62         /// Current position of item.
63         ParConstIterator par_it_;
64
65         /// nesting depth
66         int depth_;
67
68         /// Full item string
69         docstring str_;
70 };
71
72
73 ///
74 typedef std::vector<TocItem> Toc;
75 typedef Toc::const_iterator TocIterator;
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 /**
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(std::string const & type, ParConstIterator const &) const;
109
110         void writePlaintextTocList(std::string const & type, odocstream & os) const;
111
112 private:
113         /// 
114         TocList tocs_;
115         ///
116         Buffer const * buffer_;
117
118 }; // TocBackend
119
120 inline
121 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
128 bool operator!=(TocItem const & a, TocItem const & b)
129 {
130         return !(a == b);
131 }
132
133
134 } // namespace lyx
135
136 #endif // TOC_BACKEND_H