1
0

bigstring.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef __BIGSTRING_H
  2. #define __BIGSTRING_H
  3. /*
  4. A class tor concatenate chunks of texts into one big pool. This is much faster than using String if you are adding
  5. a lot of tiny pieces into one giant block (a typical cases of this is when writing xml). Upon request for the value,
  6. the class allocates one big block of memory and copies all the strings into it serially (as opposed to String
  7. reallocating the entire block at each concatenation). Note that because of the type of implementation BigString has
  8. to use, you cannot get the full block as a return value to your concatenations and assignments (+= and = return void).
  9. To do this, request the value explicitely (this should be kept to a strict minimum or the advantage of BigString over
  10. String will disapear)
  11. */
  12. #include <bfc/string/bfcstring.h>
  13. #include <bfc/ptrlist.h>
  14. class BigString {
  15. public:
  16. BigString();
  17. virtual ~BigString();
  18. operator const char *() /*const*/ { return getValue(); }
  19. const char *getValue() /*const*/;
  20. char *getNonConstVal() { return (char *)getValue(); }
  21. void setValue(const char *val);
  22. // copy assignment operator
  23. BigString& operator =(/*const*/ BigString &s) {
  24. if (this != &s)
  25. setValue(s);
  26. return *this;
  27. }
  28. void operator =(const char *newval) { setValue(newval); }
  29. void operator +=(const char *addval) {
  30. cat(addval);
  31. }
  32. int isempty();
  33. void reset();
  34. void catn(const char *s, int n);
  35. void cat(const char *s);
  36. char lastChar();
  37. char firstChar();
  38. int getLineCount();
  39. private:
  40. PtrList<String> strings;
  41. char *mem;
  42. int m_linecount;
  43. };
  44. #endif