--- deliantra/server/include/dynbuf.h 2006/09/19 22:05:55 1.3 +++ deliantra/server/include/dynbuf.h 2007/04/23 18:09:57 1.4 @@ -4,14 +4,17 @@ #include #include +#include "shstr.h" + // this is a "buffer" that can grow fast // and is still somewhat space-efficient. // unlike obstacks or other data structures, // it never moves data around. basically, // this is a fast strstream without the overhead. -class dynbuf +struct dynbuf { +protected: struct chunk { chunk *next; @@ -76,11 +79,10 @@ add (s, strlen (s)); } - static const int max_sint32_size = 11; - static const int max_sint64_size = 20; - - void add (sint32 i); - void add (sint64 i); + void add (const shstr &s) + { + add (s.s, s.length ()); + } //TODO //void add_destructive (dynbuf &buf); @@ -88,6 +90,26 @@ dynbuf &operator << (char c) { add (c); return *this; } dynbuf &operator << (unsigned char c) { return *this << char (c); } dynbuf &operator << (const char *s) { add (s); return *this; } + dynbuf &operator << (const std::string &s) { add (s.data(), s.size ()); return *this; } + + operator std::string (); +}; + +struct dynbuf_text : dynbuf +{ + dynbuf_text (int initial = 4096, int extend = 16384) + : dynbuf (initial, extend) + { } + + using dynbuf::add; + + static const int max_sint32_size = 11; + static const int max_sint64_size = 20; + + void add (sint32 i); + void add (sint64 i); + + void printf (const char *format, ...); }; #endif