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,51 +51,51 @@
int totalmemallocated = 0; int totalmemallocated = 0;
int numclassesallocated = 0; int numclassesallocated = 0;
static ClassDef *classlist = NULL; static ClassDef* classlist = NULL;
ClassDef::ClassDef() ClassDef::ClassDef()
{ {
this->classname = NULL; this->classname = NULL;
this->classID = NULL; this->classID = NULL;
this->superclass = NULL; this->superclass = NULL;
this->responses = NULL; this->responses = NULL;
this->numEvents = 0; this->numEvents = 0;
this->responseLookup = NULL; this->responseLookup = NULL;
this->newInstance = NULL; this->newInstance = NULL;
this->classSize = 0; this->classSize = 0;
this->super = NULL; this->super = NULL;
this->prev = this; this->prev = this;
this->next = this; this->next = this;
} }
ClassDef::ClassDef( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses, ClassDef::ClassDef( const char* classname, const char* classID, const char* superclass, ResponseDef<Class>* responses,
void *( *newInstance )( void ), int classSize ) void* ( *newInstance )( void ), int classSize )
{ {
ClassDef *node; ClassDef* node;
if ( classlist == NULL ) if ( classlist == NULL )
{ {
classlist = new ClassDef; classlist = new ClassDef;
} }
this->classname = classname; this->classname = classname;
this->classID = classID; this->classID = classID;
this->superclass = superclass; this->superclass = superclass;
this->responses = responses; this->responses = responses;
this->numEvents = 0; this->numEvents = 0;
this->responseLookup = NULL; this->responseLookup = NULL;
this->newInstance = newInstance; this->newInstance = newInstance;
this->classSize = classSize; 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 // 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. // to an empty string so that we're not checking for it all the time.
if ( !classID ) if ( !classID )
{ {
this->classID = ""; this->classID = "";
} }
// Check if any subclasses were initialized before their superclass // Check if any subclasses were initialized before their superclass
for( node = classlist->next; node != classlist; node = node->next ) for( node = classlist->next; node != classlist; node = node->next )
{ {
@ -105,7 +105,7 @@ ClassDef::ClassDef( const char *classname, const char *classID, const char *supe
node->super = this; node->super = this;
} }
} }
// Add to front of list // Add to front of list
LL_Add( classlist, this, prev, next ); LL_Add( classlist, this, prev, next );
} }
@ -121,12 +121,12 @@ void ClassDef::Shutdown( void )
ClassDef::~ClassDef() ClassDef::~ClassDef()
{ {
ClassDef *node; ClassDef* node;
if ( classlist != this ) if ( classlist != this )
{ {
LL_Remove( this, prev, next ); LL_Remove( this, prev, next );
// Check if any subclasses were initialized before their superclass // Check if any subclasses were initialized before their superclass
for( node = classlist->next; node != classlist; node = node->next ) for( node = classlist->next; node != classlist; node = node->next )
{ {
@ -141,7 +141,7 @@ ClassDef::~ClassDef()
// If the head of the list is deleted before the list is cleared, then we may have problems // If the head of the list is deleted before the list is cleared, then we may have problems
assert( this->next == this->prev ); assert( this->next == this->prev );
} }
if ( responseLookup ) if ( responseLookup )
{ {
delete[] responseLookup; delete[] responseLookup;
@ -151,28 +151,28 @@ ClassDef::~ClassDef()
void ClassDef::BuildResponseList( void ) void ClassDef::BuildResponseList( void )
{ {
ClassDef *c; ClassDef* c;
ResponseDef<Class> *r; ResponseDef<Class>* r;
int ev; int ev;
int i; int i;
qboolean *set; qboolean* set;
int num; int num;
if ( responseLookup ) if ( responseLookup )
{ {
delete[] responseLookup; delete[] responseLookup;
responseLookup = NULL; responseLookup = NULL;
} }
num = Event::NumEventCommands(); num = Event::NumEventCommands();
responseLookup = ( Response ** )new char[ sizeof( Response * ) * num ]; responseLookup = ( Response ** )new char[ sizeof( Response * ) * num ];
memset( responseLookup, 0, sizeof( Response * ) * num ); memset( responseLookup, 0, sizeof( Response * ) * num );
set = new qboolean[ num ]; set = new qboolean[ num ];
memset( set, 0, sizeof( qboolean ) * num ); memset( set, 0, sizeof( qboolean ) * num );
this->numEvents = num; this->numEvents = num;
for( c = this; c != NULL; c = c->super ) for( c = this; c != NULL; c = c->super )
{ {
r = c->responses; r = c->responses;
@ -196,34 +196,34 @@ void ClassDef::BuildResponseList( void )
} }
} }
} }
delete[] set; delete[] set;
} }
void BuildEventResponses( void ) void BuildEventResponses( void )
{ {
ClassDef *c; ClassDef* c;
int amount; int amount;
int numclasses; int numclasses;
amount = 0; amount = 0;
numclasses = 0; numclasses = 0;
for( c = classlist->next; c != classlist; c = c->next ) for( c = classlist->next; c != classlist; c = c->next )
{ {
c->BuildResponseList(); c->BuildResponseList();
amount += c->numEvents * sizeof( Response * ); amount += c->numEvents * sizeof( Response * );
numclasses++; numclasses++;
} }
CLASS_DPrintf( "\n------------------\nEvent system initialized: " CLASS_DPrintf( "\n------------------\nEvent system initialized: "
"%d classes %d events %d total memory in response list\n\n", numclasses, Event::NumEventCommands(), amount ); "%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 ) for( c = classlist->next; c != classlist; c = c->next )
{ {
if ( c->classID && !Q_stricmp( c->classID, name ) ) if ( c->classID && !Q_stricmp( c->classID, name ) )
@ -231,14 +231,14 @@ ClassDef *getClassForID( const char *name )
return c; return c;
} }
} }
return NULL; 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 ) for( c = classlist->next; c != classlist; c = c->next )
{ {
if ( !Q_stricmp( c->classname, name ) ) if ( !Q_stricmp( c->classname, name ) )
@ -246,30 +246,30 @@ ClassDef *getClass( const char *name )
return c; return c;
} }
} }
return NULL; return NULL;
} }
ClassDef *getClassList( void ) ClassDef* getClassList( void )
{ {
return classlist; return classlist;
} }
void listAllClasses( void ) void listAllClasses( void )
{ {
ClassDef *c; ClassDef* c;
for( c = classlist->next; c != classlist; c = c->next ) for( c = classlist->next; c != classlist; c = c->next )
{ {
CLASS_DPrintf( "%s\n", c->classname ); CLASS_DPrintf( "%s\n", c->classname );
} }
} }
void listInheritanceOrder( const char *classname ) void listInheritanceOrder( const char* classname )
{ {
ClassDef *cls; ClassDef* cls;
ClassDef *c; ClassDef* c;
cls = getClass( classname ); cls = getClass( classname );
if ( !cls ) if ( !cls )
{ {
@ -282,10 +282,10 @@ 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 ) for( c = subclass; c != NULL; c = c->super )
{ {
if ( c == superclass ) if ( c == superclass )
@ -296,10 +296,10 @@ qboolean checkInheritance( const ClassDef *superclass, const ClassDef *subclass
return false; return false;
} }
qboolean checkInheritance( ClassDef *superclass, const char *subclass ) qboolean checkInheritance( ClassDef* superclass, const char* subclass )
{ {
ClassDef *c; ClassDef* c;
c = getClass( subclass ); c = getClass( subclass );
if ( c == NULL ) if ( c == NULL )
{ {
@ -309,11 +309,11 @@ qboolean checkInheritance( ClassDef *superclass, const char *subclass )
return checkInheritance( superclass, c ); return checkInheritance( superclass, c );
} }
qboolean checkInheritance( const char *superclass, const char *subclass ) qboolean checkInheritance( const char* superclass, const char* subclass )
{ {
ClassDef *c1; ClassDef* c1;
ClassDef *c2; ClassDef* c2;
c1 = getClass( superclass ); c1 = getClass( superclass );
c2 = getClass( subclass ); c2 = getClass( subclass );
if ( c1 == NULL ) if ( c1 == NULL )
@ -329,15 +329,15 @@ qboolean checkInheritance( const char *superclass, const char *subclass )
return checkInheritance( c1, c2 ); 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; va_list argptr;
char text[ 1024 ]; char text[ 1024 ];
va_start( argptr, fmt ); va_start( argptr, fmt );
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
if ( class_file ) if ( class_file )
fprintf( class_file, text ); fprintf( class_file, text );
else else
@ -351,13 +351,13 @@ CLASS_DECLARATION( NULL, Class, NULL )
#ifdef NDEBUG #ifdef NDEBUG
void * Class::operator new( size_t s ) void* Class::operator new( size_t s )
{ {
int *p; int* p;
if ( s == 0 ) if ( s == 0 )
return 0; return 0;
s += sizeof( int ); s += sizeof( int );
#if defined( GAME_DLL ) #if defined( GAME_DLL )
p = ( int * )gi.Malloc( s ); p = ( int * )gi.Malloc( s );
@ -372,10 +372,10 @@ void * Class::operator new( size_t s )
return p + 1; return p + 1;
} }
void Class::operator delete( void *ptr ) void Class::operator delete( void* ptr )
{ {
int *p; int* p;
p = ( ( int * )ptr ) - 1; p = ( ( int * )ptr ) - 1;
totalmemallocated -= *p; totalmemallocated -= *p;
numclassesallocated--; numclassesallocated--;
@ -394,10 +394,10 @@ void Class::operator delete( void *ptr )
int classindex = 0; int classindex = 0;
#endif #endif
void * Class::operator new( size_t s ) void* Class::operator new( size_t s )
{ {
int *p; int *p;
s += sizeof( int ) * 3; s += sizeof( int ) * 3;
#if defined( GAME_DLL ) #if defined( GAME_DLL )
p = ( int * )gi.Malloc( s ); p = ( int * )gi.Malloc( s );
@ -420,16 +420,16 @@ void * Class::operator new( size_t s )
return p + 2; return p + 2;
} }
void Class::operator delete( void *ptr ) void Class::operator delete( void* ptr )
{ {
int *p; int* p;
p = ( ( int * )ptr ) - 2; p = ( ( int * )ptr ) - 2;
#ifndef MEMORY_LEAK_TEST #ifndef MEMORY_LEAK_TEST
assert( p[ 0 ] == 0x12348765 ); assert( p[ 0 ] == 0x12348765 );
#endif #endif
assert( *( int * )( ((byte *)p) + p[ 1 ] - sizeof( int ) ) == 0x56784321 ); assert( *( int * )( ((byte *)p) + p[ 1 ] - sizeof( int ) ) == 0x56784321 );
totalmemallocated -= p[ 1 ]; totalmemallocated -= p[ 1 ];
numclassesallocated--; numclassesallocated--;
#if defined( GAME_DLL ) #if defined( GAME_DLL )
@ -475,15 +475,15 @@ 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; va_list argptr;
char text[ 1024 ]; char text[ 1024 ];
va_start( argptr, fmt ); va_start( argptr, fmt );
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
if ( getClassID() ) if ( getClassID() )
{ {
CLASS_WDPrintf( "%s::%s : %s\n", getClassID(), function, text ); CLASS_WDPrintf( "%s::%s : %s\n", getClassID(), function, text );
@ -494,15 +494,15 @@ 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; va_list argptr;
char text[ 1024 ]; char text[ 1024 ];
va_start( argptr, fmt ); va_start( argptr, fmt );
vsprintf( text, fmt, argptr ); vsprintf( text, fmt, argptr );
va_end( argptr ); va_end( argptr );
if ( getClassID() ) if ( getClassID() )
{ {
CLASS_Error( ERR_DROP, "%s::%s : %s\n", getClassID(), function, text ); CLASS_Error( ERR_DROP, "%s::%s : %s\n", getClassID(), function, text );
@ -513,10 +513,10 @@ 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 ); c = getClass( name );
if ( c == NULL ) if ( c == NULL )
{ {
@ -526,10 +526,10 @@ qboolean Class::inheritsFrom( const char *name ) const
return checkInheritance( c, classinfo() ); 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 ); c = getClass( name );
if ( c == NULL ) if ( c == NULL )
{ {
@ -539,62 +539,62 @@ qboolean Class::isInheritedBy( const char *name ) const
return checkInheritance( classinfo(), c ); return checkInheritance( classinfo(), c );
} }
const char *Class::getClassname( void ) const char* Class::getClassname( void )
{ {
ClassDef *cls; ClassDef* cls;
cls = classinfo(); cls = classinfo();
return cls->classname; return cls->classname;
} }
const char *Class::getClassID( void ) const char* Class::getClassID( void )
{ {
ClassDef *cls; ClassDef* cls;
cls = classinfo(); cls = classinfo();
return cls->classID; return cls->classID;
} }
const char *Class::getSuperclass( void ) const char* Class::getSuperclass( void )
{ {
ClassDef *cls; ClassDef* cls;
cls = classinfo(); cls = classinfo();
return cls->superclass; return cls->superclass;
} }
void *Class::newInstance( void ) void* Class::newInstance( void )
{ {
ClassDef *cls; ClassDef* cls;
cls = classinfo(); cls = classinfo();
return cls->newInstance(); return cls->newInstance();
} }
#define MAX_INHERITANCE 64 #define MAX_INHERITANCE 64
void ClassEvents( const char *classname, qboolean print_to_disk ) void ClassEvents( const char* classname, qboolean print_to_disk )
{ {
ClassDef *c; ClassDef* c;
ResponseDef<Class> *r; ResponseDef<Class>* r;
int ev; int ev;
int i, j; int i, j;
qboolean *set; qboolean* set;
int num, orderNum; int num, orderNum;
Event **events; Event** events;
byte *order; byte* order;
FILE *class_file; FILE* class_file;
str classNames[ MAX_INHERITANCE ]; str classNames[ MAX_INHERITANCE ];
str class_filename; str class_filename;
c = getClass( classname ); c = getClass( classname );
if ( !c ) if ( !c )
{ {
CLASS_WDPrintf( "Unknown class: %s\n", classname ); CLASS_WDPrintf( "Unknown class: %s\n", classname );
return; return;
} }
class_file = NULL; class_file = NULL;
if ( print_to_disk ) if ( print_to_disk )
{ {
class_filename = str ( classname ) + ".txt"; class_filename = str ( classname ) + ".txt";
@ -602,18 +602,18 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
if ( class_file == NULL ) if ( class_file == NULL )
return; return;
} }
num = Event::NumEventCommands(); num = Event::NumEventCommands();
set = new qboolean[ num ]; set = new qboolean[ num ];
memset( set, 0, sizeof( qboolean ) * num ); memset( set, 0, sizeof( qboolean ) * num );
events = new Event *[ num ]; events = new Event*[ num ];
memset( events, 0, sizeof( Event * ) * num ); memset( events, 0, sizeof( Event * ) * num );
order = new byte[ num ]; order = new byte[ num ];
memset( order, 0, sizeof( byte ) * num ); memset( order, 0, sizeof( byte ) * num );
orderNum = 0; orderNum = 0;
for( ; c != NULL; c = c->super ) for( ; c != NULL; c = c->super )
{ {
@ -630,7 +630,7 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
if ( !set[ ev ] ) if ( !set[ ev ] )
{ {
set[ ev ] = true; set[ ev ] = true;
if ( r[ i ].response ) if ( r[ i ].response )
{ {
events[ ev ] = r[ i ].event; events[ ev ] = r[ i ].event;
@ -641,13 +641,13 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
} }
orderNum++; orderNum++;
} }
CLASS_Print( class_file, "********************************************************\n" ); CLASS_Print( class_file, "********************************************************\n" );
CLASS_Print( class_file, "********************************************************\n" ); CLASS_Print( class_file, "********************************************************\n" );
CLASS_Print( class_file, "* All Events For Class: %s\n", classname ); CLASS_Print( class_file, "* All Events For Class: %s\n", classname );
CLASS_Print( class_file, "********************************************************\n" ); CLASS_Print( class_file, "********************************************************\n" );
CLASS_Print( class_file, "********************************************************\n\n" ); CLASS_Print( class_file, "********************************************************\n\n" );
for( j = orderNum - 1; j >= 0; j-- ) for( j = orderNum - 1; j >= 0; j-- )
{ {
CLASS_Print( class_file, "\n********************************************************\n" ); CLASS_Print( class_file, "\n********************************************************\n" );
@ -656,21 +656,21 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
for( i = 1; i < num; i++ ) for( i = 1; i < num; i++ )
{ {
int index; int index;
index = Event::MapSortedEventIndex( i ); index = Event::MapSortedEventIndex( i );
if ( events[ index ] && ( order[ index ] == j ) ) if ( events[ index ] && ( order[ index ] == j ) )
{ {
Event::PrintEventDocumentation( events[ index ], class_file ); Event::PrintEventDocumentation( events[ index ], class_file );
} }
} }
} }
if ( class_file != NULL ) if ( class_file != NULL )
{ {
CLASS_DPrintf( "Printed class info to file %s\n", class_filename.c_str() ); CLASS_DPrintf( "Printed class info to file %s\n", class_filename.c_str() );
fclose( class_file ); fclose( class_file );
} }
delete[] events; delete[] events;
delete[] order; delete[] order;
delete[] set; delete[] set;
@ -678,26 +678,26 @@ void ClassEvents( const char *classname, qboolean print_to_disk )
static int dump_numclasses; static int dump_numclasses;
static int dump_numevents; 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; ClassDef* c;
ResponseDef<Class> *r; ResponseDef<Class>* r;
int ev; int ev;
int i; int i;
int num; int num;
Event **events; Event** events;
c = getClass( className ); c = getClass( className );
if ( !c ) if ( !c )
{ {
return; return;
} }
num = Event::NumEventCommands(); num = Event::NumEventCommands();
events = new Event *[ num ]; events = new Event *[ num ];
memset( events, 0, sizeof( Event * ) * num ); memset( events, 0, sizeof( Event * ) * num );
// gather event responses for this class // gather event responses for this class
r = c->responses; r = c->responses;
if ( r ) if ( r )
@ -711,7 +711,7 @@ void DumpClass( FILE * class_file, const char * className, int typeFlag )
} }
} }
} }
CLASS_Print( class_file, "\n"); CLASS_Print( class_file, "\n");
if ( c->classID[ 0 ] ) if ( c->classID[ 0 ] )
{ {
@ -721,21 +721,21 @@ void DumpClass( FILE * class_file, const char * className, int typeFlag )
{ {
CLASS_Print( class_file, "<h2> <a name=\"%s\">%s</a>", c->classname, c->classname ); CLASS_Print( class_file, "<h2> <a name=\"%s\">%s</a>", c->classname, c->classname );
} }
// print out lineage // print out lineage
for( c = c->super; c != NULL; c = c->super ) for( c = c->super; c != NULL; c = c->super )
{ {
CLASS_Print( class_file, " -> <a href=\"#%s\">%s</a>", c->classname, c->classname ); CLASS_Print( class_file, " -> <a href=\"#%s\">%s</a>", c->classname, c->classname );
} }
CLASS_Print( class_file, "</h2>\n"); CLASS_Print( class_file, "</h2>\n");
dump_numclasses++; dump_numclasses++;
CLASS_Print( class_file, "<BLOCKQUOTE>\n"); CLASS_Print( class_file, "<BLOCKQUOTE>\n");
for( i = 1; i < num; i++ ) for( i = 1; i < num; i++ )
{ {
int index; int index;
index = Event::MapSortedEventIndex( i ); index = Event::MapSortedEventIndex( i );
if ( events[ index ] ) if ( events[ index ] )
{ {
@ -747,7 +747,7 @@ void DumpClass( FILE * class_file, const char * className, int typeFlag )
delete[] events; delete[] events;
} }
void DumpAllClasses( int typeFlag, int outputType, const char *filename ) void DumpAllClasses( int typeFlag, int outputType, const char* filename )
{ {
str defaultname; str defaultname;
#if defined( GAME_DLL ) #if defined( GAME_DLL )
@ -757,7 +757,7 @@ void DumpAllClasses( int typeFlag, int outputType, const char *filename )
#else #else
defaultname = "cl_allclasses"; defaultname = "cl_allclasses";
#endif #endif
if ( outputType == OUTPUT_HTML || !outputType ) if ( outputType == OUTPUT_HTML || !outputType )
{ {
HTMLDocFileOutput *hdout = new HTMLDocFileOutput(); HTMLDocFileOutput *hdout = new HTMLDocFileOutput();
@ -767,7 +767,7 @@ void DumpAllClasses( int typeFlag, int outputType, const char *filename )
hdout->Write(defaultname, classlist, typeFlag); hdout->Write(defaultname, classlist, typeFlag);
delete hdout; delete hdout;
} }
if ( outputType == OUTPUT_CMD || !outputType ) if ( outputType == OUTPUT_CMD || !outputType )
{ {
ToolDocFileOutput *dout = new ToolDocFileOutput(); ToolDocFileOutput *dout = new ToolDocFileOutput();
@ -778,111 +778,111 @@ void DumpAllClasses( int typeFlag, int outputType, const char *filename )
delete dout; delete dout;
} }
/* /*
int i, j, num, smallest; int i, j, num, smallest;
ClassDef *c; ClassDef *c;
FILE * class_file; FILE * class_file;
str class_filename; str class_filename;
str class_title; str class_title;
str classes[ MAX_CLASSES ]; str classes[ MAX_CLASSES ];
#if defined( GAME_DLL ) #if defined( GAME_DLL )
class_filename = "g_allclasses.html"; class_filename = "g_allclasses.html";
class_title = "Game Module"; class_title = "Game Module";
#elif defined( CGAME_DLL ) #elif defined( CGAME_DLL )
class_filename = "cg_allclasses.html"; class_filename = "cg_allclasses.html";
class_title = "Client Game Module"; class_title = "Client Game Module";
#else #else
class_filename = "cl_allclasses.html"; class_filename = "cl_allclasses.html";
class_title = "Client Module"; class_title = "Client Module";
#endif #endif
class_file = fopen( class_filename.c_str(), "w" ); class_file = fopen( class_filename.c_str(), "w" );
if ( class_file == NULL ) if ( class_file == NULL )
return; return;
// construct the HTML header for the document // construct the HTML header for the document
CLASS_Print( class_file, "<HTML>\n"); CLASS_Print( class_file, "<HTML>\n");
CLASS_Print( class_file, "<HEAD>\n"); CLASS_Print( class_file, "<HEAD>\n");
CLASS_Print( class_file, "<Title>%s Classes</Title>\n", class_title.c_str() ); CLASS_Print( class_file, "<Title>%s Classes</Title>\n", class_title.c_str() );
CLASS_Print( class_file, "</HEAD>\n"); CLASS_Print( class_file, "</HEAD>\n");
CLASS_Print( class_file, "<BODY>\n"); CLASS_Print( class_file, "<BODY>\n");
CLASS_Print( class_file, "<H1>\n"); CLASS_Print( class_file, "<H1>\n");
CLASS_Print( class_file, "<center>%s Classes</center>\n", class_title.c_str() ); CLASS_Print( class_file, "<center>%s Classes</center>\n", class_title.c_str() );
CLASS_Print( class_file, "</H1>\n"); CLASS_Print( class_file, "</H1>\n");
#if defined( GAME_DLL ) #if defined( GAME_DLL )
// //
// print out some commonly used classnames // print out some commonly used classnames
// //
CLASS_Print( class_file, "<h2>" ); CLASS_Print( class_file, "<h2>" );
CLASS_Print( class_file, "<a href=\"#Actor\">Actor</a>, " ); CLASS_Print( class_file, "<a href=\"#Actor\">Actor</a>, " );
CLASS_Print( class_file, "<a href=\"#Animate\">Animate</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=\"#Entity\">Entity</a>, " );
CLASS_Print( class_file, "<a href=\"#ScriptSlave\">ScriptSlave</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=\"#ScriptThread\">ScriptThread</a>, " );
CLASS_Print( class_file, "<a href=\"#Sentient\">Sentient</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=\"#Trigger\">Trigger</a>, " );
CLASS_Print( class_file, "<a href=\"#World\">World</a>" ); CLASS_Print( class_file, "<a href=\"#World\">World</a>" );
CLASS_Print( class_file, "</h2>" ); CLASS_Print( class_file, "</h2>" );
#endif #endif
dump_numclasses = 0; dump_numclasses = 0;
dump_numevents = 0; dump_numevents = 0;
// get all the classes // get all the classes
num = 0; num = 0;
for( c = classlist->next; c != classlist; c = c->next ) for( c = classlist->next; c != classlist; c = c->next )
{ {
if ( num < MAX_CLASSES ) if ( num < MAX_CLASSES )
{ {
classes[ num++ ] = c->classname; classes[ num++ ] = c->classname;
} }
} }
// go through and process each class from smallest to greatest // go through and process each class from smallest to greatest
for( i = 0; i < num; i++ ) for( i = 0; i < num; i++ )
{ {
smallest = -1; smallest = -1;
for( j = 0; j < num; j++ ) for( j = 0; j < num; j++ )
{ {
if ( classes[ j ].length() > 1 ) if ( classes[ j ].length() > 1 )
{ {
if ( smallest >= 0 ) if ( smallest >= 0 )
{ {
if ( classes[ j ].icmp( classes[ smallest ] ) < 0 ) if ( classes[ j ].icmp( classes[ smallest ] ) < 0 )
{ {
smallest = j; smallest = j;
} }
} }
else else
{ {
smallest = j; smallest = j;
} }
} }
} }
DumpClass( class_file, classes[ smallest ], typeFlag ); DumpClass( class_file, classes[ smallest ], typeFlag );
// delete the name from the list // delete the name from the list
classes[ smallest ] = ""; classes[ smallest ] = "";
} }
if ( class_file != NULL ) if ( class_file != NULL )
{ {
CLASS_Print( class_file, "<H2>\n"); 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, "%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, "</H2>\n");
CLASS_Print( class_file, "</BODY>\n"); CLASS_Print( class_file, "</BODY>\n");
CLASS_Print( class_file, "</HTML>\n"); CLASS_Print( class_file, "</HTML>\n");
CLASS_DPrintf( "Dumped all classes to file %s\n", class_filename.c_str() ); CLASS_DPrintf( "Dumped all classes to file %s\n", class_filename.c_str() );
fclose( class_file ); fclose( class_file );
} }
*/ */
} }
void ShutdownClasses( void ) void ShutdownClasses( void )
{ {
ClassDef *c; ClassDef* c;
for( c = classlist->next; c != classlist; c = c->next ) for( c = classlist->next; c != classlist; c = c->next )
{ {
c->Shutdown(); c->Shutdown();

View file

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