mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
indent
This commit is contained in:
parent
2763cfbd46
commit
294ca5ffd2
10 changed files with 1776 additions and 1840 deletions
|
@ -25,9 +25,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#ifndef __CLASS_H__
|
||||
#define __CLASS_H__
|
||||
|
||||
#include "q_shared.h"
|
||||
#include "container.h"
|
||||
#include "con_set.h"
|
||||
#include "container.h"
|
||||
#include "q_shared.h"
|
||||
#include "str.h"
|
||||
|
||||
#include "const_str.h"
|
||||
|
@ -35,138 +35,132 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
class Class;
|
||||
class Event;
|
||||
|
||||
#define isSubclassOf( classname )inheritsFrom( &classname::ClassInfo )
|
||||
#define isSuperclassOf( classname )isInheritedBy( &classname::ClassInfo )
|
||||
#define isSubclassOf(classname) inheritsFrom(&classname::ClassInfo)
|
||||
#define isSuperclassOf(classname) isInheritedBy(&classname::ClassInfo)
|
||||
|
||||
#ifndef NO_SCRIPTENGINE
|
||||
|
||||
#define CLASS_DECLARATION( parentclass, classname, classid ) \
|
||||
ClassDef classname::ClassInfo \
|
||||
( \
|
||||
#classname, classid, #parentclass, \
|
||||
(ResponseDef<Class> *)classname::Responses, \
|
||||
classname::_newInstance, sizeof( classname ) \
|
||||
); \
|
||||
void *classname::_newInstance( void ) \
|
||||
#define CLASS_DECLARATION(parentclass, classname, classid) \
|
||||
ClassDef classname::ClassInfo(#classname, classid, #parentclass, \
|
||||
(ResponseDef<Class>*)classname::Responses, \
|
||||
classname::_newInstance, sizeof(classname)); \
|
||||
void* classname::_newInstance(void) \
|
||||
{ \
|
||||
return new classname; \
|
||||
} \
|
||||
ClassDef *classname::classinfo( void ) const \
|
||||
ClassDef* classname::classinfo(void) const \
|
||||
{ \
|
||||
return &(classname::ClassInfo); \
|
||||
} \
|
||||
ClassDef *classname::classinfostatic( void ) \
|
||||
ClassDef* classname::classinfostatic(void) \
|
||||
{ \
|
||||
return &(classname::ClassInfo); \
|
||||
} \
|
||||
void classname::AddWaitTill( str s ) \
|
||||
void classname::AddWaitTill(str s) \
|
||||
{ \
|
||||
classname::ClassInfo.AddWaitTill( s ); \
|
||||
classname::ClassInfo.AddWaitTill(s); \
|
||||
} \
|
||||
void classname::AddWaitTill( const_str s ) \
|
||||
void classname::AddWaitTill(const_str s) \
|
||||
{ \
|
||||
classname::ClassInfo.AddWaitTill( s ); \
|
||||
classname::ClassInfo.AddWaitTill(s); \
|
||||
} \
|
||||
void classname::RemoveWaitTill( str s ) \
|
||||
void classname::RemoveWaitTill(str s) \
|
||||
{ \
|
||||
classname::ClassInfo.RemoveWaitTill( s ); \
|
||||
classname::ClassInfo.RemoveWaitTill(s); \
|
||||
} \
|
||||
void classname::RemoveWaitTill( const_str s ) \
|
||||
void classname::RemoveWaitTill(const_str s) \
|
||||
{ \
|
||||
classname::ClassInfo.RemoveWaitTill( s ); \
|
||||
classname::ClassInfo.RemoveWaitTill(s); \
|
||||
} \
|
||||
bool classname::WaitTillDefined( str s ) \
|
||||
bool classname::WaitTillDefined(str s) \
|
||||
{ \
|
||||
return classname::ClassInfo.WaitTillDefined( s ); \
|
||||
return classname::ClassInfo.WaitTillDefined(s); \
|
||||
} \
|
||||
bool classname::WaitTillDefined( const_str s ) \
|
||||
bool classname::WaitTillDefined(const_str s) \
|
||||
{ \
|
||||
return classname::ClassInfo.WaitTillDefined( s ); \
|
||||
return classname::ClassInfo.WaitTillDefined(s); \
|
||||
} \
|
||||
ResponseDef<classname> classname::Responses[] =
|
||||
|
||||
#define CLASS_PROTOTYPE( classname ) \
|
||||
public: \
|
||||
#define CLASS_PROTOTYPE(classname) \
|
||||
public: \
|
||||
static ClassDef ClassInfo; \
|
||||
static ClassDefHook _ClassInfo_; \
|
||||
static void *_newInstance( void ); \
|
||||
static ClassDef *classinfostatic(void); \
|
||||
ClassDef *classinfo(void) const override; \
|
||||
static void AddWaitTill( str s ); \
|
||||
static void AddWaitTill( const_str s ); \
|
||||
static void RemoveWaitTill( str s ); \
|
||||
static void RemoveWaitTill( const_str s ); \
|
||||
static bool WaitTillDefined( str s ); \
|
||||
static bool WaitTillDefined( const_str s ); \
|
||||
static void* _newInstance(void); \
|
||||
static ClassDef* classinfostatic(void); \
|
||||
ClassDef* classinfo(void) const override; \
|
||||
static void AddWaitTill(str s); \
|
||||
static void AddWaitTill(const_str s); \
|
||||
static void RemoveWaitTill(str s); \
|
||||
static void RemoveWaitTill(const_str s); \
|
||||
static bool WaitTillDefined(str s); \
|
||||
static bool WaitTillDefined(const_str s); \
|
||||
static ResponseDef<classname> Responses[]
|
||||
|
||||
#else
|
||||
|
||||
#define CLASS_DECLARATION( parentclass, classname, classid ) \
|
||||
ClassDef classname::ClassInfo \
|
||||
( \
|
||||
#classname, classid, #parentclass, \
|
||||
(ResponseDef<Class> *)classname::Responses, \
|
||||
classname::_newInstance, sizeof( classname ) \
|
||||
); \
|
||||
void *classname::_newInstance( void ) \
|
||||
#define CLASS_DECLARATION(parentclass, classname, classid) \
|
||||
ClassDef classname::ClassInfo(#classname, classid, #parentclass, \
|
||||
(ResponseDef<Class>*)classname::Responses, \
|
||||
classname::_newInstance, sizeof(classname)); \
|
||||
void* classname::_newInstance(void) \
|
||||
{ \
|
||||
return new classname; \
|
||||
} \
|
||||
ClassDef *classname::classinfo( void ) const \
|
||||
ClassDef* classname::classinfo(void) const \
|
||||
{ \
|
||||
return &(classname::ClassInfo); \
|
||||
} \
|
||||
ClassDef *classname::classinfostatic( void ) \
|
||||
ClassDef* classname::classinfostatic(void) \
|
||||
{ \
|
||||
return &(classname::ClassInfo); \
|
||||
} \
|
||||
ResponseDef<classname> classname::Responses[] =
|
||||
|
||||
#define CLASS_PROTOTYPE( classname ) \
|
||||
public: \
|
||||
#define CLASS_PROTOTYPE(classname) \
|
||||
public: \
|
||||
static ClassDef ClassInfo; \
|
||||
static ClassDefHook _ClassInfo_; \
|
||||
static void *_newInstance( void ); \
|
||||
static ClassDef *classinfostatic(void); \
|
||||
ClassDef *classinfo(void) const override; \
|
||||
static void* _newInstance(void); \
|
||||
static ClassDef* classinfostatic(void); \
|
||||
ClassDef* classinfo(void) const override; \
|
||||
static ResponseDef<classname> Responses[]
|
||||
|
||||
#endif
|
||||
|
||||
typedef void ( Class::*Response )( Event *ev );
|
||||
typedef void (Class::*Response)(Event* ev);
|
||||
|
||||
class EventDef;
|
||||
|
||||
template< class Type >
|
||||
template<class Type>
|
||||
struct ResponseDef
|
||||
{
|
||||
Event *event;
|
||||
void ( Type::*response )( Event *ev );
|
||||
EventDef *def;
|
||||
Event* event;
|
||||
void (Type::*response)(Event* ev);
|
||||
EventDef* def;
|
||||
};
|
||||
|
||||
class ClassDef
|
||||
{
|
||||
public:
|
||||
const char *classname;
|
||||
const char *classID;
|
||||
const char *superclass;
|
||||
void *(*newInstance)(void);
|
||||
const char* classname;
|
||||
const char* classID;
|
||||
const char* superclass;
|
||||
void* (*newInstance)(void);
|
||||
int classSize;
|
||||
ResponseDef<Class> *responses;
|
||||
ResponseDef<Class> **responseLookup;
|
||||
ClassDef *super;
|
||||
ClassDef *next;
|
||||
ClassDef *prev;
|
||||
ResponseDef<Class>* responses;
|
||||
ResponseDef<Class>** responseLookup;
|
||||
ClassDef* super;
|
||||
ClassDef* next;
|
||||
ClassDef* prev;
|
||||
|
||||
#ifndef NO_SCRIPTENGINE
|
||||
con_set<const_str, const_str> *waitTillSet;
|
||||
con_set<const_str, const_str>* waitTillSet;
|
||||
#endif
|
||||
|
||||
int numEvents;
|
||||
|
||||
static ClassDef *classlist;
|
||||
static ClassDef* classlist;
|
||||
static int numclasses;
|
||||
|
||||
static void BuildEventResponses();
|
||||
|
@ -175,68 +169,72 @@ public:
|
|||
|
||||
static int dump_numclasses;
|
||||
static int dump_numevents;
|
||||
static Container< int > sortedList;
|
||||
static Container< ClassDef * > sortedClassList;
|
||||
static Container<int> sortedList;
|
||||
static Container<ClassDef*> sortedClassList;
|
||||
|
||||
ClassDef();
|
||||
~ClassDef();
|
||||
|
||||
static int compareClasses( const void *arg1, const void *arg2 );
|
||||
static void SortClassList( Container< ClassDef * > *sortedList );
|
||||
static int compareClasses(const void* arg1, const void* arg2);
|
||||
static void SortClassList(Container<ClassDef*>* sortedList);
|
||||
|
||||
#ifndef NO_SCRIPTENGINE
|
||||
void AddWaitTill( str s );
|
||||
void AddWaitTill( const_str s );
|
||||
void RemoveWaitTill( str s );
|
||||
void RemoveWaitTill( const_str s );
|
||||
bool WaitTillDefined( str s );
|
||||
bool WaitTillDefined( const_str s );
|
||||
void AddWaitTill(str s);
|
||||
void AddWaitTill(const_str s);
|
||||
void RemoveWaitTill(str s);
|
||||
void RemoveWaitTill(const_str s);
|
||||
bool WaitTillDefined(str s);
|
||||
bool WaitTillDefined(const_str s);
|
||||
#endif
|
||||
|
||||
/* Create-a-class function */
|
||||
ClassDef( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
|
||||
void *( *newInstance )( void ), int classSize );
|
||||
void CreateInternal( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
|
||||
void *( *newInstance )( void ), int classSize );
|
||||
void CreateInternalWin( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
|
||||
void *( *newInstance )( void ), int classSize );
|
||||
ClassDef(const char* classname, const char* classID, const char* superclass,
|
||||
ResponseDef<Class>* responses, void* (*newInstance)(void),
|
||||
int classSize);
|
||||
void CreateInternal(const char* classname, const char* classID,
|
||||
const char* superclass, ResponseDef<Class>* responses,
|
||||
void* (*newInstance)(void), int classSize);
|
||||
void CreateInternalWin(const char* classname, const char* classID,
|
||||
const char* superclass,
|
||||
ResponseDef<Class>* responses,
|
||||
void* (*newInstance)(void), int classSize);
|
||||
|
||||
EventDef *GetDef( int eventnum );
|
||||
int GetFlags( Event *event );
|
||||
EventDef* GetDef(int eventnum);
|
||||
int GetFlags(Event* event);
|
||||
|
||||
void Destroy();
|
||||
};
|
||||
|
||||
ClassDef *getClassList( void );
|
||||
qboolean checkInheritance( const ClassDef *superclass, const ClassDef *subclass );
|
||||
qboolean checkInheritance( ClassDef *superclass, const char *subclass );
|
||||
qboolean checkInheritance( const char *superclass, const char *subclass );
|
||||
void CLASS_Print( FILE *class_file, const char *fmt, ... );
|
||||
void ClassEvents( const char *classname, qboolean print_to_disk );
|
||||
void DumpClass( FILE * class_file, const char * className );
|
||||
void DumpAllClasses( void );
|
||||
ClassDef* getClassList(void);
|
||||
qboolean checkInheritance(const ClassDef* superclass, const ClassDef* subclass);
|
||||
qboolean checkInheritance(ClassDef* superclass, const char* subclass);
|
||||
qboolean checkInheritance(const char* superclass, const char* subclass);
|
||||
void CLASS_Print(FILE* class_file, const char* fmt, ...);
|
||||
void ClassEvents(const char* classname, qboolean print_to_disk);
|
||||
void DumpClass(FILE* class_file, const char* className);
|
||||
void DumpAllClasses(void);
|
||||
|
||||
class ClassDefHook
|
||||
{
|
||||
private:
|
||||
ClassDef *classdef;
|
||||
ClassDef* classdef;
|
||||
|
||||
public:
|
||||
//void * operator new( size_t );
|
||||
//void operator delete( void * );
|
||||
// void * operator new( size_t );
|
||||
// void operator delete( void * );
|
||||
|
||||
ClassDefHook();
|
||||
~ClassDefHook();
|
||||
|
||||
/* Hook-a-class function */
|
||||
ClassDefHook( ClassDef * classdef, ResponseDef<Class> *responses );
|
||||
ClassDefHook(ClassDef* classdef, ResponseDef<Class>* responses);
|
||||
};
|
||||
|
||||
ClassDef *getClassForID( const char *name );
|
||||
ClassDef *getClass( const char * name );
|
||||
ClassDef *getClassList( void );
|
||||
void listAllClasses( void );
|
||||
void listInheritanceOrder( const char *classname );
|
||||
ClassDef* getClassForID(const char* name);
|
||||
ClassDef* getClass(const char* name);
|
||||
ClassDef* getClassList(void);
|
||||
void listAllClasses(void);
|
||||
void listInheritanceOrder(const char* classname);
|
||||
|
||||
class SafePtrBase;
|
||||
class Archiver;
|
||||
|
@ -244,40 +242,40 @@ class Archiver;
|
|||
class Class
|
||||
{
|
||||
public:
|
||||
SafePtrBase *SafePtrList;
|
||||
SafePtrBase* SafePtrList;
|
||||
|
||||
private:
|
||||
void ClearSafePointers();
|
||||
|
||||
public:
|
||||
#ifndef _DEBUG_MEM
|
||||
void * operator new( size_t );
|
||||
void operator delete( void * );
|
||||
void* operator new(size_t);
|
||||
void operator delete(void*);
|
||||
#endif
|
||||
|
||||
Class();
|
||||
virtual ~Class();
|
||||
|
||||
virtual void Archive( Archiver& arc );
|
||||
virtual void Archive(Archiver& arc);
|
||||
|
||||
static ClassDef ClassInfo;
|
||||
static ClassDefHook _ClassInfo_;
|
||||
static void *_newInstance( void );
|
||||
static ClassDef *classinfostatic(void);
|
||||
virtual ClassDef *classinfo(void) const;
|
||||
static void* _newInstance(void);
|
||||
static ClassDef* classinfostatic(void);
|
||||
virtual ClassDef* classinfo(void) const;
|
||||
static ResponseDef<Class> Responses[];
|
||||
|
||||
const char *getClassID( void ) const;
|
||||
const char *getClassname( void ) const;
|
||||
const char *getSuperclass( void ) const;
|
||||
const char* getClassID(void) const;
|
||||
const char* getClassname(void) const;
|
||||
const char* getSuperclass(void) const;
|
||||
|
||||
qboolean inheritsFrom( ClassDef *c ) const;
|
||||
qboolean inheritsFrom( const char * name ) const;
|
||||
qboolean isInheritedBy( const char * name ) const;
|
||||
qboolean isInheritedBy( ClassDef *c ) const;
|
||||
qboolean inheritsFrom(ClassDef* c) const;
|
||||
qboolean inheritsFrom(const char* name) const;
|
||||
qboolean isInheritedBy(const char* name) const;
|
||||
qboolean isInheritedBy(ClassDef* c) const;
|
||||
|
||||
void warning( const char *function, const char *format, ... );
|
||||
void error( const char *function, const char *format, ... );
|
||||
void warning(const char* function, const char* format, ...);
|
||||
void error(const char* function, const char* format, ...);
|
||||
};
|
||||
|
||||
#include "safeptr.h"
|
||||
|
|
|
@ -37,74 +37,78 @@ typedef struct configValue_s {
|
|||
typedef struct configKey_s {
|
||||
bool m_bNeedWrite;
|
||||
str name;
|
||||
Container< configValue_t > value;
|
||||
Container<configValue_t> value;
|
||||
bool m_bArray;
|
||||
} configKey_t;
|
||||
|
||||
typedef struct configSection_s {
|
||||
bool m_bNeedWrite;
|
||||
str name;
|
||||
Container< configKey_t * > key;
|
||||
Container<configKey_t*> key;
|
||||
} configSection_t;
|
||||
|
||||
enum {
|
||||
LINE_EMPTY,
|
||||
LINE_COMMENT,
|
||||
LINE_SECTION,
|
||||
LINE_VALUE,
|
||||
LINE_ERROR
|
||||
};
|
||||
enum { LINE_EMPTY, LINE_COMMENT, LINE_SECTION, LINE_VALUE, LINE_ERROR };
|
||||
|
||||
class Configurator : public Class {
|
||||
class Configurator : public Class
|
||||
{
|
||||
private:
|
||||
str m_filename;
|
||||
bool m_bNoWrite;
|
||||
bool m_bNeedWrite;
|
||||
|
||||
con_set< str, configSection_t > m_sections;
|
||||
Container< configSection_t * > m_reverseSections;
|
||||
con_set<str, configSection_t> m_sections;
|
||||
Container<configSection_t*> m_reverseSections;
|
||||
|
||||
private:
|
||||
size_t GetLine( char *dest, const char *data, size_t size );
|
||||
str GetValue( const char *section, const char *key, str defaultValue, int index = -1 );
|
||||
configKey_t *GetKey( const char *section, const char *key, int index = -1 );
|
||||
size_t GetLine(char* dest, const char* data, size_t size);
|
||||
str GetValue(const char* section, const char* key, str defaultValue,
|
||||
int index = -1);
|
||||
configKey_t* GetKey(const char* section, const char* key, int index = -1);
|
||||
|
||||
int CutLine( char *data );
|
||||
bool SetupLine( char *line, int& lineno, size_t& len, size_t& last );
|
||||
bool FindData( int type, const char *section, const char *key, size_t *offset, const char *data, size_t size );
|
||||
void ParseData( const char *data, size_t size );
|
||||
void WriteData( char **data, size_t *size );
|
||||
void WriteData2( char **data, size_t *size );
|
||||
int ParseLine( char *line, char *section, char *key, char *value );
|
||||
int CutLine(char* data);
|
||||
bool SetupLine(char* line, int& lineno, size_t& len, size_t& last);
|
||||
bool FindData(int type, const char* section, const char* key,
|
||||
size_t* offset, const char* data, size_t size);
|
||||
void ParseData(const char* data, size_t size);
|
||||
void WriteData(char** data, size_t* size);
|
||||
void WriteData2(char** data, size_t* size);
|
||||
int ParseLine(char* line, char* section, char* key, char* value);
|
||||
|
||||
configSection_t *CreateSection( const char *section );
|
||||
configSection_t *FindSection( const char *section );
|
||||
int GetKeyArray( char *key );
|
||||
int GetKeyArray( str& key );
|
||||
configKey_t *CreateKey( configSection_t *section, const char *key, unsigned int *index );
|
||||
configKey_t *FindKey( configSection_t *section, const char *key );
|
||||
void RemoveSection( configSection_t *section );
|
||||
void RemoveKey( configSection_t *section, configKey_t *key );
|
||||
configSection_t* CreateSection(const char* section);
|
||||
configSection_t* FindSection(const char* section);
|
||||
int GetKeyArray(char* key);
|
||||
int GetKeyArray(str& key);
|
||||
configKey_t* CreateKey(configSection_t* section, const char* key,
|
||||
unsigned int* index);
|
||||
configKey_t* FindKey(configSection_t* section, const char* key);
|
||||
void RemoveSection(configSection_t* section);
|
||||
void RemoveKey(configSection_t* section, configKey_t* key);
|
||||
|
||||
public:
|
||||
CLASS_PROTOTYPE( Configurator );
|
||||
CLASS_PROTOTYPE(Configurator);
|
||||
|
||||
Configurator( const char *filename );
|
||||
Configurator(const char* filename);
|
||||
Configurator();
|
||||
~Configurator();
|
||||
|
||||
void Parse( const char *filename );
|
||||
void Parse(const char* filename);
|
||||
void Close();
|
||||
void SetWrite( bool bWrite );
|
||||
void SetWrite(bool bWrite);
|
||||
|
||||
str GetString( const char *section, const char *key, str defaultValue, int index = -1 );
|
||||
int GetInteger( const char *section, const char *key, int defaultValue, int index = -1 );
|
||||
float GetFloat( const char *section, const char *key, float defaultValue, int index = -1 );
|
||||
void SetString( const char *section, const char *key, str value, int index = -1 );
|
||||
void SetInteger( const char *section, const char *key, int value, int index = -1 );
|
||||
void SetFloat( const char *section, const char *key, float value, int index = -1 );
|
||||
str GetString(const char* section, const char* key, str defaultValue,
|
||||
int index = -1);
|
||||
int GetInteger(const char* section, const char* key, int defaultValue,
|
||||
int index = -1);
|
||||
float GetFloat(const char* section, const char* key, float defaultValue,
|
||||
int index = -1);
|
||||
void SetString(const char* section, const char* key, str value,
|
||||
int index = -1);
|
||||
void SetInteger(const char* section, const char* key, int value,
|
||||
int index = -1);
|
||||
void SetFloat(const char* section, const char* key, float value,
|
||||
int index = -1);
|
||||
};
|
||||
|
||||
void test_config( void );
|
||||
void test_config(void);
|
||||
|
||||
#endif /* __CONFIGURATOR_H__ */
|
||||
|
|
|
@ -27,70 +27,72 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#ifdef GAME_DLL
|
||||
#ifdef WIN32
|
||||
#define glbprintf( text ) gi.Printf( text )
|
||||
#define glbprintf(text) gi.Printf(text)
|
||||
#else
|
||||
#define glbprintf( text )
|
||||
#define glbprintf(text)
|
||||
#endif
|
||||
#elif defined CGAME_DLL
|
||||
#define glbprintf( text ) cgi.Printf( text )
|
||||
#define glbprintf(text) cgi.Printf(text)
|
||||
#else
|
||||
#define glbprintf( text ) printf( text )
|
||||
#define glbprintf(text) printf(text)
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define CONTAINER_Error( id, text ) glbprintf( text ); assert( 0 );
|
||||
#define CONTAINER_Error(id, text) \
|
||||
glbprintf(text); \
|
||||
assert(0);
|
||||
#else
|
||||
#define CONTAINER_Error( id, text ) throw( text ) //gi.Error
|
||||
#define CONTAINER_Error(id, text) throw(text) // gi.Error
|
||||
#endif
|
||||
#define CONTAINER_DPrintf( text ) glbprintf( text )
|
||||
#define CONTAINER_WDPrintf( text ) glbprintf( text )
|
||||
#define CONTAINER_DPrintf(text) glbprintf(text)
|
||||
#define CONTAINER_WDPrintf(text) glbprintf(text)
|
||||
|
||||
class Archiver;
|
||||
|
||||
template< class Type >
|
||||
template<class Type>
|
||||
class Container
|
||||
{
|
||||
private:
|
||||
Type *objlist;
|
||||
Type* objlist;
|
||||
int numobjects;
|
||||
int maxobjects;
|
||||
|
||||
private:
|
||||
void Copy( const Container<Type>& container );
|
||||
void Copy(const Container<Type>& container);
|
||||
|
||||
public:
|
||||
Container();
|
||||
Container( const Container<Type>& container );
|
||||
Container(const Container<Type>& container);
|
||||
~Container();
|
||||
|
||||
void Archive( Archiver& arc );
|
||||
void Archive( Archiver& arc, void( *ArchiveFunc )( Archiver &arc, Type *obj ) );
|
||||
void Archive(Archiver& arc);
|
||||
void Archive(Archiver& arc, void (*ArchiveFunc)(Archiver& arc, Type* obj));
|
||||
|
||||
int AddObject( const Type& obj );
|
||||
int AddUniqueObject( const Type& obj );
|
||||
void AddObjectAt( int index, const Type& obj );
|
||||
Type *AddressOfObjectAt( int index );
|
||||
// void Archive( Archiver &arc );
|
||||
void ClearObjectList( void );
|
||||
void Fix( void );
|
||||
void FreeObjectList( void );
|
||||
int IndexOfObject( const Type& obj );
|
||||
void InsertObjectAt( int index, const Type& obj );
|
||||
int MaxObjects( void ) const;
|
||||
int NumObjects( void ) const;
|
||||
Type& ObjectAt( const size_t index ) const;
|
||||
bool ObjectInList( const Type& obj );
|
||||
void RemoveObjectAt( int index );
|
||||
void RemoveObject( const Type& obj );
|
||||
void Reset( void );
|
||||
void Resize( int maxelements );
|
||||
void SetObjectAt( int index, const Type& obj );
|
||||
void Sort( int( *compare )( const void *elem1, const void *elem2 ) );
|
||||
Type& operator[]( const int index ) const;
|
||||
Container<Type>& operator=( const Container<Type>& container );
|
||||
int AddObject(const Type& obj);
|
||||
int AddUniqueObject(const Type& obj);
|
||||
void AddObjectAt(int index, const Type& obj);
|
||||
Type* AddressOfObjectAt(int index);
|
||||
// void Archive( Archiver &arc );
|
||||
void ClearObjectList(void);
|
||||
void Fix(void);
|
||||
void FreeObjectList(void);
|
||||
int IndexOfObject(const Type& obj);
|
||||
void InsertObjectAt(int index, const Type& obj);
|
||||
int MaxObjects(void) const;
|
||||
int NumObjects(void) const;
|
||||
Type& ObjectAt(const size_t index) const;
|
||||
bool ObjectInList(const Type& obj);
|
||||
void RemoveObjectAt(int index);
|
||||
void RemoveObject(const Type& obj);
|
||||
void Reset(void);
|
||||
void Resize(int maxelements);
|
||||
void SetObjectAt(int index, const Type& obj);
|
||||
void Sort(int (*compare)(const void* elem1, const void* elem2));
|
||||
Type& operator[](const int index) const;
|
||||
Container<Type>& operator=(const Container<Type>& container);
|
||||
};
|
||||
|
||||
template< class Type >
|
||||
template<class Type>
|
||||
Container<Type>::Container()
|
||||
{
|
||||
objlist = NULL;
|
||||
|
@ -98,28 +100,29 @@ Container<Type>::Container()
|
|||
maxobjects = 0;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
Container<Type>::Container( const Container<Type>& container )
|
||||
template<class Type>
|
||||
Container<Type>::Container(const Container<Type>& container)
|
||||
{
|
||||
objlist = NULL;
|
||||
|
||||
Copy( container );
|
||||
Copy(container);
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
template<class Type>
|
||||
Container<Type>::~Container()
|
||||
{
|
||||
FreeObjectList();
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
int Container<Type>::AddObject( const Type& obj )
|
||||
template<class Type>
|
||||
int Container<Type>::AddObject(const Type& obj)
|
||||
{
|
||||
if ( !objlist )
|
||||
Resize( 10 );
|
||||
if (!objlist) {
|
||||
Resize(10);
|
||||
}
|
||||
|
||||
if ( numobjects >= maxobjects ) {
|
||||
Resize( numobjects * 2 );
|
||||
if (numobjects >= maxobjects) {
|
||||
Resize(numobjects * 2);
|
||||
}
|
||||
|
||||
objlist[numobjects] = obj;
|
||||
|
@ -128,40 +131,44 @@ int Container<Type>::AddObject( const Type& obj )
|
|||
return numobjects;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
int Container<Type>::AddUniqueObject( const Type& obj )
|
||||
template<class Type>
|
||||
int Container<Type>::AddUniqueObject(const Type& obj)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = IndexOfObject( obj );
|
||||
index = IndexOfObject(obj);
|
||||
|
||||
if ( !index ) {
|
||||
index = AddObject( obj );
|
||||
if (!index) {
|
||||
index = AddObject(obj);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::AddObjectAt( int index, const Type& obj )
|
||||
template<class Type>
|
||||
void Container<Type>::AddObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ( index > maxobjects )
|
||||
Resize( index );
|
||||
|
||||
if ( index > numobjects )
|
||||
numobjects = index;
|
||||
|
||||
SetObjectAt( index, obj );
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
Type *Container<Type>::AddressOfObjectAt( int index )
|
||||
{
|
||||
if ( index > maxobjects ) {
|
||||
CONTAINER_Error( ERR_DROP, "Container::AddressOfObjectAt : index is greater than maxobjects" );
|
||||
if (index > maxobjects) {
|
||||
Resize(index);
|
||||
}
|
||||
|
||||
if ( index > numobjects ) {
|
||||
if (index > numobjects) {
|
||||
numobjects = index;
|
||||
}
|
||||
|
||||
SetObjectAt(index, obj);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
Type* Container<Type>::AddressOfObjectAt(int index)
|
||||
{
|
||||
if (index > maxobjects) {
|
||||
CONTAINER_Error(
|
||||
ERR_DROP,
|
||||
"Container::AddressOfObjectAt : index is greater than maxobjects");
|
||||
}
|
||||
|
||||
if (index > numobjects) {
|
||||
numobjects = index;
|
||||
}
|
||||
|
||||
|
@ -174,15 +181,13 @@ void Container<Type>::Archive( Archiver &arc )
|
|||
|
||||
}*/
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::ClearObjectList( void )
|
||||
template<class Type>
|
||||
void Container<Type>::ClearObjectList(void)
|
||||
{
|
||||
if ( objlist && numobjects )
|
||||
{
|
||||
if (objlist && numobjects) {
|
||||
delete[] objlist;
|
||||
|
||||
if ( maxobjects == 0 )
|
||||
{
|
||||
if (maxobjects == 0) {
|
||||
objlist = NULL;
|
||||
return;
|
||||
}
|
||||
|
@ -192,23 +197,22 @@ void Container<Type>::ClearObjectList( void )
|
|||
}
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::Fix( void )
|
||||
template<class Type>
|
||||
void Container<Type>::Fix(void)
|
||||
{
|
||||
if( !objlist || !numobjects ) {
|
||||
if (!objlist || !numobjects) {
|
||||
return;
|
||||
}
|
||||
|
||||
Type *newlist = new Type[ numobjects ];
|
||||
Type* newlist = new Type[numobjects];
|
||||
int j = 0;
|
||||
|
||||
for( int i = 0; i < numobjects; i++ )
|
||||
{
|
||||
if( objlist[ i ] == NULL ) {
|
||||
for (int i = 0; i < numobjects; i++) {
|
||||
if (objlist[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newlist[ j ] = objlist[ i ];
|
||||
newlist[j] = objlist[i];
|
||||
j++;
|
||||
}
|
||||
|
||||
|
@ -217,15 +221,15 @@ void Container<Type>::Fix( void )
|
|||
delete[] objlist;
|
||||
objlist = newlist;
|
||||
|
||||
if( !numobjects ) {
|
||||
if (!numobjects) {
|
||||
ClearObjectList();
|
||||
}
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::FreeObjectList( void )
|
||||
template<class Type>
|
||||
void Container<Type>::FreeObjectList(void)
|
||||
{
|
||||
if( objlist ) {
|
||||
if (objlist) {
|
||||
delete[] objlist;
|
||||
}
|
||||
|
||||
|
@ -234,19 +238,17 @@ void Container<Type>::FreeObjectList( void )
|
|||
maxobjects = 0;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
int Container<Type>::IndexOfObject( const Type& obj )
|
||||
template<class Type>
|
||||
int Container<Type>::IndexOfObject(const Type& obj)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( !objlist ) {
|
||||
if (!objlist) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for ( i = 0; i < numobjects; i++ )
|
||||
{
|
||||
if ( objlist[i] == obj )
|
||||
{
|
||||
for (i = 0; i < numobjects; i++) {
|
||||
if (objlist[i] == obj) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
@ -254,126 +256,122 @@ int Container<Type>::IndexOfObject( const Type& obj )
|
|||
return 0;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::InsertObjectAt( int index, const Type& obj )
|
||||
template<class Type>
|
||||
void Container<Type>::InsertObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ( ( index <= 0 ) || ( index > numobjects + 1 ) )
|
||||
{
|
||||
CONTAINER_Error( ERR_DROP, "Container::InsertObjectAt : index out of range" );
|
||||
if ((index <= 0) || (index > numobjects + 1)) {
|
||||
CONTAINER_Error(ERR_DROP,
|
||||
"Container::InsertObjectAt : index out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
numobjects++;
|
||||
int arrayIndex = index - 1;
|
||||
|
||||
if ( numobjects > maxobjects )
|
||||
{
|
||||
if (numobjects > maxobjects) {
|
||||
maxobjects = numobjects;
|
||||
if ( !objlist ) {
|
||||
if (!objlist) {
|
||||
objlist = new Type[maxobjects];
|
||||
objlist[arrayIndex] = obj;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Type *temp = objlist;
|
||||
if ( maxobjects < numobjects )
|
||||
{
|
||||
} else {
|
||||
Type* temp = objlist;
|
||||
if (maxobjects < numobjects) {
|
||||
maxobjects = numobjects;
|
||||
}
|
||||
|
||||
objlist = new Type[maxobjects];
|
||||
|
||||
int i;
|
||||
for ( i = arrayIndex - 1; i >= 0; i-- ) {
|
||||
for (i = arrayIndex - 1; i >= 0; i--) {
|
||||
objlist[i] = temp[i];
|
||||
}
|
||||
|
||||
objlist[arrayIndex] = obj;
|
||||
for ( i = numobjects - 1; i > arrayIndex; i-- ) {
|
||||
for (i = numobjects - 1; i > arrayIndex; i--) {
|
||||
objlist[i] = temp[i - 1];
|
||||
}
|
||||
|
||||
delete[] temp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( int i = numobjects - 1; i > arrayIndex; i-- ) {
|
||||
} else {
|
||||
for (int i = numobjects - 1; i > arrayIndex; i--) {
|
||||
objlist[i] = objlist[i - 1];
|
||||
}
|
||||
objlist[arrayIndex] = obj;
|
||||
}
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
int Container<Type>::MaxObjects( void ) const
|
||||
template<class Type>
|
||||
int Container<Type>::MaxObjects(void) const
|
||||
{
|
||||
return maxobjects;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
int Container<Type>::NumObjects( void ) const
|
||||
template<class Type>
|
||||
int Container<Type>::NumObjects(void) const
|
||||
{
|
||||
return numobjects;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
Type& Container<Type>::ObjectAt( const size_t index ) const
|
||||
template<class Type>
|
||||
Type& Container<Type>::ObjectAt(const size_t index) const
|
||||
{
|
||||
if( ( index <= 0 ) || ( index > numobjects ) ) {
|
||||
CONTAINER_Error( ERR_DROP, "Container::ObjectAt : index out of range" );
|
||||
if ((index <= 0) || (index > numobjects)) {
|
||||
CONTAINER_Error(ERR_DROP, "Container::ObjectAt : index out of range");
|
||||
}
|
||||
|
||||
return objlist[index - 1];
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
bool Container<Type>::ObjectInList( const Type& obj )
|
||||
template<class Type>
|
||||
bool Container<Type>::ObjectInList(const Type& obj)
|
||||
{
|
||||
if ( !IndexOfObject( obj ) ) {
|
||||
if (!IndexOfObject(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::RemoveObjectAt( int index )
|
||||
template<class Type>
|
||||
void Container<Type>::RemoveObjectAt(int index)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( !objlist )
|
||||
if (!objlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( index <= 0 ) || ( index > numobjects ) )
|
||||
if ((index <= 0) || (index > numobjects)) {
|
||||
return;
|
||||
}
|
||||
|
||||
i = index - 1;
|
||||
numobjects--;
|
||||
|
||||
for ( i = index - 1; i < numobjects; i++ )
|
||||
for (i = index - 1; i < numobjects; i++) {
|
||||
objlist[i] = objlist[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::RemoveObject( const Type& obj )
|
||||
template<class Type>
|
||||
void Container<Type>::RemoveObject(const Type& obj)
|
||||
{
|
||||
int index;
|
||||
|
||||
index = IndexOfObject( obj );
|
||||
index = IndexOfObject(obj);
|
||||
|
||||
assert( index );
|
||||
if ( !index )
|
||||
{
|
||||
CONTAINER_WDPrintf( "Container::RemoveObject : Object not in list\n" );
|
||||
assert(index);
|
||||
if (!index) {
|
||||
CONTAINER_WDPrintf("Container::RemoveObject : Object not in list\n");
|
||||
return;
|
||||
}
|
||||
|
||||
RemoveObjectAt( index );
|
||||
RemoveObjectAt(index);
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
template<class Type>
|
||||
void Container<Type>::Reset()
|
||||
{
|
||||
objlist = NULL;
|
||||
|
@ -381,36 +379,32 @@ void Container<Type>::Reset()
|
|||
maxobjects = 0;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::Resize( int maxelements )
|
||||
template<class Type>
|
||||
void Container<Type>::Resize(int maxelements)
|
||||
{
|
||||
Type* temp;
|
||||
int i;
|
||||
|
||||
if ( maxelements <= 0 )
|
||||
{
|
||||
if (maxelements <= 0) {
|
||||
FreeObjectList();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !objlist )
|
||||
{
|
||||
if (!objlist) {
|
||||
maxobjects = maxelements;
|
||||
objlist = new Type[maxobjects];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
temp = objlist;
|
||||
|
||||
maxobjects = maxelements;
|
||||
|
||||
if ( maxobjects < numobjects ) {
|
||||
if (maxobjects < numobjects) {
|
||||
maxobjects = numobjects;
|
||||
}
|
||||
|
||||
objlist = new Type[maxobjects];
|
||||
|
||||
for ( i = 0; i < numobjects; i++ ) {
|
||||
for (i = 0; i < numobjects; i++) {
|
||||
objlist[i] = temp[i];
|
||||
}
|
||||
|
||||
|
@ -418,42 +412,44 @@ void Container<Type>::Resize( int maxelements )
|
|||
}
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::SetObjectAt( int index, const Type& obj )
|
||||
template<class Type>
|
||||
void Container<Type>::SetObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ( !objlist )
|
||||
if (!objlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( ( index <= 0 ) || ( index > numobjects ) ) {
|
||||
CONTAINER_Error( ERR_DROP, "Container::SetObjectAt : index out of range" );
|
||||
if ((index <= 0) || (index > numobjects)) {
|
||||
CONTAINER_Error(ERR_DROP,
|
||||
"Container::SetObjectAt : index out of range");
|
||||
}
|
||||
|
||||
objlist[index - 1] = obj;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::Sort( int( *compare )( const void *elem1, const void *elem2 ) )
|
||||
template<class Type>
|
||||
void Container<Type>::Sort(int (*compare)(const void* elem1, const void* elem2))
|
||||
|
||||
{
|
||||
if ( !objlist ) {
|
||||
if (!objlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
qsort( ( void * )objlist, ( size_t )numobjects, sizeof( Type ), compare );
|
||||
qsort((void*)objlist, (size_t)numobjects, sizeof(Type), compare);
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
Type& Container<Type>::operator[]( const int index ) const
|
||||
template<class Type>
|
||||
Type& Container<Type>::operator[](const int index) const
|
||||
{
|
||||
return ObjectAt( index + 1 );
|
||||
return ObjectAt(index + 1);
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
void Container<Type>::Copy( const Container<Type>& container )
|
||||
template<class Type>
|
||||
void Container<Type>::Copy(const Container<Type>& container)
|
||||
{
|
||||
int i;
|
||||
|
||||
if( &container == this ) {
|
||||
if (&container == this) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -463,27 +459,27 @@ void Container<Type>::Copy( const Container<Type>& container )
|
|||
maxobjects = container.maxobjects;
|
||||
objlist = NULL;
|
||||
|
||||
if( container.objlist == NULL || !container.maxobjects ) {
|
||||
if (container.objlist == NULL || !container.maxobjects) {
|
||||
return;
|
||||
}
|
||||
|
||||
Resize( maxobjects );
|
||||
Resize(maxobjects);
|
||||
|
||||
if( !container.numobjects ) {
|
||||
if (!container.numobjects) {
|
||||
return;
|
||||
}
|
||||
|
||||
for( i = 0; i < container.numobjects; i++ ) {
|
||||
objlist[ i ] = container.objlist[ i ];
|
||||
for (i = 0; i < container.numobjects; i++) {
|
||||
objlist[i] = container.objlist[i];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
template< class Type >
|
||||
Container<Type>& Container<Type>::operator=( const Container<Type>& container )
|
||||
template<class Type>
|
||||
Container<Type>& Container<Type>::operator=(const Container<Type>& container)
|
||||
{
|
||||
Copy( container );
|
||||
Copy(container);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -26,34 +26,53 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "container.h"
|
||||
|
||||
template< class Type >
|
||||
class ContainerClass : public Class {
|
||||
Container< Type > value;
|
||||
template<class Type>
|
||||
class ContainerClass : public Class
|
||||
{
|
||||
Container<Type> value;
|
||||
|
||||
public:
|
||||
virtual ~ContainerClass() { value.FreeObjectList(); }
|
||||
|
||||
virtual void Archive( Archiver& arc );
|
||||
virtual void Archive(Archiver& arc);
|
||||
|
||||
int AddObject( const Type& obj ) { return value.AddObject( obj ); }
|
||||
int AddUniqueObject( const Type& obj ) { return value.AddUniqueObject( obj ); }
|
||||
void AddObjectAt( int index, const Type& obj ) { return value.AddObjectAt( index, obj ); }
|
||||
Type *AddressOfObjectAt( int index ) { return value.AddressOfObjectAt( index ); }
|
||||
int AddObject(const Type& obj) { return value.AddObject(obj); }
|
||||
int AddUniqueObject(const Type& obj) { return value.AddUniqueObject(obj); }
|
||||
void AddObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.AddObjectAt(index, obj);
|
||||
}
|
||||
Type* AddressOfObjectAt(int index)
|
||||
{
|
||||
return value.AddressOfObjectAt(index);
|
||||
}
|
||||
|
||||
void ClearObjectList( void ) { return value.ClearObjectList(); }
|
||||
void Fix( void ) { return value.Fix(); }
|
||||
void FreeObjectList( void ) { return value.FreeObjectList(); }
|
||||
int IndexOfObject( const Type& obj ) { return value.IndexOfObject( obj ); }
|
||||
void InsertObjectAt( int index, const Type& obj ) { return value.InsertObjectAt( index, obj ); }
|
||||
int NumObjects( void ) const { return value.NumObjects(); }
|
||||
Type& ObjectAt( const size_t index ) const { return value.ObjectAt( index ); }
|
||||
bool ObjectInList( const Type& obj ) { return value.ObjectInList( obj ); }
|
||||
void RemoveObjectAt( int index ) { return value.RemoveObjectAt( index ); }
|
||||
void RemoveObject( const Type& obj ) { return value.RemoveObject( obj ); }
|
||||
void Reset( void ) { return value.Reset(); }
|
||||
void Resize( int maxelements ) { return value.Resize( maxelements ); }
|
||||
void SetObjectAt( int index, const Type& obj ) { return value.SetObjectAt( index, obj ); }
|
||||
void Sort( int( *compare )( const void *elem1, const void *elem2 ) ) { return value.Sort( compare ); }
|
||||
Type& operator[]( const int index ) const { return value[ index ]; }
|
||||
Container<Type>& operator=( const Container<Type>& container ) { return value = container; }
|
||||
void ClearObjectList(void) { return value.ClearObjectList(); }
|
||||
void Fix(void) { return value.Fix(); }
|
||||
void FreeObjectList(void) { return value.FreeObjectList(); }
|
||||
int IndexOfObject(const Type& obj) { return value.IndexOfObject(obj); }
|
||||
void InsertObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.InsertObjectAt(index, obj);
|
||||
}
|
||||
int NumObjects(void) const { return value.NumObjects(); }
|
||||
Type& ObjectAt(const size_t index) const { return value.ObjectAt(index); }
|
||||
bool ObjectInList(const Type& obj) { return value.ObjectInList(obj); }
|
||||
void RemoveObjectAt(int index) { return value.RemoveObjectAt(index); }
|
||||
void RemoveObject(const Type& obj) { return value.RemoveObject(obj); }
|
||||
void Reset(void) { return value.Reset(); }
|
||||
void Resize(int maxelements) { return value.Resize(maxelements); }
|
||||
void SetObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.SetObjectAt(index, obj);
|
||||
}
|
||||
void Sort(int (*compare)(const void* elem1, const void* elem2))
|
||||
{
|
||||
return value.Sort(compare);
|
||||
}
|
||||
Type& operator[](const int index) const { return value[index]; }
|
||||
Container<Type>& operator=(const Container<Type>& container)
|
||||
{
|
||||
return value = container;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,28 +26,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "g_local.h"
|
||||
|
||||
void *MEM_Alloc( int size )
|
||||
{
|
||||
return gi.Malloc( size );
|
||||
}
|
||||
void* MEM_Alloc(int size) { return gi.Malloc(size); }
|
||||
|
||||
void MEM_Free( void *ptr )
|
||||
{
|
||||
return gi.Free( ptr );
|
||||
}
|
||||
void MEM_Free(void* ptr) { return gi.Free(ptr); }
|
||||
|
||||
#else
|
||||
|
||||
#include "qcommon.h"
|
||||
|
||||
void* MEM_Alloc(int size)
|
||||
{
|
||||
return Z_Malloc(size);
|
||||
}
|
||||
void* MEM_Alloc(int size) { return Z_Malloc(size); }
|
||||
|
||||
void MEM_Free(void* ptr)
|
||||
{
|
||||
return Z_Free(ptr);
|
||||
}
|
||||
void MEM_Free(void* ptr) { return Z_Free(ptr); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -31,28 +31,24 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include <type_traits>
|
||||
#include <new>
|
||||
|
||||
void *MEM_Alloc( int size );
|
||||
void MEM_Free( void *ptr );
|
||||
void* MEM_Alloc(int size);
|
||||
void MEM_Free(void* ptr);
|
||||
|
||||
static constexpr size_t DefaultBlock = 256;
|
||||
|
||||
enum class alloc_source_e
|
||||
{
|
||||
SourceBlock = 174,
|
||||
SourceMalloc
|
||||
};
|
||||
enum class alloc_source_e { SourceBlock = 174, SourceMalloc };
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
class MEM_BlockAlloc_enum;
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
class block_s {
|
||||
class block_s
|
||||
{
|
||||
private:
|
||||
static constexpr size_t bitsNeeded =
|
||||
blocksize <= 0x80 ? 8 :
|
||||
blocksize <= 0x8000 ? 16 :
|
||||
blocksize <= 0x80000000 ? 32 :
|
||||
64;
|
||||
static constexpr size_t bitsNeeded = blocksize <= 0x80 ? 8
|
||||
: blocksize <= 0x8000 ? 16
|
||||
: blocksize <= 0x80000000 ? 32
|
||||
: 64;
|
||||
|
||||
public:
|
||||
block_s();
|
||||
|
@ -66,10 +62,22 @@ public:
|
|||
template<size_t bits>
|
||||
struct selectType_t;
|
||||
|
||||
template<> struct selectType_t<8> { using type = uint8_t; };
|
||||
template<> struct selectType_t<16> { using type = uint16_t; };
|
||||
template<> struct selectType_t<32> { using type = uint32_t; };
|
||||
template<> struct selectType_t<64> { using type = uint64_t; };
|
||||
template<>
|
||||
struct selectType_t<8> {
|
||||
using type = uint8_t;
|
||||
};
|
||||
template<>
|
||||
struct selectType_t<16> {
|
||||
using type = uint16_t;
|
||||
};
|
||||
template<>
|
||||
struct selectType_t<32> {
|
||||
using type = uint32_t;
|
||||
};
|
||||
template<>
|
||||
struct selectType_t<64> {
|
||||
using type = uint64_t;
|
||||
};
|
||||
|
||||
using offset_t = typename selectType_t<bitsNeeded>::type;
|
||||
|
||||
|
@ -109,8 +117,7 @@ block_s<aclass, blocksize>::block_s()
|
|||
{
|
||||
info_t* header;
|
||||
offset_t curr;
|
||||
for (curr = 0; curr < blocksize - 1; ++curr)
|
||||
{
|
||||
for (curr = 0; curr < blocksize - 1; ++curr) {
|
||||
offset_t next = curr + 1;
|
||||
header = &data[curr];
|
||||
header->source = alloc_source_e::SourceBlock;
|
||||
|
@ -131,21 +138,20 @@ block_s<aclass, blocksize>::block_s()
|
|||
has_used_data = false;
|
||||
}
|
||||
#else
|
||||
: prev_block(nullptr)
|
||||
, next_block(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
: prev_block(nullptr), next_block(nullptr)
|
||||
{}
|
||||
#endif
|
||||
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
template<typename aclass, size_t blocksize>
|
||||
bool block_s<aclass, blocksize>::usedDataAvailable() const {
|
||||
bool block_s<aclass, blocksize>::usedDataAvailable() const
|
||||
{
|
||||
return has_used_data;
|
||||
}
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
bool block_s<aclass, blocksize>::freeDataAvailable() const {
|
||||
bool block_s<aclass, blocksize>::freeDataAvailable() const
|
||||
{
|
||||
return has_free_data;
|
||||
}
|
||||
#endif
|
||||
|
@ -154,6 +160,7 @@ template<typename aclass, size_t blocksize = DefaultBlock>
|
|||
class MEM_BlockAlloc
|
||||
{
|
||||
static_assert(blocksize >= 2, "Minimum 2x class preallocation required!!");
|
||||
|
||||
public:
|
||||
MEM_BlockAlloc();
|
||||
~MEM_BlockAlloc();
|
||||
|
@ -193,10 +200,7 @@ public:
|
|||
aclass* NextElement();
|
||||
aclass* CurrentElement();
|
||||
|
||||
enum blockType_e {
|
||||
used,
|
||||
full
|
||||
};
|
||||
enum blockType_e { used, full };
|
||||
|
||||
private:
|
||||
using block_t = block_s<aclass, blocksize>;
|
||||
|
@ -214,8 +218,7 @@ private:
|
|||
template<typename a, size_t b>
|
||||
MEM_BlockAlloc<a, b>::MEM_BlockAlloc()
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
: m_StartUsedBlock()
|
||||
, m_StartFullBlock()
|
||||
: m_StartUsedBlock(), m_StartFullBlock()
|
||||
{
|
||||
m_FreeBlock = nullptr;
|
||||
m_BlockCount = 0;
|
||||
|
@ -237,7 +240,7 @@ template<typename a, size_t b>
|
|||
void* MEM_BlockAlloc<a, b>::Alloc()
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_t* block = new(MEM_Alloc(sizeof(block_t))) block_t();
|
||||
block_t* block = new (MEM_Alloc(sizeof(block_t))) block_t();
|
||||
|
||||
m_Block.AddFirst(block);
|
||||
|
||||
|
@ -248,40 +251,36 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
block_offset_t free_data;
|
||||
block_offset_t next_data;
|
||||
|
||||
if (m_StartUsedBlock)
|
||||
{
|
||||
if (m_StartUsedBlock) {
|
||||
used_block = m_StartUsedBlock;
|
||||
|
||||
free_data = used_block->free_data;
|
||||
next_data = used_block->next_data[free_data];
|
||||
|
||||
if (next_data == free_data)
|
||||
{
|
||||
// Move the block to the next block list as there is no space available
|
||||
if (next_data == free_data) {
|
||||
// Move the block to the next block list as there is no space
|
||||
// available
|
||||
m_StartUsedBlock = used_block->next_block;
|
||||
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, used_block, next_block, prev_block);
|
||||
LL_SafeAddFirst(m_StartFullBlock, used_block, next_block, prev_block);
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, used_block, next_block,
|
||||
prev_block);
|
||||
LL_SafeAddFirst(m_StartFullBlock, used_block, next_block,
|
||||
prev_block);
|
||||
|
||||
used_block->has_free_data = false;
|
||||
return TakeFree(used_block, free_data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_FreeBlock)
|
||||
{
|
||||
} else {
|
||||
if (m_FreeBlock) {
|
||||
// start from the free block
|
||||
used_block = m_FreeBlock;
|
||||
m_FreeBlock = nullptr;
|
||||
free_data = used_block->free_data;
|
||||
next_data = used_block->next_data[free_data];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_BlockCount++;
|
||||
// allocate and construct a new block
|
||||
used_block = new(MEM_Alloc(sizeof(block_t))) block_t();
|
||||
used_block = new (MEM_Alloc(sizeof(block_t))) block_t();
|
||||
|
||||
free_data = 0;
|
||||
next_data = 1;
|
||||
|
@ -297,8 +296,7 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
used_block->free_data = next_data;
|
||||
used_block->has_free_data = true;
|
||||
|
||||
if (!used_block->usedDataAvailable())
|
||||
{
|
||||
if (!used_block->usedDataAvailable()) {
|
||||
used_block->used_data = free_data;
|
||||
used_block->has_used_data = true;
|
||||
used_block->next_data[free_data] = free_data;
|
||||
|
@ -310,8 +308,9 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
#endif
|
||||
}
|
||||
|
||||
template< typename aclass, size_t blocksize>
|
||||
void* MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t* block, uintptr_t free_data)
|
||||
template<typename aclass, size_t blocksize>
|
||||
void* MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t* block,
|
||||
uintptr_t free_data)
|
||||
{
|
||||
const block_offset_t used_data = block->used_data;
|
||||
const block_offset_t prev_data = block->prev_data[used_data];
|
||||
|
@ -327,7 +326,7 @@ template<typename a, size_t b>
|
|||
void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_s<a, b>* block = (block_s<a, b> *)ptr;
|
||||
block_s<a, b>* block = (block_s<a, b>*)ptr;
|
||||
|
||||
m_Block.Remove(block);
|
||||
|
||||
|
@ -335,17 +334,19 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
MEM::Free(block);
|
||||
#else
|
||||
// get the header of the pointer
|
||||
typename block_t::info_t* header = reinterpret_cast<typename block_t::info_t*>(static_cast<unsigned char*>(ptr) - block_t::headersize);
|
||||
typename block_t::info_t* header =
|
||||
reinterpret_cast<typename block_t::info_t*>(
|
||||
static_cast<unsigned char*>(ptr) - block_t::headersize);
|
||||
const block_offset_t used_data = header->index;
|
||||
// get the block from the header
|
||||
block_t* const block = (block_t*)((uint8_t*)header - used_data * block_t::datasize - block_t::dataoffset);
|
||||
block_t* const block =
|
||||
(block_t*)((uint8_t*)header - used_data * block_t::datasize -
|
||||
block_t::dataoffset);
|
||||
const block_offset_t next_data = block->next_data[used_data];
|
||||
if (next_data == used_data)
|
||||
{
|
||||
if (next_data == used_data) {
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, block, next_block, prev_block);
|
||||
|
||||
if (m_FreeBlock)
|
||||
{
|
||||
if (m_FreeBlock) {
|
||||
// deallocate the free block because of another deallocation
|
||||
--m_BlockCount;
|
||||
MEM_Free(m_FreeBlock);
|
||||
|
@ -362,9 +363,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
block->prev_data[free_data] = used_data;
|
||||
block->next_data[used_data] = free_data;
|
||||
block->prev_data[used_data] = prev_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
const block_offset_t prev_data = block->prev_data[used_data];
|
||||
|
||||
block->next_data[prev_data] = next_data;
|
||||
|
@ -372,8 +371,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
block->used_data = next_data;
|
||||
block->has_used_data = true;
|
||||
|
||||
if (block->freeDataAvailable())
|
||||
{
|
||||
if (block->freeDataAvailable()) {
|
||||
const block_offset_t free_data = block->free_data;
|
||||
const block_offset_t prev_data = block->prev_data[free_data];
|
||||
|
||||
|
@ -384,8 +382,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_StartFullBlock == block)
|
||||
{
|
||||
if (m_StartFullBlock == block) {
|
||||
m_StartFullBlock = block->next_block;
|
||||
}
|
||||
|
||||
|
@ -406,8 +403,7 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
block_t* block;
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_t* next = m_Block.Root();
|
||||
for (block = next; block; block = next)
|
||||
{
|
||||
for (block = next; block; block = next) {
|
||||
next = block->next_block;
|
||||
m_BlockCount--;
|
||||
a* ptr = (a*)block->data;
|
||||
|
@ -416,10 +412,8 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
}
|
||||
m_Block.Reset();
|
||||
#else
|
||||
while((block = m_StartFullBlock) != nullptr)
|
||||
{
|
||||
if (block->usedDataAvailable())
|
||||
{
|
||||
while ((block = m_StartFullBlock) != nullptr) {
|
||||
if (block->usedDataAvailable()) {
|
||||
a* ptr = (a*)block->data[block->used_data].data;
|
||||
ptr->~a();
|
||||
Free(ptr);
|
||||
|
@ -427,18 +421,15 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
}
|
||||
}
|
||||
|
||||
while ((block = m_StartUsedBlock) != nullptr)
|
||||
{
|
||||
if (block->usedDataAvailable())
|
||||
{
|
||||
while ((block = m_StartUsedBlock) != nullptr) {
|
||||
if (block->usedDataAvailable()) {
|
||||
a* ptr = (a*)block->data[block->used_data].data;
|
||||
ptr->~a();
|
||||
Free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_FreeBlock)
|
||||
{
|
||||
if (m_FreeBlock) {
|
||||
m_BlockCount--;
|
||||
MEM_Free(m_FreeBlock);
|
||||
m_FreeBlock = nullptr;
|
||||
|
@ -451,25 +442,21 @@ size_t MEM_BlockAlloc<a, b>::Count(const block_t* list)
|
|||
{
|
||||
int count = 0;
|
||||
#if _DEBUG_MEMBLOCK
|
||||
for (const block_t* block = list; block; block = block->next_block)
|
||||
{
|
||||
for (const block_t* block = list; block; block = block->next_block) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
|
||||
for (const block_t* block = list; block; block = block->next_block)
|
||||
{
|
||||
if (!block->usedDataAvailable())
|
||||
{
|
||||
for (const block_t* block = list; block; block = block->next_block) {
|
||||
if (!block->usedDataAvailable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const block_offset_t used_data = block->used_data;
|
||||
block_offset_t current_used_data = used_data;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
count++;
|
||||
current_used_data = block->next_data[current_used_data];
|
||||
} while (current_used_data != used_data);
|
||||
|
@ -501,9 +488,8 @@ size_t MEM_BlockAlloc<a, b>::BlockMemory()
|
|||
return sizeof(block_s<a, b>);
|
||||
}
|
||||
|
||||
|
||||
template<typename a, size_t b>
|
||||
MEM_BlockAlloc_enum<a, b >::MEM_BlockAlloc_enum(MEM_BlockAlloc< a, b>& owner)
|
||||
MEM_BlockAlloc_enum<a, b>::MEM_BlockAlloc_enum(MEM_BlockAlloc<a, b>& owner)
|
||||
{
|
||||
m_Owner = &owner;
|
||||
m_CurrentBlock = nullptr;
|
||||
|
@ -516,21 +502,16 @@ template<typename a, size_t b>
|
|||
a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
if (!m_CurrentBlock)
|
||||
{
|
||||
if (!m_CurrentBlock) {
|
||||
m_CurrentBlock = m_Owner->m_Block.Root();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_CurrentBlock = m_CurrentBlock->next_block;
|
||||
}
|
||||
return (a*)m_CurrentBlock;
|
||||
#else
|
||||
// search for a valid block type
|
||||
while (!m_CurrentBlock)
|
||||
{
|
||||
switch (m_CurrentBlockType)
|
||||
{
|
||||
while (!m_CurrentBlock) {
|
||||
switch (m_CurrentBlockType) {
|
||||
case blockType_e::used:
|
||||
m_CurrentBlock = m_Owner->m_StartUsedBlock;
|
||||
break;
|
||||
|
@ -544,20 +525,18 @@ a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
|||
reinterpret_cast<uint8_t&>(m_CurrentBlockType)++;
|
||||
|
||||
_label:
|
||||
for (; m_CurrentBlock; m_CurrentBlock = m_CurrentBlock->next_block)
|
||||
{
|
||||
if (m_CurrentBlock->usedDataAvailable())
|
||||
{
|
||||
for (; m_CurrentBlock; m_CurrentBlock = m_CurrentBlock->next_block) {
|
||||
if (m_CurrentBlock->usedDataAvailable()) {
|
||||
m_CurrentData = m_CurrentBlock->used_data;
|
||||
return reinterpret_cast<a*>(m_CurrentBlock->data[m_CurrentData].data);
|
||||
return reinterpret_cast<a*>(
|
||||
m_CurrentBlock->data[m_CurrentData].data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_CurrentData = m_CurrentBlock->next_data[m_CurrentData];
|
||||
|
||||
if (m_CurrentData == m_CurrentBlock->used_data)
|
||||
{
|
||||
if (m_CurrentData == m_CurrentBlock->used_data) {
|
||||
// found an object
|
||||
m_CurrentBlock = m_CurrentBlock->next_block;
|
||||
goto _label;
|
||||
|
|
|
@ -56,29 +56,24 @@ MEM_TempAlloc::MEM_TempAlloc()
|
|||
|
||||
void* MEM_TempAlloc::Alloc(size_t len)
|
||||
{
|
||||
if (m_CurrentMemoryBlock && m_CurrentMemoryPos + len <= m_BlockSize)
|
||||
{
|
||||
if (m_CurrentMemoryBlock && m_CurrentMemoryPos + len <= m_BlockSize) {
|
||||
void* data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
m_CurrentMemoryPos += len;
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return CreateBlock(len);
|
||||
}
|
||||
}
|
||||
|
||||
void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
||||
{
|
||||
if (m_CurrentMemoryBlock)
|
||||
{
|
||||
if (m_CurrentMemoryBlock) {
|
||||
if (m_CurrentMemoryPos % alignment != 0) {
|
||||
m_CurrentMemoryPos += alignment - m_CurrentMemoryPos % alignment;
|
||||
}
|
||||
|
||||
if (m_CurrentMemoryPos + len <= m_BlockSize)
|
||||
{
|
||||
if (m_CurrentMemoryPos + len <= m_BlockSize) {
|
||||
void* data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
m_CurrentMemoryPos += len;
|
||||
|
@ -89,10 +84,9 @@ void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
|||
return CreateBlock(len);
|
||||
}
|
||||
|
||||
void MEM_TempAlloc::FreeAll( void )
|
||||
void MEM_TempAlloc::FreeAll(void)
|
||||
{
|
||||
while (m_CurrentMemoryBlock)
|
||||
{
|
||||
while (m_CurrentMemoryBlock) {
|
||||
tempBlock_t* prev_block = m_CurrentMemoryBlock->prev;
|
||||
MEM_TempFree(m_CurrentMemoryBlock);
|
||||
m_CurrentMemoryBlock = prev_block;
|
||||
|
@ -105,17 +99,12 @@ void* MEM_TempAlloc::CreateBlock(size_t len)
|
|||
|
||||
// allocate a new block
|
||||
tempBlock_t* prev_block = m_CurrentMemoryBlock;
|
||||
m_CurrentMemoryBlock = (tempBlock_t*)MEM_TempAllocate(sizeof(tempBlock_t) + max(m_BlockSize, len));
|
||||
m_CurrentMemoryBlock = (tempBlock_t*)MEM_TempAllocate(
|
||||
sizeof(tempBlock_t) + max(m_BlockSize, len));
|
||||
m_CurrentMemoryBlock->prev = prev_block;
|
||||
return m_CurrentMemoryBlock->GetData();
|
||||
}
|
||||
|
||||
void* tempBlock_t::GetData()
|
||||
{
|
||||
return (void*)(this + 1);
|
||||
}
|
||||
void* tempBlock_t::GetData() { return (void*)(this + 1); }
|
||||
|
||||
void* tempBlock_t::GetData(size_t pos)
|
||||
{
|
||||
return (uint8_t*)(this + 1) + pos;
|
||||
}
|
||||
void* tempBlock_t::GetData(size_t pos) { return (uint8_t*)(this + 1) + pos; }
|
||||
|
|
|
@ -28,7 +28,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
class tempBlock_t;
|
||||
|
||||
class MEM_TempAlloc {
|
||||
class MEM_TempAlloc
|
||||
{
|
||||
public:
|
||||
MEM_TempAlloc();
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -36,153 +36,145 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#define TOKENCOMMENT (';')
|
||||
#define TOKENCOMMENT2 ('#')
|
||||
#define TOKENEOL ('\n')
|
||||
//#define TOKENNULL ('\0')
|
||||
// #define TOKENNULL ('\0')
|
||||
#define TOKENSPACE (' ')
|
||||
#define TOKENSPECIAL ('$')
|
||||
|
||||
#define MAXTOKEN 512
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
qboolean tokenready;
|
||||
int offset;
|
||||
int line;
|
||||
char token[ MAXTOKEN ];
|
||||
} scriptmarker_t;
|
||||
char token[MAXTOKEN];
|
||||
} scriptmarker_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
//const char *macroName;
|
||||
//const char *macroText;
|
||||
typedef struct {
|
||||
// const char *macroName;
|
||||
// const char *macroText;
|
||||
str macroName;
|
||||
str macroText;
|
||||
} macro;
|
||||
} macro;
|
||||
|
||||
class Script : public Class
|
||||
{
|
||||
protected:
|
||||
{
|
||||
protected:
|
||||
qboolean tokenready;
|
||||
|
||||
str filename;
|
||||
const char *script_p;
|
||||
const char *end_p;
|
||||
Container<macro *> macrolist;
|
||||
const char* script_p;
|
||||
const char* end_p;
|
||||
Container<macro*> macrolist;
|
||||
|
||||
int line;
|
||||
char token[ MAXTOKEN ];
|
||||
char token[MAXTOKEN];
|
||||
|
||||
qboolean releaseBuffer;
|
||||
qboolean hasError;
|
||||
|
||||
qboolean AtComment( void );
|
||||
void CheckOverflow( void );
|
||||
qboolean AtComment(void);
|
||||
void CheckOverflow(void);
|
||||
|
||||
public:
|
||||
const char *buffer;
|
||||
public:
|
||||
const char* buffer;
|
||||
size_t length;
|
||||
|
||||
CLASS_PROTOTYPE( Script );
|
||||
CLASS_PROTOTYPE(Script);
|
||||
|
||||
#if defined(ARCHIVE_SUPPORTED)
|
||||
void Archive( Archiver &arc ) override;
|
||||
void Archive(Archiver& arc) override;
|
||||
#endif
|
||||
|
||||
~Script();
|
||||
Script( const char* filename );
|
||||
Script(const char* filename);
|
||||
Script();
|
||||
|
||||
void Close( void );
|
||||
const char *Filename( void );
|
||||
int GetLineNumber( void );
|
||||
void Reset( void );
|
||||
void MarkPosition( scriptmarker_t *mark );
|
||||
void RestorePosition( const scriptmarker_t *mark );
|
||||
qboolean SkipToEOL( void );
|
||||
void SkipWhiteSpace( qboolean crossline );
|
||||
void SkipNonToken( qboolean crossline );
|
||||
qboolean TokenAvailable( qboolean crossline );
|
||||
qboolean CommentAvailable( qboolean crossline );
|
||||
void UnGetToken( void );
|
||||
qboolean AtString( qboolean crossline );
|
||||
qboolean AtOpenParen( qboolean crossline );
|
||||
qboolean AtCloseParen( qboolean crossline );
|
||||
qboolean AtComma( qboolean crossline );
|
||||
qboolean AtDot( qboolean crossline );
|
||||
qboolean AtAssignment( qboolean crossline );
|
||||
const char *GetToken( qboolean crossline );
|
||||
const char *GetLine( qboolean crossline );
|
||||
const char *GetRaw( void );
|
||||
const char *GetString( qboolean crossline );
|
||||
qboolean GetSpecific( const char *string );
|
||||
qboolean GetBoolean( qboolean crossline );
|
||||
int GetInteger( qboolean crossline );
|
||||
double GetDouble( qboolean crossline );
|
||||
float GetFloat( qboolean crossline );
|
||||
Vector GetVector( qboolean crossline );
|
||||
int LinesInFile( void );
|
||||
void Parse( const char *data, size_t length, const char *name );
|
||||
void LoadFile( const char *name );
|
||||
void LoadFile( const char *name, int length, const char *buf );
|
||||
const char *Token( void );
|
||||
void AddMacroDefinition( qboolean crossline );
|
||||
const char *GetMacroString( const char *theMacroName );
|
||||
char *EvaluateMacroString( const char *theMacroString );
|
||||
void Close(void);
|
||||
const char* Filename(void);
|
||||
int GetLineNumber(void);
|
||||
void Reset(void);
|
||||
void MarkPosition(scriptmarker_t* mark);
|
||||
void RestorePosition(const scriptmarker_t* mark);
|
||||
qboolean SkipToEOL(void);
|
||||
void SkipWhiteSpace(qboolean crossline);
|
||||
void SkipNonToken(qboolean crossline);
|
||||
qboolean TokenAvailable(qboolean crossline);
|
||||
qboolean CommentAvailable(qboolean crossline);
|
||||
void UnGetToken(void);
|
||||
qboolean AtString(qboolean crossline);
|
||||
qboolean AtOpenParen(qboolean crossline);
|
||||
qboolean AtCloseParen(qboolean crossline);
|
||||
qboolean AtComma(qboolean crossline);
|
||||
qboolean AtDot(qboolean crossline);
|
||||
qboolean AtAssignment(qboolean crossline);
|
||||
const char* GetToken(qboolean crossline);
|
||||
const char* GetLine(qboolean crossline);
|
||||
const char* GetRaw(void);
|
||||
const char* GetString(qboolean crossline);
|
||||
qboolean GetSpecific(const char* string);
|
||||
qboolean GetBoolean(qboolean crossline);
|
||||
int GetInteger(qboolean crossline);
|
||||
double GetDouble(qboolean crossline);
|
||||
float GetFloat(qboolean crossline);
|
||||
Vector GetVector(qboolean crossline);
|
||||
int LinesInFile(void);
|
||||
void Parse(const char* data, size_t length, const char* name);
|
||||
void LoadFile(const char* name);
|
||||
void LoadFile(const char* name, int length, const char* buf);
|
||||
const char* Token(void);
|
||||
void AddMacroDefinition(qboolean crossline);
|
||||
const char* GetMacroString(const char* theMacroName);
|
||||
char* EvaluateMacroString(const char* theMacroString);
|
||||
float EvaluateMacroMath(float value, float newval, char oper);
|
||||
const char *GetExprToken(const char *ptr, char *token);
|
||||
const char *GrabNextToken( qboolean crossline );
|
||||
qboolean isMacro( void );
|
||||
const char* GetExprToken(const char* ptr, char* token);
|
||||
const char* GrabNextToken(qboolean crossline);
|
||||
qboolean isMacro(void);
|
||||
|
||||
qboolean EndOfFile();
|
||||
qboolean isValid( void );
|
||||
qboolean isValid(void);
|
||||
|
||||
Container<macro *> *GetMacroList() { return ¯olist; }
|
||||
void AddMacro(const char *name, const char *value);
|
||||
};
|
||||
Container<macro*>* GetMacroList() { return ¯olist; }
|
||||
void AddMacro(const char* name, const char* value);
|
||||
};
|
||||
|
||||
#if defined(ARCHIVE_SUPPORTED)
|
||||
|
||||
inline void Script::Archive
|
||||
(
|
||||
Archiver &arc
|
||||
)
|
||||
{
|
||||
inline void Script::Archive(Archiver& arc)
|
||||
{
|
||||
int pos;
|
||||
|
||||
arc.ArchiveBoolean( &tokenready );
|
||||
arc.ArchiveBoolean(&tokenready);
|
||||
|
||||
arc.ArchiveString( &filename );
|
||||
if ( arc.Loading() )
|
||||
{
|
||||
arc.ArchiveString(&filename);
|
||||
if (arc.Loading()) {
|
||||
//
|
||||
// load the file in
|
||||
//
|
||||
LoadFile( filename.c_str() );
|
||||
LoadFile(filename.c_str());
|
||||
}
|
||||
|
||||
if ( !arc.Loading() )
|
||||
{
|
||||
if (!arc.Loading()) {
|
||||
//
|
||||
// save out current pointer as an offset
|
||||
//
|
||||
pos = script_p - buffer;
|
||||
}
|
||||
arc.ArchiveInteger( &pos );
|
||||
if ( arc.Loading() )
|
||||
{
|
||||
arc.ArchiveInteger(&pos);
|
||||
if (arc.Loading()) {
|
||||
//
|
||||
// restore the script pointer
|
||||
//
|
||||
script_p = buffer + pos;
|
||||
}
|
||||
|
||||
//const char *end_p;
|
||||
//Container<macro *> macrolist;
|
||||
// const char *end_p;
|
||||
// Container<macro *> macrolist;
|
||||
|
||||
arc.ArchiveInteger( &line );
|
||||
arc.ArchiveRaw( &token, sizeof( token ) );
|
||||
arc.ArchiveInteger(&line);
|
||||
arc.ArchiveRaw(&token, sizeof(token));
|
||||
|
||||
//qboolean releaseBuffer;
|
||||
}
|
||||
// qboolean releaseBuffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue