]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
Fix bug 3148: always update the Labels if a DEPM is triggered.
[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 Paragraph;
32 class FuncRequest;
33 class LCursor;
34
35 ///
36 /**
37 */
38 class TocItem
39 {
40         friend class TocBackend;
41
42 public:
43         ///
44         TocItem(ParConstIterator const & par_it = ParConstIterator(),
45                 int d = -1,
46                 docstring const & s = docstring());
47         ///
48         ~TocItem() {}
49         ///
50         bool const isValid() const;
51         ///
52         int const id() const;
53         ///
54         int const depth() const;
55         ///
56         docstring const & str() const;
57         ///
58         docstring const asString() const;
59
60         /// the action corresponding to the goTo above
61         FuncRequest action() const;
62         
63 protected:
64         /// Current position of item.
65         ParConstIterator par_it_;
66
67         /// nesting depth
68         int depth_;
69
70         /// Full item string
71         docstring str_;
72 };
73
74
75 ///
76 typedef std::vector<TocItem> Toc;
77 typedef Toc::const_iterator TocIterator;
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 /**
87 */
88 class TocBackend
89 {
90 public:
91         ///
92         TocBackend(Buffer const * buffer = NULL): buffer_(buffer) {}
93         ///
94         ~TocBackend() {}
95         ///
96         void setBuffer(Buffer const * buffer)
97         { buffer_ = buffer; }
98         ///
99         bool addType(std::string const & type);
100         ///
101         void update();
102         ///
103         TocList const & tocs() const
104         { return tocs_; }
105         ///
106         std::vector<std::string> const & types() const
107         { return types_; }
108         ///
109         Toc const & toc(std::string const & type) const;
110         /// Return the first Toc Item before the cursor
111         TocIterator const item(std::string const & type, ParConstIterator const &) const;
112
113         void writePlaintextTocList(std::string const & type, odocstream & os) const;
114
115 private:
116         /// 
117         TocList tocs_;
118         ///
119         std::vector<std::string> types_;
120         ///
121         Buffer const * buffer_;
122
123 }; // TocBackend
124
125 inline
126 bool operator==(TocItem const & a, TocItem const & b)
127 {
128         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
129 }
130
131
132 inline
133 bool operator!=(TocItem const & a, TocItem const & b)
134 {
135         return !(a == b);
136 }
137
138
139 } // namespace lyx
140
141 #endif // TOC_BACKEND_H