]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
Get package things working with modules prior to UI patch.
[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         /// 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 const id() const;
52         ///
53         int const 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 /// 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 /**
86 */
87 class TocBackend
88 {
89 public:
90         ///
91         TocBackend(Buffer const * buffer = NULL): buffer_(buffer) {}
92         ///
93         ~TocBackend() {}
94         ///
95         void setBuffer(Buffer const * buffer)
96         { buffer_ = buffer; }
97         ///
98         void update();
99         ///
100         void updateItem(ParConstIterator const & pit);
101
102         ///
103         TocList const & tocs() const
104         { return tocs_; }
105
106         ///
107         Toc const & toc(std::string const & type) const;
108         /// Return the first Toc Item before the cursor
109         TocIterator const item(
110                 std::string const & type, ///< Type of Toc.
111                 ParConstIterator const & ///< The cursor location in the document.
112                 ) const;
113
114         void writePlaintextTocList(std::string const & type, odocstream & os) const;
115
116 private:
117         ///
118         TocList tocs_;
119         ///
120         Buffer const * buffer_;
121
122 }; // TocBackend
123
124 inline
125 bool operator==(TocItem const & a, TocItem const & b)
126 {
127         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
128 }
129
130
131 inline
132 bool operator!=(TocItem const & a, TocItem const & b)
133 {
134         return !(a == b);
135 }
136
137
138 } // namespace lyx
139
140 #endif // TOC_BACKEND_H