void RString::CloneString(void) { //takes the current string (presumably shared) and makes a new copy of it, //setting _this_ CBaseStr to it SetRefCount(RefCount()-1); char *nstring = new char[StrLen()+2]; nstring++; strcpy(nstring,myString); myString = nstring; SetRefCount(0); }
bool BackupStoreRefCountDatabase::RemoveReference(int64_t ObjectID) { refcount_t refcount = GetRefCount(ObjectID); // must exist in database ASSERT(refcount > 0); refcount--; SetRefCount(ObjectID, refcount); return (refcount > 0); }
void CMapLocation::load(IReader &stream) { u16 c = stream.r_u16(); xr_string hint; stream.r_stringZ(hint); SetHint (hint.c_str()); SetRefCount (c); m_flags.flags = stream.r_u32 (); }
void RString::Clone(RString& clone_to) { /* makes shared copy */ clone_to.SafeDealloc(); if(!myString) return (void)(clone_to.myString = NULL); if(RefCount() > 250) CloneString(); SetRefCount(RefCount() == 0 ? 2 : RefCount() + 1); clone_to.myString = myString; return; }
RString& RString::operator +=(const char *str) { if(!str) return *this; char *nstring = new char[StrLen() + strlen(str) + 2]; nstring++; *nstring = '\0'; if(myString) strcpy(nstring, myString); strcat(nstring, str); SafeDealloc(); myString = nstring; SetRefCount(0); return *this; }
void RString::SafeDealloc(void) { if(!myString) return; if(RefCount() > 0) { SetRefCount(RefCount() - 1); myString = NULL; return; } //hack int i; if((int *)myString > &i) return; myString--; delete[] myString; }
void BackupStoreRefCountDatabase::AddReference(int64_t ObjectID) { refcount_t refcount; if (ObjectID > GetLastObjectIDUsed()) { // new object, assume no previous references refcount = 0; } else { // read previous value from database refcount = GetRefCount(ObjectID); } refcount++; SetRefCount(ObjectID, refcount); }
RString::RString(const RString& nStr) { /* copy constructor called by RString new = me*/ myString = nStr.myString; SetRefCount(RefCount()+1); }