Reformatting of class.h and class.cpp

This commit is contained in:
Walter Julius Hennecke 2012-12-31 21:19:39 +01:00
parent 2459be24a1
commit 862d4c102f
2 changed files with 449 additions and 507 deletions

View file

@ -51,28 +51,28 @@
int totalmemallocated = 0;
int numclassesallocated = 0;
static ClassDef *classlist = NULL;
static ClassDef* classlist = NULL;
ClassDef::ClassDef()
{
this->classname = NULL;
this->classname = NULL;
this->classID = NULL;
this->superclass = NULL;
this->responses = NULL;
this->numEvents = 0;
this->responseLookup = NULL;
this->responses = NULL;
this->numEvents = 0;
this->responseLookup = NULL;
this->newInstance = NULL;
this->classSize = 0;
this->classSize = 0;
this->super = NULL;
this->prev = this;
this->next = this;
}
ClassDef::ClassDef( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
void *( *newInstance )( void ), int classSize )
ClassDef::ClassDef( const char* classname, const char* classID, const char* superclass, ResponseDef<Class>* responses,
void* ( *newInstance )( void ), int classSize )
{
ClassDef *node;
ClassDef* node;
if ( classlist == NULL )
{
@ -80,14 +80,14 @@ ClassDef::ClassDef( const char *classname, const char *classID, const char *supe
}
this->classname = classname;
this->classID = classID;
this->superclass = superclass;
this->classID = classID;
this->superclass = superclass;
this->responses = responses;
this->numEvents = 0;
this->responseLookup = NULL;
this->newInstance = newInstance;
this->responseLookup = NULL;
this->newInstance = newInstance;
this->classSize = classSize;
this->super = getClass( superclass );
this->super = getClass( superclass );
// It's not uncommon for classes to not have a class id, so just set it
// to an empty string so that we're not checking for it all the time.
@ -121,7 +121,7 @@ void ClassDef::Shutdown( void )
ClassDef::~ClassDef()
{
ClassDef *node;
ClassDef* node;
if ( classlist != this )
{
@ -151,12 +151,12 @@ ClassDef::~ClassDef()
void ClassDef::BuildResponseList( void )
{
ClassDef *c;
ResponseDef<Class> *r;
int ev;
int i;
qboolean *set;
int num;
ClassDef* c;
ResponseDef<Class>* r;
int ev;
int i;
qboolean* set;
int num;
if ( responseLookup )
{
@ -202,9 +202,9 @@ void ClassDef::BuildResponseList( void )
void BuildEventResponses( void )
{
ClassDef *c;
int amount;
int numclasses;
ClassDef* c;
int amount;
int numclasses;
amount = 0;
numclasses = 0;
@ -220,9 +220,9 @@ void BuildEventResponses( void )
"%d classes %d events %d total memory in response list\n\n", numclasses, Event::NumEventCommands(), amount );
}
ClassDef *getClassForID( const char *name )
ClassDef* getClassForID( const char* name )
{
ClassDef *c;
ClassDef* c;
for( c = classlist->next; c != classlist; c = c->next )
{
@ -235,9 +235,9 @@ ClassDef *getClassForID( const char *name )
return NULL;
}
ClassDef *getClass( const char *name )
ClassDef* getClass( const char* name )
{
ClassDef *c;
ClassDef* c;
for( c = classlist->next; c != classlist; c = c->next )
{
@ -250,14 +250,14 @@ ClassDef *getClass( const char *name )
return NULL;
}
ClassDef *getClassList( void )
ClassDef* getClassList( void )
{
return classlist;
}
void listAllClasses( void )
{
ClassDef *c;
ClassDef* c;
for( c = classlist->next; c != classlist; c = c->next )
{
@ -265,10 +265,10 @@ void listAllClasses( void )
}
}
void listInheritanceOrder( const char *classname )
void listInheritanceOrder( const char* classname )
{
ClassDef *cls;
ClassDef *c;
ClassDef* cls;
ClassDef* c;
cls = getClass( classname );
if ( !cls )
@ -282,9 +282,9 @@ void listInheritanceOrder( const char *classname )
}
}
qboolean checkInheritance( const ClassDef *superclass, const ClassDef *subclass )
qboolean checkInheritance( const ClassDef* superclass, const ClassDef* subclass )
{
const ClassDef *c;
const ClassDef* c;
for( c = subclass; c != NULL; c = c->super )
{
@ -296,9 +296,9 @@ qboolean checkInheritance( const ClassDef *superclass, const ClassDef *subclass
return false;
}
qboolean checkInheritance( ClassDef *superclass, const char *subclass )
qboolean checkInheritance( ClassDef* superclass, const char* subclass )
{
ClassDef *c;
ClassDef* c;
c = getClass( subclass );
if ( c == NULL )
@ -309,10 +309,10 @@ qboolean checkInheritance( ClassDef *superclass, const char *subclass )
return checkInheritance( superclass, c );
}
qboolean checkInheritance( const char *superclass, const char *subclass )
qboolean checkInheritance( const char* superclass, const char* subclass )
{
ClassDef *c1;
ClassDef *c2;
ClassDef* c1;
ClassDef* c2;
c1 = getClass( superclass );
c2 = getClass( subclass );
@ -329,10 +329,10 @@ qboolean checkInheritance( const char *superclass, const char *subclass )
return checkInheritance( c1, c2 );
}
void CLASS_Print( FILE *class_file, const char *fmt, ... )
void CLASS_Print( FILE* class_file, const char* fmt, ... )
{
va_list argptr;
char text[ 1024 ];
char text[ 1024 ];
va_start( argptr, fmt );
vsprintf( text, fmt, argptr );
@ -351,9 +351,9 @@ CLASS_DECLARATION( NULL, Class, NULL )
#ifdef NDEBUG
void * Class::operator new( size_t s )
void* Class::operator new( size_t s )
{
int *p;
int* p;
if ( s == 0 )
return 0;
@ -372,9 +372,9 @@ void * Class::operator new( size_t s )
return p + 1;
}
void Class::operator delete( void *ptr )
void Class::operator delete( void* ptr )
{
int *p;
int* p;
p = ( ( int * )ptr ) - 1;
totalmemallocated -= *p;
@ -394,7 +394,7 @@ void Class::operator delete( void *ptr )
int classindex = 0;
#endif
void * Class::operator new( size_t s )
void* Class::operator new( size_t s )
{
int *p;
@ -420,9 +420,9 @@ void * Class::operator new( size_t s )
return p + 2;
}
void Class::operator delete( void *ptr )
void Class::operator delete( void* ptr )
{
int *p;
int* p;
p = ( ( int * )ptr ) - 2;
#ifndef MEMORY_LEAK_TEST
@ -475,10 +475,10 @@ void Class::ClearSafePointers( void )
}
void Class::warning( const char *function, const char *fmt, ... )
void Class::warning( const char* function, const char* fmt, ... )
{
va_list argptr;
char text[ 1024 ];
char text[ 1024 ];
va_start( argptr, fmt );
vsprintf( text, fmt, argptr );
@ -494,10 +494,10 @@ void Class::warning( const char *function, const char *fmt, ... )
}
}
void Class::error( const char *function, const char *fmt, ... )
void Class::error( const char* function, const char* fmt, ... )
{
va_list argptr;
char text[ 1024 ];
char text[ 1024 ];
va_start( argptr, fmt );
vsprintf( text, fmt, argptr );
@ -513,9 +513,9 @@ void Class::error( const char *function, const char *fmt, ... )
}
}
qboolean Class::inheritsFrom( const char *name ) const
qboolean Class::inheritsFrom( const char* name ) const
{
ClassDef *c;
ClassDef* c;
c = getClass( name );
if ( c == NULL )
@ -526,9 +526,9 @@ qboolean Class::inheritsFrom( const char *name ) const
return checkInheritance( c, classinfo() );
}
qboolean Class::isInheritedBy( const char *name ) const
qboolean Class::isInheritedBy( const char* name ) const
{
ClassDef *c;
ClassDef* c;
c = getClass( name );
if ( c == NULL )
@ -539,52 +539,52 @@ qboolean Class::isInheritedBy( const char *name ) const
return checkInheritance( classinfo(), c );
}
const char *Class::getClassname( void )
const char* Class::getClassname( void )
{
ClassDef *cls;
ClassDef* cls;
cls = classinfo();
return cls->classname;
}
const char *Class::getClassID( void )
const char* Class::getClassID( void )
{
ClassDef *cls;
ClassDef* cls;
cls = classinfo();
return cls->classID;
}
const char *Class::getSuperclass( void )
const char* Class::getSuperclass( void )
{
ClassDef *cls;
ClassDef* cls;
cls = classinfo();
return cls->superclass;
}
void *Class::newInstance( void )
void* Class::newInstance( void )
{
ClassDef *cls;
ClassDef* cls;
cls = classinfo();
return cls->newInstance();
}
#define MAX_INHERITANCE 64
void ClassEvents( const char *classname, qboolean print_to_disk )
void ClassEvents( const char* classname, qboolean print_to_disk )
{
ClassDef *c;
ResponseDef<Class> *r;
int ev;
int i, j;
qboolean *set;
int num, orderNum;
Event **events;
byte *order;
FILE *class_file;
str classNames[ MAX_INHERITANCE ];
str class_filename;
ClassDef* c;
ResponseDef<Class>* r;
int ev;
int i, j;
qboolean* set;
int num, orderNum;
Event** events;
byte* order;
FILE* class_file;
str classNames[ MAX_INHERITANCE ];
str class_filename;
c = getClass( classname );
if ( !c )
@ -608,7 +608,7 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
set = new qboolean[ num ];
memset( set, 0, sizeof( qboolean ) * num );
events = new Event *[ num ];
events = new Event*[ num ];
memset( events, 0, sizeof( Event * ) * num );
order = new byte[ num ];
@ -659,9 +659,9 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
index = Event::MapSortedEventIndex( i );
if ( events[ index ] && ( order[ index ] == j ) )
{
{
Event::PrintEventDocumentation( events[ index ], class_file );
}
}
}
}
@ -678,14 +678,14 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
static int dump_numclasses;
static int dump_numevents;
void DumpClass( FILE * class_file, const char * className, int typeFlag )
void DumpClass( FILE* class_file, const char* className, int typeFlag )
{
ClassDef *c;
ResponseDef<Class> *r;
int ev;
int i;
int num;
Event **events;
ClassDef* c;
ResponseDef<Class>* r;
int ev;
int i;
int num;
Event** events;
c = getClass( className );
if ( !c )
@ -747,7 +747,7 @@ void DumpClass( FILE * class_file, const char * className, int typeFlag )
delete[] events;
}
void DumpAllClasses( int typeFlag, int outputType, const char *filename )
void DumpAllClasses( int typeFlag, int outputType, const char* filename )
{
str defaultname;
#if defined( GAME_DLL )
@ -778,110 +778,110 @@ void DumpAllClasses( int typeFlag, int outputType, const char *filename )
delete dout;
}
/*
int i, j, num, smallest;
/*
int i, j, num, smallest;
ClassDef *c;
FILE * class_file;
str class_filename;
str class_title;
str classes[ MAX_CLASSES ];
FILE * class_file;
str class_filename;
str class_title;
str classes[ MAX_CLASSES ];
#if defined( GAME_DLL )
#if defined( GAME_DLL )
class_filename = "g_allclasses.html";
class_title = "Game Module";
#elif defined( CGAME_DLL )
class_title = "Game Module";
#elif defined( CGAME_DLL )
class_filename = "cg_allclasses.html";
class_title = "Client Game Module";
#else
class_title = "Client Game Module";
#else
class_filename = "cl_allclasses.html";
class_title = "Client Module";
#endif
class_title = "Client Module";
#endif
class_file = fopen( class_filename.c_str(), "w" );
if ( class_file == NULL )
return;
return;
// construct the HTML header for the document
CLASS_Print( class_file, "<HTML>\n");
CLASS_Print( class_file, "<HEAD>\n");
CLASS_Print( class_file, "<Title>%s Classes</Title>\n", class_title.c_str() );
CLASS_Print( class_file, "</HEAD>\n");
CLASS_Print( class_file, "<BODY>\n");
CLASS_Print( class_file, "<H1>\n");
CLASS_Print( class_file, "<center>%s Classes</center>\n", class_title.c_str() );
CLASS_Print( class_file, "</H1>\n");
#if defined( GAME_DLL )
//
// print out some commonly used classnames
//
CLASS_Print( class_file, "<h2>" );
CLASS_Print( class_file, "<a href=\"#Actor\">Actor</a>, " );
CLASS_Print( class_file, "<a href=\"#Animate\">Animate</a>, " );
CLASS_Print( class_file, "<a href=\"#Entity\">Entity</a>, " );
CLASS_Print( class_file, "<a href=\"#ScriptSlave\">ScriptSlave</a>, " );
CLASS_Print( class_file, "<a href=\"#ScriptThread\">ScriptThread</a>, " );
CLASS_Print( class_file, "<a href=\"#Sentient\">Sentient</a>, " );
CLASS_Print( class_file, "<a href=\"#Trigger\">Trigger</a>, " );
CLASS_Print( class_file, "<a href=\"#World\">World</a>" );
CLASS_Print( class_file, "</h2>" );
#endif
// construct the HTML header for the document
CLASS_Print( class_file, "<HTML>\n");
CLASS_Print( class_file, "<HEAD>\n");
CLASS_Print( class_file, "<Title>%s Classes</Title>\n", class_title.c_str() );
CLASS_Print( class_file, "</HEAD>\n");
CLASS_Print( class_file, "<BODY>\n");
CLASS_Print( class_file, "<H1>\n");
CLASS_Print( class_file, "<center>%s Classes</center>\n", class_title.c_str() );
CLASS_Print( class_file, "</H1>\n");
#if defined( GAME_DLL )
//
// print out some commonly used classnames
//
CLASS_Print( class_file, "<h2>" );
CLASS_Print( class_file, "<a href=\"#Actor\">Actor</a>, " );
CLASS_Print( class_file, "<a href=\"#Animate\">Animate</a>, " );
CLASS_Print( class_file, "<a href=\"#Entity\">Entity</a>, " );
CLASS_Print( class_file, "<a href=\"#ScriptSlave\">ScriptSlave</a>, " );
CLASS_Print( class_file, "<a href=\"#ScriptThread\">ScriptThread</a>, " );
CLASS_Print( class_file, "<a href=\"#Sentient\">Sentient</a>, " );
CLASS_Print( class_file, "<a href=\"#Trigger\">Trigger</a>, " );
CLASS_Print( class_file, "<a href=\"#World\">World</a>" );
CLASS_Print( class_file, "</h2>" );
#endif
dump_numclasses = 0;
dump_numevents = 0;
dump_numclasses = 0;
dump_numevents = 0;
// get all the classes
num = 0;
// get all the classes
num = 0;
for( c = classlist->next; c != classlist; c = c->next )
{
if ( num < MAX_CLASSES )
{
classes[ num++ ] = c->classname;
}
}
{
if ( num < MAX_CLASSES )
{
classes[ num++ ] = c->classname;
}
}
// go through and process each class from smallest to greatest
for( i = 0; i < num; i++ )
{
smallest = -1;
for( j = 0; j < num; j++ )
{
if ( classes[ j ].length() > 1 )
{
if ( smallest >= 0 )
{
if ( classes[ j ].icmp( classes[ smallest ] ) < 0 )
{
smallest = j;
}
}
else
{
smallest = j;
}
}
}
DumpClass( class_file, classes[ smallest ], typeFlag );
// delete the name from the list
classes[ smallest ] = "";
}
// go through and process each class from smallest to greatest
for( i = 0; i < num; i++ )
{
smallest = -1;
for( j = 0; j < num; j++ )
{
if ( classes[ j ].length() > 1 )
{
if ( smallest >= 0 )
{
if ( classes[ j ].icmp( classes[ smallest ] ) < 0 )
{
smallest = j;
}
}
else
{
smallest = j;
}
}
}
DumpClass( class_file, classes[ smallest ], typeFlag );
// delete the name from the list
classes[ smallest ] = "";
}
if ( class_file != NULL )
{
CLASS_Print( class_file, "<H2>\n");
CLASS_Print( class_file, "%d %s Classes.<BR>%d %s Events.\n", dump_numclasses, class_title.c_str(), dump_numevents, class_title.c_str() );
CLASS_Print( class_file, "</H2>\n");
CLASS_Print( class_file, "</BODY>\n");
CLASS_Print( class_file, "</HTML>\n");
CLASS_DPrintf( "Dumped all classes to file %s\n", class_filename.c_str() );
fclose( class_file );
}
*/
{
CLASS_Print( class_file, "<H2>\n");
CLASS_Print( class_file, "%d %s Classes.<BR>%d %s Events.\n", dump_numclasses, class_title.c_str(), dump_numevents, class_title.c_str() );
CLASS_Print( class_file, "</H2>\n");
CLASS_Print( class_file, "</BODY>\n");
CLASS_Print( class_file, "</HTML>\n");
CLASS_DPrintf( "Dumped all classes to file %s\n", class_filename.c_str() );
fclose( class_file );
}
*/
}
void ShutdownClasses( void )
{
ClassDef *c;
ClassDef* c;
for( c = classlist->next; c != classlist; c = c->next )
{

View file

@ -85,162 +85,154 @@ typedef void ( Class::*Response )( Event *event );
template< class Type >
struct ResponseDef
{
Event *event;
void ( Type::*response )( Event *event );
};
{
Event* event;
void ( Type::*response )( Event *event );
};
/***********************************************************************
ClassDef
ClassDef
***********************************************************************/
class ClassDef
{
public:
const char *classname;
const char *classID;
const char *superclass;
void *( *newInstance )( void );
int classSize;
ResponseDef<Class> *responses;
int numEvents;
Response **responseLookup;
ClassDef *super;
ClassDef *next;
ClassDef *prev;
{
public:
const char* classname;
const char* classID;
const char* superclass;
void* ( *newInstance )( void );
int classSize;
ResponseDef<Class>* responses;
int numEvents;
Response** responseLookup;
ClassDef* super;
ClassDef* next;
ClassDef* prev;
ClassDef();
~ClassDef();
ClassDef( const char *classname, const char *classID, const char *superclass,
ResponseDef<Class> *responses, void *( *newInstance )( void ), int classSize );
void BuildResponseList( void );
void Shutdown( void );
};
ClassDef();
~ClassDef();
ClassDef( const char* classname, const char* classID, const char* superclass, ResponseDef<Class>* responses, void* ( *newInstance )( void ), int classSize );
void BuildResponseList( void );
void Shutdown( void );
};
/***********************************************************************
SafePtr
SafePtr
***********************************************************************/
class SafePtrBase;
class Class;
class SafePtrBase
{
private:
void AddReference( Class *ptr );
void RemoveReference( Class *ptr );
{
private:
void AddReference( Class* ptr );
void RemoveReference( Class* ptr );
protected:
SafePtrBase *prevSafePtr;
SafePtrBase *nextSafePtr;
Class *ptr;
protected:
SafePtrBase* prevSafePtr;
SafePtrBase* nextSafePtr;
Class* ptr;
public:
SafePtrBase();
virtual ~SafePtrBase();
void InitSafePtr( Class *newptr );
Class *Pointer( void );
void Clear( void );
};
public:
SafePtrBase();
virtual ~SafePtrBase();
void InitSafePtr( Class* newptr );
Class* Pointer( void );
void Clear( void );
};
/***********************************************************************
Class
Class
***********************************************************************/
#define CLASS_DECLARATION( nameofsuperclass, nameofclass, classid ) \
ClassDef nameofclass::ClassInfo \
( \
#nameofclass, classid, #nameofsuperclass, \
( ResponseDef<Class> * )nameofclass::Responses, \
nameofclass::_newInstance, sizeof( nameofclass ) \
); \
void *nameofclass::_newInstance( void ) \
{ \
return new nameofclass; \
} \
ClassDef *nameofclass::classinfo( void ) const \
{ \
return &( nameofclass::ClassInfo ); \
} \
ResponseDef<nameofclass> nameofclass::Responses[] =
ClassDef nameofclass::ClassInfo \
( \
#nameofclass, classid, #nameofsuperclass, \
( ResponseDef<Class>* )nameofclass::Responses, \
nameofclass::_newInstance, sizeof( nameofclass ) \
); \
void* nameofclass::_newInstance( void ) \
{ \
return new nameofclass; \
} \
ClassDef* nameofclass::classinfo( void ) const \
{ \
return &( nameofclass::ClassInfo ); \
} \
ResponseDef<nameofclass> nameofclass::Responses[] =
#define CLASS_PROTOTYPE( nameofclass ) \
public: \
static ClassDef ClassInfo; \
static void *_newInstance( void ); \
virtual ClassDef *classinfo( void ) const; \
#define CLASS_PROTOTYPE( nameofclass ) \
public: \
static ClassDef ClassInfo; \
static void* _newInstance( void ); \
virtual ClassDef* classinfo( void ) const; \
static ResponseDef<nameofclass> Responses[]
class Class
{
private:
SafePtrBase *SafePtrList;
friend class SafePtrBase;
{
private:
SafePtrBase* SafePtrList;
friend class SafePtrBase;
protected:
void ClearSafePointers( void );
protected:
void ClearSafePointers( void );
public:
CLASS_PROTOTYPE( Class );
void * operator new( size_t );
void operator delete( void * );
public:
CLASS_PROTOTYPE( Class );
void* operator new( size_t );
void operator delete( void* );
Class();
virtual ~Class();
void warning( const char *function, const char *fmt, ... );
void error( const char *function, const char *fmt, ... );
qboolean inheritsFrom( ClassDef *c ) const;
qboolean inheritsFrom( const char *name ) const;
qboolean isInheritedBy( const char *name ) const;
qboolean isInheritedBy( ClassDef *c ) const;
const char *getClassname( void );
const char *getClassID( void );
const char *getSuperclass( void );
void *newInstance( void );
Class();
virtual ~Class();
void warning( const char* function, const char* fmt, ... );
void error( const char* function, const char* fmt, ... );
qboolean inheritsFrom( ClassDef* c ) const;
qboolean inheritsFrom( const char* name ) const;
qboolean isInheritedBy( const char* name ) const;
qboolean isInheritedBy( ClassDef* c ) const;
const char* getClassname( void );
const char* getClassID( void );
const char* getSuperclass( void );
void* newInstance( void );
#ifdef GAME_DLL
virtual void Archive( Archiver &arc );
virtual void Archive( Archiver &arc );
#endif
};
};
void BuildEventResponses( void );
ClassDef *getClassForID( const char *name );
ClassDef *getClass( const char *name );
ClassDef *getClassList( void );
ClassDef* getClassForID( const char* name );
ClassDef* getClass( const char* name );
ClassDef* getClassList( void );
void listAllClasses( void );
void listInheritanceOrder( const char *classname );
qboolean checkInheritance( const ClassDef * const superclass, const ClassDef * const subclass );
qboolean checkInheritance( ClassDef * const superclass, const char * const subclass );
qboolean checkInheritance( const char * const superclass, const char * const subclass );
void DisplayMemoryUsage( void );
void ClassEvents( const char *classname, qboolean dump = false );
void DumpAllClasses( int typeFlag = EVENT_ALL, int outputType = OUTPUT_ALL, const char *filename = NULL);
void DumpClass( FILE * class_file, const char * className, int typeFlag = 0);
void listInheritanceOrder( const char* classname );
qboolean checkInheritance( const ClassDef* const superclass, const ClassDef* const subclass );
qboolean checkInheritance( ClassDef* const superclass, const char* const subclass );
qboolean checkInheritance( const char* const superclass, const char* const subclass );
void DisplayMemoryUsage( void );
void ClassEvents( const char* classname, qboolean dump = false );
void DumpAllClasses( int typeFlag = EVENT_ALL, int outputType = OUTPUT_ALL, const char* filename = NULL);
void DumpClass( FILE* class_file, const char* className, int typeFlag = 0);
inline qboolean Class::inheritsFrom
(
ClassDef *c
) const
{
inline qboolean Class::inheritsFrom(ClassDef* c) const
{
return checkInheritance( c, classinfo() );
}
}
inline qboolean Class::isInheritedBy
(
ClassDef *c
) const
{
inline qboolean Class::isInheritedBy(ClassDef*c ) const
{
return checkInheritance( classinfo(), c );
}
}
// The lack of a space between the ")" and "inheritsFrom" is intentional.
// It allows the macro to compile like a function call. However, this
@ -252,239 +244,189 @@ inline qboolean Class::isInheritedBy
/***********************************************************************
SafePtr
SafePtr
***********************************************************************/
inline void SafePtrBase::AddReference
(
Class *ptr
)
{
inline void SafePtrBase::AddReference(Class* ptr)
{
if ( !ptr->SafePtrList )
{
{
ptr->SafePtrList = this;
LL_Reset( this, nextSafePtr, prevSafePtr );
}
else
{
LL_Add( ptr->SafePtrList, this, nextSafePtr, prevSafePtr );
}
}
inline void SafePtrBase::RemoveReference
(
Class *ptr
)
else
{
LL_Add( ptr->SafePtrList, this, nextSafePtr, prevSafePtr );
}
}
inline void SafePtrBase::RemoveReference(Class* ptr)
{
if ( ptr->SafePtrList == this )
{
{
if ( ptr->SafePtrList->nextSafePtr == this )
{
{
ptr->SafePtrList = NULL;
}
}
else
{
{
ptr->SafePtrList = nextSafePtr;
LL_Remove( this, nextSafePtr, prevSafePtr );
}
}
else
{
LL_Remove( this, nextSafePtr, prevSafePtr );
}
}
inline void SafePtrBase::Clear
(
void
)
else
{
LL_Remove( this, nextSafePtr, prevSafePtr );
}
}
inline void SafePtrBase::Clear(void)
{
if ( ptr )
{
{
RemoveReference( ptr );
ptr = NULL;
}
}
}
inline SafePtrBase::SafePtrBase()
{
prevSafePtr = NULL;
{
prevSafePtr = NULL;
nextSafePtr = NULL;
ptr = NULL;
}
ptr = NULL;
}
inline SafePtrBase::~SafePtrBase()
{
Clear();
}
{
Clear();
}
inline Class * SafePtrBase::Pointer
(
void
)
inline Class* SafePtrBase::Pointer(void)
{
return ptr;
}
{
return ptr;
}
inline void SafePtrBase::InitSafePtr
(
Class *newptr
)
{
inline void SafePtrBase::InitSafePtr(Class* newptr)
{
if ( ptr != newptr )
{
{
if ( ptr )
{
{
RemoveReference( ptr );
}
}
ptr = newptr;
if ( ptr == NULL )
{
return;
}
if ( ptr == NULL )
{
return;
}
AddReference( ptr );
}
AddReference( ptr );
}
}
template<class T>
class SafePtr : public SafePtrBase
{
public:
SafePtr( T* objptr = 0 );
SafePtr( const SafePtr& obj );
{
public:
SafePtr( T* objptr = 0 );
SafePtr( const SafePtr& obj );
SafePtr& operator=( const SafePtr& obj );
SafePtr& operator=( T * const obj );
SafePtr& operator=( const SafePtr& obj );
SafePtr& operator=( T* const obj );
template <class F> friend int operator==( SafePtr<F> a, F *b );
template <class F> friend int operator!=( SafePtr<F> a, F *b );
template <class F> friend int operator==( F *a, SafePtr<F> b );
template <class F> friend int operator!=( F *a, SafePtr<F> b );
template <class F> friend int operator==( SafePtr<F> a, SafePtr<F> b );
template <class F> friend int operator!=( SafePtr<F> a, SafePtr<F> b );
template <class F> friend int operator==( SafePtr<F> a, F* b );
template <class F> friend int operator!=( SafePtr<F> a, F* b );
template <class F> friend int operator==( F* a, SafePtr<F> b );
template <class F> friend int operator!=( F* a, SafePtr<F> b );
template <class F> friend int operator==( SafePtr<F> a, SafePtr<F> b );
template <class F> friend int operator!=( SafePtr<F> a, SafePtr<F> b );
operator T*() const;
T* operator->() const;
T& operator*() const;
};
operator T*() const;
T* operator->() const;
T& operator*() const;
};
template<class T>
inline SafePtr<T>::SafePtr( T* objptr )
{
InitSafePtr( objptr );
}
{
InitSafePtr( objptr );
}
template<class T>
inline SafePtr<T>::SafePtr( const SafePtr& obj )
{
InitSafePtr( obj.ptr );
}
{
InitSafePtr( obj.ptr );
}
template<class T>
inline SafePtr<T>& SafePtr<T>::operator=( const SafePtr& obj )
{
InitSafePtr( obj.ptr );
{
InitSafePtr( obj.ptr );
return *this;
}
}
template<class T>
inline SafePtr<T>& SafePtr<T>::operator=( T * const obj )
{
InitSafePtr( obj );
inline SafePtr<T>& SafePtr<T>::operator=( T* const obj )
{
InitSafePtr( obj );
return *this;
}
}
template<class T>
inline int operator==
(
SafePtr<T> a,
T* b
)
{
inline int operator==(SafePtr<T> a, T* b)
{
return a.ptr == b;
}
}
template<class T>
inline int operator!=
(
SafePtr<T> a,
T* b
)
{
inline int operator!=(SafePtr<T> a, T* b)
{
return a.ptr != b;
}
}
template<class T>
inline int operator==
(
T* a,
SafePtr<T> b
)
{
inline int operator==(T* a, SafePtr<T> b)
{
return a == b.ptr;
}
}
template<class T>
inline int operator!=
(
T* a,
SafePtr<T> b
)
{
inline int operator!=(T* a, SafePtr<T> b)
{
return a != b.ptr;
}
}
template<class T>
inline int operator==
(
SafePtr<T> a,
SafePtr<T> b
)
{
inline int operator==(SafePtr<T> a, SafePtr<T> b)
{
return a.ptr == b.ptr;
}
}
template<class T>
inline int operator!=
(
SafePtr<T> a,
SafePtr<T> b
)
{
inline int operator!=(SafePtr<T> a,SafePtr<T> b)
{
return a.ptr != b.ptr;
}
}
template<class T>
inline SafePtr<T>::operator T*() const
{
{
return ( T * )ptr;
}
}
template<class T>
inline T* SafePtr<T>::operator->() const
{
{
return ( T * )ptr;
}
}
template<class T>
inline T& SafePtr<T>::operator*() const
{
{
return *( T * )ptr;
}
}
typedef SafePtr<Class> ClassPtr;
@ -497,10 +439,10 @@ extern int totalmemallocated;
#ifndef GAME_DLL
extern "C"
{
// interface functions
void ShutdownClasses( void );
}
{
// interface functions
void ShutdownClasses( void );
}
#endif
#endif /* class.h */