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