]> git.lyx.org Git - features.git/blob - src/TocBackend.h
Cleanup of the Toc model and controller: The objective is to let the View (TocWidget...
[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  * 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         void update();
100         ///
101         void updateItem(ParConstIterator const & pit);
102
103         ///
104         TocList const & tocs() const
105         { return tocs_; }
106
107         ///
108         Toc const & toc(std::string const & type) const;
109         /// Return the first Toc Item before the cursor
110         TocIterator const item(std::string const & type, ParConstIterator const &) const;
111
112         void writePlaintextTocList(std::string const & type, odocstream & os) const;
113
114 private:
115         /// 
116         TocList tocs_;
117         ///
118         Buffer const * buffer_;
119
120 }; // TocBackend
121
122 inline
123 bool operator==(TocItem const & a, TocItem const & b)
124 {
125         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
126 }
127
128
129 inline
130 bool operator!=(TocItem const & a, TocItem const & b)
131 {
132         return !(a == b);
133 }
134
135
136 } // namespace lyx
137
138 #endif // TOC_BACKEND_H