]> git.lyx.org Git - lyx.git/blobdiff - src/Bullet.h
Fix crash when entering unhandled math objects in toolbar
[lyx.git] / src / Bullet.h
index d2744f6e97f59fdfb75b282b42c5fb0c8982c57c..38fc29e4cbc85308cf248fe9da80ea0400066ff2 100644 (file)
@@ -6,7 +6,7 @@
  *           LyX, The Document Processor
  *
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-1999 The LyX Team.
+ *           Copyright 1995-2000 The LyX Team.
  *
  *           This file Copyright 1997-1999
  *           Allan Rae
 class Bullet {
 public:
        ///
-       Bullet(const int f = -1, const int c = -1, const int s = -1);
+       Bullet(int f = -1, int c = -1, int s = -1);
 
        ///
-       Bullet(string const &);
+       explicit Bullet(string const &);
 
        ///
-       void setCharacter(const int);
+       void setCharacter(int);
        ///
-       void setFont(const int);
+       void setFont(int);
        ///
-       void setSize(const int);
+       void setSize(int);
        ///
        void setText(string const &);
        ///
@@ -47,58 +47,46 @@ public:
        ///
        int getSize() const;
        ///
-       string getText() const;
+       string const & getText() const;
        ///
-       string getText();
+       Bullet & operator=(Bullet const &);
        ///
-       char const * c_str();
-       ///
-       Bullet & operator = (const Bullet &);
-       ///
-       friend bool operator == (const Bullet &, const Bullet &);
-       ///
-       friend bool operator != (const Bullet & b1, const Bullet & b2)
-               {
-                       return !(b1 == b2);
-               }
-       
-
+       friend bool operator==(Bullet const &, Bullet const &);
 protected:
 #ifdef ENABLE_ASSERTIONS
-       void testInvariant() const
-               {
-                       Assert(font >= MIN);
-                       Assert(font < FONTMAX);
-                       Assert(character >= MIN);
-                       Assert(character < CHARMAX);
-                       Assert(size >= MIN);
-                       Assert(size < SIZEMAX);
-                       Assert(user_text >= -1);
-                       Assert(user_text <= 1);
-                       // now some relational/operational tests
-                       if (user_text == 1) {
-                               Assert(font == -1 && (character == -1 && size == -1));
-                               //        Assert(!text.empty()); // this isn't necessarily an error
-                       }
-                       //      else if (user_text == -1) {
-                       //        Assert(!text.empty()); // this also isn't necessarily an error
-                       //      }
-                       //      else {
-                       //        // user_text == 0
-                       //        Assert(text.empty()); // not usually true
-                       //      }
+       ///
+       void testInvariant() const {
+               Assert(font >= MIN);
+               Assert(font < FONTMAX);
+               Assert(character >= MIN);
+               Assert(character < CHARMAX);
+               Assert(size >= MIN);
+               Assert(size < SIZEMAX);
+               Assert(user_text >= -1);
+               Assert(user_text <= 1);
+               // now some relational/operational tests
+               if (user_text == 1) {
+                       Assert(font == -1 && (character == -1 && size == -1));
+                       //        Assert(!text.empty()); // this isn't necessarily an error
                }
+               //      else if (user_text == -1) {
+               //        Assert(!text.empty()); // this also isn't necessarily an error
+               //      }
+               //      else {
+               //        // user_text == 0
+               //        Assert(text.empty()); // not usually true
+               //      }
+       }
 #endif
-
 private:
        /**
-         This enum makes adding additional panels or changing panel sizes
-         easier. Since you only need change these values for all tests to
-         be correct for the new values.
-         
-         Note: MAX means the size of the array so to test you need:
-         (x < MAX)  *not* (x <= MAX)
-         */
+          This enum makes adding additional panels or changing panel sizes
+          easier. Since you only need change these values for all tests to
+          be correct for the new values.
+          
+          Note: MAX means the size of the array so to test you need:
+          (x < MAX)  *not* (x <= MAX)
+       */
        enum {
                ///
                MIN = -1,
@@ -109,45 +97,46 @@ private:
                ///
                SIZEMAX = 10
        };
-
+       
        ///
-       void generateText();
+       void generateText() const;
        ///
-       static string bulletSize(const short &);
+       static string const bulletSize(short int);
        ///
-       static string bulletEntry(const short &, const short &);
-
+       static string const bulletEntry(short int, short int);
+       
        ///
-       short font;
+       int font;
        ///
-       short character;
+       int character;
        ///
-       short size;
+       int size;
        
        // size, character and font are array indices to access 
        // the predefined arrays of LaTeX equivalent strings.
-
+       
        /** flag indicates if user has control of text (1)
-         or if I can use it to generate strings (0)
-         or have already (-1)
-         */
-       short user_text; 
-
+           or if I can use it to generate strings (0)
+           or have already (-1)
+       */
+       mutable short user_text; 
+       
        //NOTE: Arranging these four shorts above to be together
        //      like this should ensure they are in a single cache line
+       
        /** text may contain a user-defined LaTeX symbol command
-         or one generated internally from the font, character
-         and size settings.
-         */
-       string text;
+           or one generated internally from the font, character
+           and size settings.
+       */
+       mutable string text;
 };
 
 
 /*----------------Inline Bullet Member Functions------------------*/
 
-inline Bullet::Bullet(string const & t) 
-  :  font(MIN), character(MIN), size(MIN), user_text(1), text(t)
+inline
+Bullet::Bullet(string const & t) 
+       :  font(MIN), character(MIN), size(MIN), user_text(1), text(t)
 {
 #ifdef ENABLE_ASSERTIONS
        testInvariant();
@@ -155,12 +144,12 @@ inline Bullet::Bullet(string const & t)
 }
 
 
-inline void Bullet::setCharacter(const int c)
+inline
+void Bullet::setCharacter(int c)
 {
        if (c < MIN || c >= CHARMAX) {
                character = MIN;
-       }
-       else {
+       } else {
                character = c;
        }
        user_text = 0;
@@ -170,12 +159,12 @@ inline void Bullet::setCharacter(const int c)
 }
 
 
-inline void Bullet::setFont(const int f)
+inline
+void Bullet::setFont(int f)
 {
        if (f < MIN || f >= FONTMAX) {
                font = MIN;
-       }
-       else {
+       } else {
                font = f;
        }
        user_text = 0;
@@ -185,12 +174,12 @@ inline void Bullet::setFont(const int f)
 }
 
 
-inline void Bullet::setSize(const int s)
+inline
+void Bullet::setSize(int s)
 {
        if (s < MIN || s >= SIZEMAX) {
                size = MIN;
-       }
-       else {
+       } else {
                size = s;
        }
        user_text = 0;
@@ -200,7 +189,8 @@ inline void Bullet::setSize(const int s)
 }
 
 
-inline void Bullet::setText(string const & t)
+inline
+void Bullet::setText(string const & t)
 {
        font = character = size = MIN;
        user_text = 1;
@@ -211,31 +201,29 @@ inline void Bullet::setText(string const & t)
 }
 
 
-inline int Bullet::getCharacter() const
+inline
+int Bullet::getCharacter() const
 {
        return character;
 }
 
 
-inline int Bullet::getFont() const
+inline
+int Bullet::getFont() const
 {
        return font;
 }
 
 
-inline int Bullet::getSize() const
+inline
+int Bullet::getSize() const
 {
        return size;
 }
 
 
-inline string Bullet::getText() const
-{
-       return text;
-}
-
-
-inline Bullet & Bullet::operator = (const Bullet & b)
+inline
+Bullet & Bullet::operator=(Bullet const & b)
 {
 #ifdef ENABLE_ASSERTIONS
        b.testInvariant();
@@ -246,24 +234,21 @@ inline Bullet & Bullet::operator = (const Bullet & b)
        user_text = b.user_text;
        text = b.text;
 #ifdef ENABLE_ASSERTIONS
-    this->testInvariant();
+       this->testInvariant();
 #endif
        return *this;
 }
 
+/*-----------------End Bullet Member Functions-----------------*/
 
-inline char const * Bullet::c_str()
+inline
+bool operator!=(Bullet const & b1, Bullet const & b2)
 {
-       return this->getText().c_str();
+       return !(b1 == b2);
 }
 
+///
+extern
+Bullet const ITEMIZE_DEFAULTS[];
 
-/*-----------------End Bullet Member Functions-----------------*/
-
-/** The four LaTeX itemize environment default bullets
-  */
-static Bullet const ITEMIZE_DEFAULTS[4] = { Bullet( 0, 8 ),//"\\(\\bullet\\)"
-                                            Bullet( 0, 0 ),//"\\normalfont\\bfseries{--}"
-                                            Bullet( 0, 6 ),//"\\(\\ast\\)"
-                                            Bullet( 0, 10 ) };//"\\(\\cdot\\)"
 #endif /* BULLET_H_ */