1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-21 12:49:10 +00:00

plGenericVar => plString

- Also fixes a bug in plGenericType::CopyFrom, where doubles would get
  only half copied (and therefore become corrupt)
This commit is contained in:
2014-01-11 12:10:07 -08:00
parent a783642515
commit 0c1783b2f3
5 changed files with 53 additions and 141 deletions

View File

@ -53,21 +53,18 @@ class hsStream;
//
class plGenericType
{
public:
typedef char* CharPtr;
protected:
union
{
int32_t fI;
uint32_t fU;
int32_t fI;
uint32_t fU;
float fF;
double fD;
bool fB;
CharPtr fS;
char fC;
};
plString fS;
public:
enum Types
@ -86,20 +83,19 @@ public:
protected:
uint8_t fType;
const int32_t &IToInt( void ) const;
const uint32_t &IToUInt( void ) const;
const float &IToFloat( void ) const;
const double &IToDouble( void ) const;
const bool &IToBool( void ) const;
const CharPtr &IToString( void ) const;
const char &IToChar( void ) const;
int32_t IToInt( void ) const;
uint32_t IToUInt( void ) const;
float IToFloat( void ) const;
double IToDouble( void ) const;
bool IToBool( void ) const;
plString IToString( void ) const;
char IToChar( void ) const;
void IDeallocString() { if (fType==kString || fType==kAny) {delete [] fS; fS=nil;} }
public:
plGenericType() : fType(kNone) { Reset(); }
plGenericType(const plGenericType& c) { CopyFrom(c); }
virtual ~plGenericType() { IDeallocString(); }
virtual ~plGenericType() { }
plGenericType& operator=(const plGenericType& c) { CopyFrom(c); return *this; }
@ -110,34 +106,33 @@ public:
operator double() const { return IToDouble(); }
operator float() const { return IToFloat(); }
operator bool() const { return IToBool(); }
operator const CharPtr() const { return IToString(); }
operator plString() const { return IToString(); }
operator char() const { return IToChar(); }
void SetType(Types t) { fType=t; }
uint8_t GetType( void ) const { return fType; }
uint8_t GetType( void ) const { return fType; }
plString GetAsString() const;
// implicit set
void Set( int32_t i ) { fI = i; fType = kInt; }
void Set( uint32_t i ) { fU = i; fType = kUInt; }
void Set( int32_t i ) { fI = i; fType = kInt; }
void Set( uint32_t i ) { fU = i; fType = kUInt; }
void Set( float f ) { fF = f; fType = kFloat; }
void Set( double d ) { fD = d; fType = kDouble; }
void Set( bool b ) { fB = b; fType = kBool; }
void Set( CharPtr s ) { IDeallocString(); fS = hsStrcpy(s); fType = kString; }
void Set( const plString& s ) { fS = s; fType = kString; }
void Set( char c ) { fC = c; fType = kChar; }
// explicit set
void SetInt( int32_t i ) { fI = i; fType = kInt; }
void SetUInt( uint32_t i ) { fU = i; fType = kUInt; }
void SetInt( int32_t i ) { fI = i; fType = kInt; }
void SetUInt( uint32_t i ) { fU = i; fType = kUInt; }
void SetFloat( float f ) { fF = f; fType = kFloat; }
void SetDouble( double d ) { fD = d; fType = kDouble; }
void SetBool( bool b ) { fB = b; fType = kBool; }
void SetString( CharPtr s ) { IDeallocString(); fS = hsStrcpy(s); fType = kString; }
void SetString( const plString& s ) { fS = s; fType = kString; }
void SetChar( char c ) { fC = c; fType = kChar; }
void SetAny( CharPtr s ) { IDeallocString(); fS = hsStrcpy(s); fType = kAny; }
void SetAny( const plString& s ) { fS = s; fType = kAny; }
void SetNone( void ) { fType = kNone; }
void SetVar(Types t, unsigned int size, void* val);
virtual void Read(hsStream* s);
virtual void Write(hsStream* s);
@ -150,17 +145,17 @@ class plGenericVar
{
protected:
plGenericType fValue;
char* fName;
plString fName;
public:
plGenericVar(const plGenericVar &c) : fName(nil) { CopyFrom(c); }
plGenericVar(const char* name=nil) : fName(nil) { SetName(name); }
virtual ~plGenericVar() { delete [] fName; }
plGenericVar(const plGenericVar &c) { CopyFrom(c); }
plGenericVar(const plString& name="") : fName(name) { }
virtual ~plGenericVar() { }
virtual void Reset() { Value().Reset(); } // reset runtime state, not inherent state
plGenericVar& operator=(const plGenericVar &c) { CopyFrom(c); return *this; }
void CopyFrom(const plGenericVar &c) { delete [] fName; fName=hsStrcpy(c.GetName()); fValue=c.Value(); }
const char* GetName() const { return fName; }
void SetName(const char* n) { delete [] fName; fName = hsStrcpy(n); }
void CopyFrom(const plGenericVar &c) { fName=c.GetName(); fValue=c.Value(); }
plString GetName() const { return fName; }
void SetName(const plString& n) { fName = n; }
plGenericType& Value() { return fValue; }
const plGenericType& Value() const { return fValue; }
@ -186,7 +181,7 @@ public:
operator float() const { return (float)fValue; }
operator double() const { return (double)fValue; }
operator bool() const { return (bool)fValue; }
operator const char *() const { return (const char *)fValue; }
operator plString() const { return (plString)fValue; }
operator char() const { return (char)fValue; }
};