//
// String.h - Header for custom string class
// By: Odis
//
#ifndef INC_STRING
#define INC_STRING
#ifndef DELETE_MACRO
#define DELETE_MACRO
#define KILL(point) \
do \
{ \
if(point) \
delete point; \
} while(0)
#endif
#include <string.h>
class String
{
public:
String(int length); // alloc a string that is -length- in size
String(const char *str); // make a string from this string
~String();
int Size() const { return strlen(mString); } // return the length minus the null terminator
unsigned int GetRef() const { return mRef; }
void AddRef() { mRef++; }; // add 1 to the ref count
void SubRef() // subtract 1 from the ref count, if 0 or below, unalloc
{
if ( --mRef <= 0 )
delete this;
}
const char *GetString()
{
if ( this->Size() > 0 )
return mString;
else
return NULL;
}
bool SetString(const char *str);
String *DupString(); // pointer to new memory containing string
bool Merge( String *str ); // returns false if they didnt merge, true of the str pointer
// was successfully merged and dealloced
void Kill() { this->SubRef(); } // kill this string
private:
char *mString; // Allocated string
unsigned int mRef; // Number of references
};
// compare two strings, return false if the same, case doesnt matter
bool StrCmp( const char *astr, const char *bstr );
#endif