]> git.lyx.org Git - lyx.git/blob - src/ParagraphList.C
fix disabling of submenu items
[lyx.git] / src / ParagraphList.C
1 #include <config.h>
2
3 #include "ParagraphList.h"
4
5 #include "paragraph.h"
6
7 ////////// The ParagraphList::iterator
8
9 ParagraphList::iterator::iterator()
10         : ptr(0)
11 {}
12
13
14 ParagraphList::iterator::iterator(Paragraph * p)
15         : ptr(p)
16 {}
17
18
19 ParagraphList::iterator::reference
20 ParagraphList::iterator::operator*()
21 {
22         return *ptr;
23 }
24
25
26 ParagraphList::iterator::pointer
27 ParagraphList::iterator::operator->()
28 {
29         return ptr;
30 }
31
32
33 ParagraphList::iterator &
34 ParagraphList::iterator::operator++()
35 {
36         ptr = ptr->next();
37         return *this;
38 }
39
40
41 ParagraphList::iterator
42 ParagraphList::iterator::operator++(int)
43 {
44         iterator tmp = *this;
45         ++*this;
46         return tmp;
47 }
48
49
50 ParagraphList::iterator &
51 ParagraphList::iterator::operator--()
52 {
53         ptr = ptr->previous();
54         return *this;
55 }
56
57
58 ParagraphList::iterator
59 ParagraphList::iterator::operator--(int)
60 {
61         iterator tmp = *this;
62         --*this;
63         return tmp;
64 }
65
66
67 bool operator==(ParagraphList::iterator const & i1,
68                 ParagraphList::iterator const & i2)
69 {
70         return &(*const_cast<ParagraphList::iterator&>(i1)) == &(*const_cast<ParagraphList::iterator&>(i2));
71 }
72
73
74 bool operator!=(ParagraphList::iterator const & i1,
75                 ParagraphList::iterator const & i2)
76 {
77         return !(i1 == i2);
78 }
79
80
81 ////////// The ParagraphList proper
82 ParagraphList::ParagraphList()
83         : parlist(0)
84 {}
85
86
87 void ParagraphList::clear()
88 {
89         while (parlist) {
90                 Paragraph * tmp = parlist->next();
91                 delete parlist;
92                 parlist = tmp;
93         }
94 }
95
96
97 ParagraphList::iterator ParagraphList::begin() 
98 {
99         return iterator(parlist);
100 }
101
102
103 ParagraphList::iterator ParagraphList::begin() const
104 {
105         return iterator(parlist);
106 }
107
108
109 ParagraphList::iterator ParagraphList::end()
110 {
111         return iterator();
112 }
113
114
115 ParagraphList::iterator ParagraphList::end() const
116 {
117         return iterator();
118 }
119
120
121 void ParagraphList::set(Paragraph * p)
122 {
123         parlist = p;
124 }
125
126
127 int ParagraphList::size() const
128 {
129         // When we switch to a std::container this will be O(1)
130         // instead of O(n). (Lgb)
131         Paragraph * tmp = parlist;
132         int c = 0;
133         while (tmp) {
134                 ++c;
135                 tmp = tmp->next();
136         }
137         return c;
138 }
139
140
141 bool ParagraphList::empty() const
142 {
143         return parlist == 0;
144 }