]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
move definition of variables to the main cmake file
[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 <iosfwd>
21 #include <vector>
22 #include <string>
23
24 #include "pariterator.h"
25
26 class Buffer;
27 class LyXView;
28 class Paragraph;
29 class FuncRequest;
30 class LCursor;
31
32 namespace lyx {
33
34 ///
35 /**
36 */
37 class TocBackend
38 {
39 public:
40
41         ///
42         /**
43         */
44         class Item
45         {
46                 friend class TocBackend;
47                 friend bool operator==(Item const & a, Item const & b);
48
49         public:
50                 ///
51                 Item(
52                         ParConstIterator const & par_it = ParConstIterator(),
53                         int d = -1,
54                         std::string const & s = std::string());
55                 ///
56                 ~Item() {}
57                 ///
58                 bool const isValid() const;
59                 ///
60                 int const id() const;
61                 ///
62                 int const depth() const;
63                 ///
64                 std::string const & str() const;
65                 ///
66                 std::string const asString() const;
67                 /// set cursor in LyXView to this Item
68                 void goTo(LyXView & lv_) const;
69                 /// the action corresponding to the goTo above
70                 FuncRequest action() const;
71                 
72         protected:
73                 /// Current position of item.
74                 ParConstIterator par_it_;
75
76                 /// nesting depth
77                 int depth_;
78
79                 /// Full item string
80                 std::string str_;
81         };
82
83         ///
84         typedef std::vector<Item> Toc;
85         typedef std::vector<Item>::const_iterator TocIterator;
86         ///
87         typedef std::map<std::string, Toc> TocList;
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         bool addType(std::string const & type);
99         ///
100         void update();
101         ///
102         TocList const & tocs()
103         { return tocs_; }
104         ///
105         std::vector<std::string> const & types()
106         { return types_; }
107         ///
108         Toc const & toc(std::string const & type);
109         /// Return the first Toc Item before the cursor
110         TocIterator const item(std::string const & type, ParConstIterator const &);
111
112         void asciiTocList(std::string const & type, std::ostream & os) const;
113
114 private:
115         /// 
116         TocList tocs_;
117         ///
118         std::vector<std::string> types_;
119         ///
120         Buffer const * buffer_;
121
122 }; // TocBackend
123
124 inline
125 bool operator==(TocBackend::Item const & a, TocBackend::Item 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!=(TocBackend::Item const & a, TocBackend::Item const & b)
133 {
134         return !(a == b);
135 }
136
137
138 } // namespace lyx
139
140 #endif // TOC_BACKEND_H