--- deliantra/server/include/dynbuf.h 2009/10/15 23:02:28 1.25 +++ deliantra/server/include/dynbuf.h 2009/11/07 18:30:05 1.27 @@ -57,7 +57,7 @@ void reserve (int size); void init (int initial); // allocate sinitial chunk void free (chunk *&chain); // free chain of chunks - char *_linearise (); + char *_linearise (int extra = 0); void finalise (); public: @@ -91,6 +91,7 @@ int room () const { return end - ptr; } + // make sure we have "size" extra room char *force (int size) { if (expect_false (ptr + size >= end)) @@ -99,6 +100,7 @@ return ptr; } + // allocate size bytes and return pointer to them (caller must force()) char *falloc (int size) { char *res = ptr; @@ -106,6 +108,7 @@ return res; } + // allocate size bytes and return pointer to them char *alloc (int size) { force (size); @@ -140,6 +143,10 @@ add (s.s, s.length ()); } + // rather inefficient + void splice (int offset, int olen, const char *s, int slen); + void splice (int offset, int olen) { splice (offset, olen, "", 0); } + //TODO //void add_destructive (dynbuf &buf); @@ -176,12 +183,19 @@ dynbuf_text &operator << (uint32 i) { add (sint64 (i)); return *this; } dynbuf_text &operator << (uint64 i) { add (sint64 (i)); return *this; } - void printf (const char *format, ...); + void printf (const char *format, ...) attribute ((format (printf, 2, 3))); void vprintf (const char *format, va_list ap); void add_abilities (const char *name, uint32 abilities); void add_paths (const char *name, uint32 paths); + // we need to redefine, to keep the API :/ + using dynbuf::splice; + void splice (int offset, int olen, const char *s) + { + dynbuf::splice (offset, olen, s, strlen (s)); + } + // returns the string, linearised and with trailing \0 operator char *(); };