]> git.lyx.org Git - lyx.git/blob - src/toc.h
fix crash when collapsing ert with cursor inside
[lyx.git] / src / toc.h
1 // -*- C++ -*-
2 /**
3  * \file toc.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  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * Nice functions and objects to handle TOCs
13  */
14
15 #ifndef TOC_H
16 #define TOC_H
17
18 #include <map>
19 #include <iosfwd>
20 #include <vector>
21 #include <string>
22
23 class Buffer;
24 class LyXView;
25 class Paragraph;
26 class FuncRequest;
27
28 namespace lyx {
29 namespace toc {
30
31 ///
32 class TocItem {
33 public:
34         TocItem(int par_id, int d, std::string const & s)
35                 : id_(par_id), depth(d), str(s) {}
36         ///
37         std::string const asString() const;
38         /// set cursor in LyXView to this TocItem
39         void goTo(LyXView & lv_) const;
40         /// the action corresponding to the goTo above
41         FuncRequest action() const;
42         /// Paragraph ID containing this item
43         int id_;
44         /// nesting depth
45         int depth;
46         ///
47         std::string str;
48 };
49
50 ///
51 typedef std::vector<TocItem> Toc;
52 ///
53 typedef std::map<std::string, Toc> TocList;
54
55 ///
56 TocList const getTocList(Buffer const &);
57
58 ///
59 std::vector<std::string> const getTypes(Buffer const &);
60
61 ///
62 void asciiTocList(std::string const &, Buffer const &, std::ostream &);
63
64 /** Given the cmdName of the TOC param, returns the type used
65     by ControlToc::getContents() */
66 std::string const getType(std::string const & cmdName);
67
68 inline
69 bool operator==(TocItem const & a, TocItem const & b)
70 {
71         return a.id_ == b.id_ && a.str == b.str;
72         // No need to compare depth.
73 }
74
75
76 inline
77 bool operator!=(TocItem const & a, TocItem const & b)
78 {
79         return !(a == b);
80 }
81
82
83 } // namespace toc
84 } // namespace lyx
85
86 #endif // CONTROLTOC_H