Small cleanup in order to improve toc change detection within insets.
[lyx.git] / src / TocBackend.h
blob1e5b031a73cdfe251ad44d6b547461fe817ceb67
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.
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
9 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
14 #ifndef TOC_BACKEND_H
15 #define TOC_BACKEND_H
17 #include "DocIterator.h"
19 #include "support/strfwd.h"
21 #include <map>
22 #include <vector>
23 #include <string>
26 namespace lyx {
28 class Buffer;
29 class FuncRequest;
31 ///
32 /**
34 class TocItem
36 friend class Toc;
37 friend class TocBackend;
39 public:
40 /// Default constructor for STL containers.
41 TocItem() {}
42 ///
43 TocItem(DocIterator const & dit,
44 int depth,
45 docstring const & s
47 ///
48 ~TocItem() {}
49 ///
50 int id() const;
51 ///
52 int depth() const;
53 ///
54 docstring const & str() const;
55 ///
56 docstring const asString() const;
58 /// the action corresponding to the goTo above
59 FuncRequest action() const;
61 protected:
62 /// Current position of item.
63 DocIterator dit_;
65 /// nesting depth
66 int depth_;
68 /// Full item string
69 docstring str_;
73 ///
74 class Toc : public std::vector<TocItem>
76 public:
77 typedef std::vector<TocItem>::const_iterator const_iterator;
78 const_iterator item(DocIterator const & dit) const;
81 typedef Toc::const_iterator TocIterator;
83 /// The ToC list.
84 /// A class and no typedef because we want to forward declare it.
85 class TocList : public std::map<std::string, Toc> {};
88 ///
89 /**
91 class TocBackend
93 public:
94 ///
95 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
96 ///
97 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
98 ///
99 void update();
100 /// \return true if the item was updated.
101 bool updateItem(DocIterator const & pit);
104 TocList const & tocs() const { return tocs_; }
105 TocList & tocs() { return tocs_; }
108 Toc const & toc(std::string const & type) const;
109 Toc & toc(std::string const & type);
111 /// Return the first Toc Item before the cursor
112 TocIterator item(
113 std::string const & type, ///< Type of Toc.
114 DocIterator const & dit ///< The cursor location in the document.
115 ) const;
118 void writePlaintextTocList(std::string const & type, odocstream & os) const;
120 private:
122 TocList tocs_;
124 Buffer const * buffer_;
125 }; // TocBackend
127 inline bool operator==(TocItem const & a, TocItem const & b)
129 return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
133 inline bool operator!=(TocItem const & a, TocItem const & b)
135 return !(a == b);
139 } // namespace lyx
141 #endif // TOC_BACKEND_H