diff options
Diffstat (limited to 'lout/misc.hh')
-rw-r--r-- | lout/misc.hh | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/lout/misc.hh b/lout/misc.hh index 6a04c89a..b362fc2f 100644 --- a/lout/misc.hh +++ b/lout/misc.hh @@ -223,6 +223,14 @@ public: assert (i >= 0 && this->num - i > 0); this->array[i] = t; } + + /** + * \brief Store an object at the end of the vector. + */ + inline void setLast (T t) { + assert (this->num > 0); + this->array[this->num - 1] = t; + } }; /** @@ -379,7 +387,7 @@ public: this->startExtra = index; resizeExtra (); } else { - if (index < startExtra) { + if (index < startExtra) { consolidate (); insert (index, numInsert); } else if (index < startExtra + numExtra) { @@ -421,14 +429,29 @@ public: */ inline T* getRef (int i) const { - if (this->startExtra == -1) + if (this->startExtra == -1) { + assert (i >= 0 && i < this->numMain); return this->arrayMain + i; - else { - if (i < this->startExtra) + } else { + if (i < this->startExtra) { + assert (i >= 0); return this->arrayMain + i; - else if (i >= this->startExtra + this->numExtra) + } else if (i >= this->startExtra + this->numExtra) { + // The original assertion + /// + // "assert (i < this->numMain + this->numExtra)" + // + // causes this warnung in dw::Textblock::breakAdded: + // + // "assuming signed overflow does not occur when assuming that + // (X - c) > X is always false [-Wstrict-overflow]" + // + // Subtracting numExtra from both sides solves this, + // interrestingly. + + assert (i - this->numExtra < this->numMain); return this->arrayMain + i - this->numExtra; - else + } else return this->arrayExtra1 + i - this->startExtra; } } @@ -485,6 +508,13 @@ public: inline void set (int i, T t) { *(this->getRef(i)) = t; } + + /** + * \brief Store an object at the end of the vector. + */ + inline void setLast (T t) { + *(this->getLastRef()) = t; + } }; /** @@ -515,6 +545,11 @@ public: * about memory management. */ inline void append(const char *str) { appendNoCopy(strdup(str)); } + inline void appendInt(int n) + { char buf[32]; sprintf (buf, "%d", n); append (buf); } + inline void appendPointer(void *p) + { char buf[32]; sprintf (buf, "%p", p); append (buf); } + inline void appendBool(bool b) { append (b ? "true" : "false"); } void appendNoCopy(char *str); const char *getChars(); void clear (); |