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