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