X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBullet.C;h=9e4c5389c0189f4d606a6796e8566f82baae23f7;hb=da7667356810c250a0875649d0b0291c90462c65;hp=70b842608a1b000b34117629e59475a8bb5daf22;hpb=b16c7bca00a5e829b4bb80d0781da84ea5c9f1fb;p=features.git diff --git a/src/Bullet.C b/src/Bullet.C index 70b842608a..9e4c5389c0 100644 --- a/src/Bullet.C +++ b/src/Bullet.C @@ -1,4 +1,3 @@ -// -*- C++ -*- /* Completes the implementation of the Bullet class * It defines the various LaTeX commands etc. required to * generate the bullets in the bullet-panel's. @@ -20,6 +19,7 @@ #endif #include "Bullet.h" +#include "support/LAssert.h" /** The four LaTeX itemize environment default bullets */ @@ -53,6 +53,104 @@ Bullet::Bullet(int f, int c, int s) } + +Bullet::Bullet(string const & t) + : font(MIN), character(MIN), size(MIN), user_text(1), text(t) +{ +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setCharacter(int c) +{ + if (c < MIN || c >= CHARMAX) { + character = MIN; + } else { + character = c; + } + user_text = 0; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setFont(int f) +{ + if (f < MIN || f >= FONTMAX) { + font = MIN; + } else { + font = f; + } + user_text = 0; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setSize(int s) +{ + if (s < MIN || s >= SIZEMAX) { + size = MIN; + } else { + size = s; + } + user_text = 0; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setText(string const & t) +{ + font = character = size = MIN; + user_text = 1; + text = t; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +int Bullet::getCharacter() const +{ + return character; +} + + +int Bullet::getFont() const +{ + return font; +} + + +int Bullet::getSize() const +{ + return size; +} + + +Bullet & Bullet::operator=(Bullet const & b) +{ +#ifdef ENABLE_ASSERTIONS + b.testInvariant(); +#endif + font = b.font; + character = b.character; + size = b.size; + user_text = b.user_text; + text = b.text; +#ifdef ENABLE_ASSERTIONS + this->testInvariant(); +#endif + return *this; +} + + string const & Bullet::getText() const { if (user_text == 0) { @@ -62,7 +160,7 @@ string const & Bullet::getText() const } -bool operator == (const Bullet & b1, const Bullet & b2) +bool operator==(const Bullet & b1, const Bullet & b2) { bool result = false; @@ -109,7 +207,7 @@ void Bullet::generateText() const } -string Bullet::bulletSize(short int s) +string const Bullet::bulletSize(short int s) { // use a parameter rather than hard code `size' in here // in case some future function may want to retrieve @@ -125,7 +223,7 @@ string Bullet::bulletSize(short int s) } -string Bullet::bulletEntry(short int f, short int c) +string const Bullet::bulletEntry(short int f, short int c) { // Despite how this may at first appear the static local variables // are only initialized once.. @@ -268,3 +366,28 @@ string Bullet::bulletEntry(short int f, short int c) return BulletPanels[f][c]; } + +#ifdef ENABLE_ASSERTIONS +void Bullet::testInvariant() const { + lyx::Assert(font >= MIN); + lyx::Assert(font < FONTMAX); + lyx::Assert(character >= MIN); + lyx::Assert(character < CHARMAX); + lyx::Assert(size >= MIN); + lyx::Assert(size < SIZEMAX); + lyx::Assert(user_text >= -1); + lyx::Assert(user_text <= 1); + // now some relational/operational tests + if (user_text == 1) { + lyx::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