X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fpersistence%2Fpersistent_cstring.cpp;fp=src%2Fstlplus%2Fpersistence%2Fpersistent_cstring.cpp;h=0000000000000000000000000000000000000000;hb=5846afb00833cc72fe72422ca896d2387c712cb4;hp=a829b9af0558aafd7ded7e62b63c2ede4958b110;hpb=a97500609dc3c1b11f9786d32bc458eb00de4c36;p=chaz%2Fyoink diff --git a/src/stlplus/persistence/persistent_cstring.cpp b/src/stlplus/persistence/persistent_cstring.cpp deleted file mode 100644 index a829b9a..0000000 --- a/src/stlplus/persistence/persistent_cstring.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// - -// Author: Andy Rushton -// Copyright: (c) Southampton University 1999-2004 -// (c) Andy Rushton 2004-2009 -// License: BSD License, see ../docs/license.html - -//////////////////////////////////////////////////////////////////////////////// - -#include "persistent_cstring.hpp" -#include "persistent_int.hpp" -#include - -//////////////////////////////////////////////////////////////////////////////// -// Null-terminated char arrays -// Format: address [ size data ] - -void stlplus::dump_cstring(stlplus::dump_context& context, const char* data) throw(stlplus::persistent_dump_failed) -{ - // register the address and get the magic key for it - std::pair mapping = context.pointer_map(data); - stlplus::dump_unsigned(context,mapping.second); - // if the address is null, then that is all that we need to do - // however, if it is non-null and this is the first sight of the address, dump the contents - if (data && !mapping.first) - { - unsigned size = strlen(data); - stlplus::dump_unsigned(context,size); - for (unsigned i = 0; i < size; i++) - stlplus::dump_char(context,data[i]); - } -} - -void stlplus::restore_cstring(restore_context& context, char*& data) throw(stlplus::persistent_restore_failed) -{ - // destroy any previous contents - if (data) - { - delete[] data; - data = 0; - } - // get the magic key - unsigned magic = 0; - stlplus::restore_unsigned(context,magic); - // now lookup the magic key to see if this pointer has already been restored - // null pointers are always flagged as already restored - std::pair address = context.pointer_map(magic); - if (!address.first) - { - // this pointer has never been seen before and is non-null - // restore the string - unsigned size = 0; - stlplus::restore_unsigned(context,size); - data = new char[size+1]; - for (unsigned i = 0; i < size; i++) - stlplus::restore_char(context,data[i]); - data[size] = '\0'; - // add this pointer to the set of already seen objects - context.pointer_add(magic,data); - } -} - -////////////////////////////////////////////////////////////////////////////////