CStr serialization support, a couple of _long -> size_t to get rid of warnings

This was SVN commit r123.
This commit is contained in:
Simon Brenner 2003-11-30 16:39:22 +00:00
parent 6026b76adc
commit e9b219f8a4
2 changed files with 32 additions and 5 deletions

View File

@ -1,4 +1,5 @@
#include "CStr.h"
#include "Network/Serialization.h"
CStr::CStr()
{
@ -189,7 +190,7 @@ CStr CStr::Right(_long len)
//Remove all occurences of some character or substring
void CStr::Remove(const CStr &Str)
{
long FoundAt = 0;
size_t FoundAt = 0;
while (FoundAt != tstring::npos)
{
FoundAt = m_String.find(Str.m_String, 0);
@ -202,7 +203,7 @@ void CStr::Remove(const CStr &Str)
//Replace all occurences of some substring by another
void CStr::Replace(const CStr &ToReplace, const CStr &ReplaceWith)
{
long Pos = 0;
size_t Pos = 0;
while (Pos != tstring::npos)
{
@ -219,7 +220,7 @@ void CStr::Replace(const CStr &ToReplace, const CStr &ReplaceWith)
// returns a trimed string, removes whitespace from the left/right/both
CStr CStr::Trim(PS_TRIM_MODE Mode)
{
int Left, Right;
size_t Left, Right;
switch (Mode)
@ -394,3 +395,24 @@ ostream &operator<<(ostream &os, CStr &Str)
os << (const TCHAR*)Str;
return os;
}
uint CStr::GetSerializedLength() const
{
return m_String.length()+1;
}
u8 *CStr::Serialize(u8 *buffer) const
{
uint length=m_String.length();
memcpy(buffer, m_String.c_str(), length+1);
return buffer+length+1;
}
const u8 *CStr::Deserialize(const u8 *buffer, const u8 *bufferend)
{
u8 *strend=(u8 *)memchr(buffer, 0, bufferend-buffer);
if (strend == NULL)
return NULL;
*this=(char *)buffer;
return strend+1;
}

View File

@ -39,6 +39,7 @@ More Info:
#include "posix.h"
#include "misc.h"
#include "Network/Serialization.h"
#include <cstdlib>
using namespace std;
@ -85,7 +86,7 @@ enum PS_TRIM_MODE {PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH};
// CStr class, the mother of all strings
class CStr
class CStr: public ISerializable
{
public:
@ -112,7 +113,7 @@ public:
_float ToFloat() const;
_double ToDouble() const;
_long Length(){return m_String.length();}
size_t Length() const {return m_String.length();}
// Retrieves the substring within the string
CStr GetSubstring(_long start, _long len);
@ -171,6 +172,10 @@ public:
TCHAR &operator[](_long n);
TCHAR &operator[](_ulong n);
// Serialization functions
virtual uint GetSerializedLength() const;
virtual u8 *Serialize(u8 *buffer) const;
virtual const u8 *Deserialize(const u8 *buffer, const u8 *bufferend);
private:
tstring m_String;