This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / Bullet.h
blobecf868c92e52f0f5c47a045cd1933aa9feff8d0c
1 // -*- C++ -*-
2 /* This is the bullet class definition file.
3 * This file is part of
4 * ======================================================
6 * LyX, The Document Processor
8 * Copyright 1995 Matthias Ettrich
9 * Copyright 1995-1999 The LyX Team.
11 * This file Copyright 1997-1999
12 * Allan Rae
13 * ======================================================*/
15 #ifndef BULLET_H
16 #define BULLET_H
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
22 #include "LString.h"
24 #ifdef DEBUG_AS_DEFAULT
25 #include <cassert>
26 #endif
28 ///
29 class Bullet {
30 public:
31 ///
32 Bullet(const int f = -1, const int c = -1, const int s = -1);
34 ///
35 Bullet(const string &);
37 ///
38 ~Bullet();
40 ///
41 void setCharacter(const int);
42 ///
43 void setFont(const int);
44 ///
45 void setSize(const int);
46 ///
47 void setText(const string &);
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)
67 return !(b1 == b2);
71 protected:
72 #ifdef DEBUG_AS_DEFAULT
73 void testInvariant() const
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
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 // }
96 #endif
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.
104 Note: MAX means the size of the array so to test you need:
105 (x < MAX) *not* (x <= MAX)
107 enum {
109 MIN = -1,
111 FONTMAX = 6,
113 CHARMAX = 36,
115 SIZEMAX = 10
119 void generateText();
121 static const string & bulletSize(const short &);
123 static const string & bulletEntry(const short &, const short &);
126 short font;
128 short character;
130 short size;
132 // size, character and font are array indices to access
133 // the predefined arrays of LaTeX equivalent strings.
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)
139 short user_text;
141 //NOTE: Arranging these four shorts above to be together
142 // like this should ensure they are in a single cache line
144 /** text may contain a user-defined LaTeX symbol command
145 or one generated internally from the font, character
146 and size settings.
148 string text;
152 /*----------------Inline Bullet Member Functions------------------*/
154 inline Bullet::Bullet(const string & t)
155 : font(MIN), character(MIN), size(MIN), user_text(1), text(t)
157 #ifdef DEBUG_AS_DEFAULT
158 testInvariant();
159 #endif
163 inline Bullet::~Bullet()
167 inline void Bullet::setCharacter(const int c)
169 if (c < MIN || c >= CHARMAX) {
170 character = MIN;
172 else {
173 character = c;
175 user_text = 0;
176 #ifdef DEBUG_AS_DEFAULT
177 testInvariant();
178 #endif
182 inline void Bullet::setFont(const int f)
184 if (f < MIN || f >= FONTMAX) {
185 font = MIN;
187 else {
188 font = f;
190 user_text = 0;
191 #ifdef DEBUG_AS_DEFAULT
192 testInvariant();
193 #endif
197 inline void Bullet::setSize(const int s)
199 if (s < MIN || s >= SIZEMAX) {
200 size = MIN;
202 else {
203 size = s;
205 user_text = 0;
206 #ifdef DEBUG_AS_DEFAULT
207 testInvariant();
208 #endif
212 inline void Bullet::setText(const string & t)
214 font = character = size = MIN;
215 user_text = 1;
216 text = t;
217 #ifdef DEBUG_AS_DEFAULT
218 testInvariant();
219 #endif
223 inline int Bullet::getCharacter() const
225 return character;
229 inline int Bullet::getFont() const
231 return font;
235 inline int Bullet::getSize() const
237 return size;
241 inline string Bullet::getText() const
243 return text;
247 inline Bullet & Bullet::operator = (const Bullet & b)
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;
264 inline const char * Bullet::c_str()
266 return this->getText().c_str();
270 /*-----------------End Bullet Member Functions-----------------*/
272 /** The four LaTeX itemize environment default bullets
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_ */