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