]> git.lyx.org Git - lyx.git/blob - src/Bullet.h
Angus insetindex patch + protect patch from Dekel
[lyx.git] / src / Bullet.h
1 // -*- C++ -*-
2 /* This is the bullet class definition file.
3  * This file is part of
4  * ====================================================== 
5  *
6  *           LyX, The Document Processor
7  *
8  *           Copyright 1995 Matthias Ettrich
9  *           Copyright 1995-2000 The LyX Team.
10  *
11  *           This file Copyright 1997-1999
12  *           Allan Rae
13  * ====================================================== */
14
15 #ifndef BULLET_H
16 #define BULLET_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "LString.h"
23
24 #include "support/LAssert.h"
25
26 ///
27 class Bullet {
28 public:
29         ///
30         Bullet(int f = -1, int c = -1, int s = -1);
31
32         ///
33         explicit Bullet(string const &);
34
35         ///
36         void setCharacter(int);
37         ///
38         void setFont(int);
39         ///
40         void setSize(int);
41         ///
42         void setText(string const &);
43         ///
44         int getCharacter() const;
45         ///
46         int getFont() const;
47         ///
48         int getSize() const;
49         ///
50         string const & getText() const;
51         ///
52         char const * c_str() const;
53         ///
54         Bullet & operator = (Bullet const &);
55         ///
56         friend bool operator==(Bullet const &, Bullet const &);
57         ///
58         friend bool operator!=(Bullet const & b1, Bullet const & b2) {
59                 return !(b1 == b2);
60         }
61 protected:
62 #ifdef ENABLE_ASSERTIONS
63         void testInvariant() const {
64                 Assert(font >= MIN);
65                 Assert(font < FONTMAX);
66                 Assert(character >= MIN);
67                 Assert(character < CHARMAX);
68                 Assert(size >= MIN);
69                 Assert(size < SIZEMAX);
70                 Assert(user_text >= -1);
71                 Assert(user_text <= 1);
72                 // now some relational/operational tests
73                 if (user_text == 1) {
74                         Assert(font == -1 && (character == -1 && size == -1));
75                         //        Assert(!text.empty()); // this isn't necessarily an error
76                 }
77                 //      else if (user_text == -1) {
78                 //        Assert(!text.empty()); // this also isn't necessarily an error
79                 //      }
80                 //      else {
81                 //        // user_text == 0
82                 //        Assert(text.empty()); // not usually true
83                 //      }
84         }
85 #endif
86 private:
87         /**
88            This enum makes adding additional panels or changing panel sizes
89            easier. Since you only need change these values for all tests to
90            be correct for the new values.
91            
92            Note: MAX means the size of the array so to test you need:
93            (x < MAX)  *not* (x <= MAX)
94         */
95         enum {
96                 ///
97                 MIN = -1,
98                 ///
99                 FONTMAX = 6,
100                 ///
101                 CHARMAX = 36,
102                 ///
103                 SIZEMAX = 10
104         };
105         
106         ///
107         void generateText() const;
108         ///
109         static string bulletSize(short int);
110         ///
111         static string bulletEntry(short int, short int);
112         
113         ///
114         short font;
115         ///
116         short character;
117         ///
118         short size;
119         
120         // size, character and font are array indices to access 
121         // the predefined arrays of LaTeX equivalent strings.
122         
123         /** flag indicates if user has control of text (1)
124             or if I can use it to generate strings (0)
125             or have already (-1)
126         */
127         mutable short user_text; 
128         
129         //NOTE: Arranging these four shorts above to be together
130         //      like this should ensure they are in a single cache line
131         
132         /** text may contain a user-defined LaTeX symbol command
133             or one generated internally from the font, character
134             and size settings.
135         */
136         mutable string text;
137 };
138
139
140 /*----------------Inline Bullet Member Functions------------------*/
141
142 inline
143 Bullet::Bullet(string const & t) 
144         :  font(MIN), character(MIN), size(MIN), user_text(1), text(t)
145 {
146 #ifdef ENABLE_ASSERTIONS
147         testInvariant();
148 #endif
149 }
150
151
152 inline
153 void Bullet::setCharacter(int c)
154 {
155         if (c < MIN || c >= CHARMAX) {
156                 character = MIN;
157         } else {
158                 character = c;
159         }
160         user_text = 0;
161 #ifdef ENABLE_ASSERTIONS
162         testInvariant();
163 #endif
164 }
165
166
167 inline
168 void Bullet::setFont(int f)
169 {
170         if (f < MIN || f >= FONTMAX) {
171                 font = MIN;
172         } else {
173                 font = f;
174         }
175         user_text = 0;
176 #ifdef ENABLE_ASSERTIONS
177         testInvariant();
178 #endif
179 }
180
181
182 inline
183 void Bullet::setSize(int s)
184 {
185         if (s < MIN || s >= SIZEMAX) {
186                 size = MIN;
187         } else {
188                 size = s;
189         }
190         user_text = 0;
191 #ifdef ENABLE_ASSERTIONS
192         testInvariant();
193 #endif
194 }
195
196
197 inline
198 void Bullet::setText(string const & t)
199 {
200         font = character = size = MIN;
201         user_text = 1;
202         text = t;
203 #ifdef ENABLE_ASSERTIONS
204         testInvariant();
205 #endif
206 }
207
208
209 inline
210 int Bullet::getCharacter() const
211 {
212         return character;
213 }
214
215
216 inline
217 int Bullet::getFont() const
218 {
219         return font;
220 }
221
222
223 inline
224 int Bullet::getSize() const
225 {
226         return size;
227 }
228
229
230 inline
231 Bullet & Bullet::operator=(Bullet const & b)
232 {
233 #ifdef ENABLE_ASSERTIONS
234         b.testInvariant();
235 #endif
236         font = b.font;
237         character = b.character;
238         size = b.size;
239         user_text = b.user_text;
240         text = b.text;
241 #ifdef ENABLE_ASSERTIONS
242         this->testInvariant();
243 #endif
244         return *this;
245 }
246
247
248 inline
249 char const * Bullet::c_str() const
250 {
251         return getText().c_str();
252 }
253
254
255 /*-----------------End Bullet Member Functions-----------------*/
256
257 extern
258 Bullet const ITEMIZE_DEFAULTS[];
259
260 #endif /* BULLET_H_ */