59static const int DEFINTION_LIST_GROW_SIZE = 1000;
60static const uint32 IDRANGE_PER_CLASS = 10000;
78int DefinitionMgrClass::_DefinitionCount = 0;
79int DefinitionMgrClass::_MaxDefinitionCount = 0;
115 int upper_index = _DefinitionCount - 1;
116 int index = upper_index / 2;
117 bool keep_going = (_DefinitionCount > 0);
130 if (curr_def->
Get_ID () ==
id) {
131 definition = _SortedDefinitionArray[index];
133 }
else if (upper_index <= lower_index + 1) {
140 if (_SortedDefinitionArray[lower_index]->Get_ID () ==
id) {
141 definition = _SortedDefinitionArray[lower_index];
142 }
else if (_SortedDefinitionArray[upper_index]->Get_ID () ==
id) {
143 definition = _SortedDefinitionArray[upper_index];
151 if (
id > curr_def->
Get_ID ()) {
153 index += (upper_index - index) / 2;
156 index -= (index - lower_index) / 2;
166 definition !=
NULL &&
190 for (
int index = 0; index < _DefinitionCount; index ++) {
196 if (curr_def !=
NULL && ::stricmp (curr_def->
Get_Name (), name) == 0) {
197 definition = curr_def;
207 definition !=
NULL &&
229 if (DefinitionHash ==
NULL) {
230 WWDEBUG_SAY ((
"DefinitionMgrClass::Find_Typed_Definition () failed due to a NULL DefinitionHash.\n"));
249 for (
int i=0;i<defs->
Length();++i) {
253 if ( (curr_class_id == class_id) ||
257 definition = curr_def;
268 for (
int index = 0; index < _DefinitionCount; index ++) {
270 if (curr_def !=
NULL) {
276 if ( (curr_class_id == class_id) ||
283 if (::stricmp (curr_def->
Get_Name (), name) == 0) {
284 definition = curr_def;
288 DefinitionHash->
Insert(lower_case_name,defs);
290 defs->
Add(definition);
303 definition !=
NULL &&
325 for (
int index = 0; index < _DefinitionCount; index ++) {
327 if (curr_def !=
NULL) {
347 WWDEBUG_SAY((
"Available superclass definitions for 0x%8X:\n", superclass_id));
375 (definition ==
NULL) && (index < _DefinitionCount);
379 if (curr_def !=
NULL) {
386 definition = curr_def;
389 definition = curr_def;
418 (definition ==
NULL) && (index < _DefinitionCount);
422 if (curr_def !=
NULL) {
429 definition = curr_def;
432 definition = curr_def;
453 if (index < _DefinitionCount) {
454 definition = _SortedDefinitionArray[index];
470 if (DefinitionHash) {
477 DefinitionHash->Remove_All();
478 delete DefinitionHash;
485 for (
int index = 0; index < _DefinitionCount; index ++) {
487 if (definition !=
NULL) {
495 if (_SortedDefinitionArray !=
NULL) {
496 delete [] _SortedDefinitionArray;
499 _SortedDefinitionArray =
NULL;
500 _MaxDefinitionCount = 0;
501 _DefinitionCount = 0;
512DefinitionMgrClass::Prepare_Definition_Array (
void)
514 if (_DefinitionCount + 1 > _MaxDefinitionCount) {
519 int new_size = _MaxDefinitionCount + DEFINTION_LIST_GROW_SIZE;
525 ::memcpy (new_array, _SortedDefinitionArray, _DefinitionCount *
sizeof (
DefinitionClass *));
530 if (_SortedDefinitionArray !=
NULL) {
531 delete [] _SortedDefinitionArray;
533 _SortedDefinitionArray = new_array;
534 _MaxDefinitionCount = new_size;
536 if (!DefinitionHash) DefinitionHash=
W3DNEW HashTemplateClass<StringClass, DynamicVectorClass<DefinitionClass*>*>;
555 Prepare_Definition_Array ();
562 int upper_index = _DefinitionCount - 1;
563 int index = upper_index / 2;
564 int insert_index = _DefinitionCount;
565 bool keep_going = (_DefinitionCount > 0);
566 bool is_valid =
true;
577 if (curr_def->
Get_ID () ==
id) {
578 insert_index = index;
586 if (
id > curr_def->
Get_ID ()) {
588 index += (upper_index - index) / 2;
591 index -= (index - lower_index) / 2;
598 if (upper_index <= lower_index + 1) {
599 if (_SortedDefinitionArray[upper_index]->Get_ID () <=
id) {
600 insert_index = upper_index + 1;
601 }
else if (_SortedDefinitionArray[lower_index]->Get_ID () <=
id) {
602 insert_index = upper_index;
604 insert_index = lower_index;
617 for (index = _DefinitionCount - 1; index >= insert_index; index --) {
618 _SortedDefinitionArray[index + 1] = _SortedDefinitionArray[index];
619 _SortedDefinitionArray[index + 1]->m_DefinitionMgrLink = index + 1;
626 _SortedDefinitionArray[insert_index] = definition;
651 for (
int index = definition->
m_DefinitionMgrLink; index < _DefinitionCount - 1; index ++) {
652 _SortedDefinitionArray[index] = _SortedDefinitionArray[index + 1];
653 _SortedDefinitionArray[index]->m_DefinitionMgrLink = index;
656 _SortedDefinitionArray[_DefinitionCount - 1] =
NULL;
751 for (
int index = 0; index < _DefinitionCount; index ++) {
801 if (factory !=
NULL) {
804 if (definition !=
NULL) {
809 Prepare_Definition_Array ();
810 _SortedDefinitionArray[_DefinitionCount ++] = definition;
820 if (_DefinitionCount > 0) {
821 ::qsort (_SortedDefinitionArray, _DefinitionCount,
sizeof (
DefinitionClass *), fnCompareDefinitionsCallback);
827 for (
int index = 0; index < _DefinitionCount; index ++) {
828 _SortedDefinitionArray[index]->m_DefinitionMgrLink = index;
871 uint32 idrange_end = (idrange_start + IDRANGE_PER_CLASS);
873 uint32 new_id = idrange_start + 1;
878 for (
int index = 0; index < _DefinitionCount; index ++) {
880 if (definition !=
NULL) {
890 if (curr_id >= idrange_start && curr_id < idrange_end) {
893 if (index < _DefinitionCount - 1) {
900 if (next_definition !=
NULL && next_definition->
Get_ID () > (curr_id + 1)) {
912 new_id = curr_id + 1;
929DefinitionMgrClass::fnCompareDefinitionsCallback
946 }
else if (definition1->
Get_ID () < definition2->
Get_ID ()) {
uint32 Cur_Micro_Chunk_ID()
bool Begin_Chunk(uint32 id)
virtual uint32 Get_ID(void) const
virtual const char * Get_Name(void) const
virtual uint32 Get_Class_ID(void) const =0
bool Is_Save_Enabled(void) const
virtual bool Save(ChunkSaveClass &csave)
static DefinitionClass * Find_Typed_Definition(const char *name, uint32 class_id, bool twiddle=true)
bool Load_Objects(ChunkLoadClass &cload)
static DefinitionClass * Find_Named_Definition(const char *name, bool twiddle=true)
static DefinitionClass * Get_Next(DefinitionClass *curr_def)
bool Save_Variables(ChunkSaveClass &csave)
static void Unregister_Definition(DefinitionClass *definition)
static uint32 Get_New_ID(uint32 class_id)
~DefinitionMgrClass(void)
bool Save_Objects(ChunkSaveClass &csave)
static DefinitionClass * Get_First(void)
bool Load_Variables(ChunkLoadClass &cload)
static void Register_Definition(DefinitionClass *definition)
static DefinitionClass * Find_Definition(uint32 id, bool twiddle=true)
friend class DefinitionClass
static void List_Available_Definitions(void)
virtual bool Load(ChunkLoadClass &cload)
static void Free_Definitions(void)
bool Insert(int index, T const &object)
bool Add(T const &object)
virtual const PersistFactoryClass & Get_Factory(void) const =0
virtual uint32 Chunk_ID(void) const =0
virtual PersistClass * Load(ChunkLoadClass &cload) const =0
virtual void Save(ChunkSaveClass &csave, PersistClass *obj) const =0
static PersistFactoryClass * Find_Persist_Factory(uint32 chunk_id)
TCHAR * Peek_Buffer(void)
WWINLINE int Length(void) const
const int DEF_CLASSID_START
uint32 SuperClassID_From_ClassID(uint32 class_id)
DefinitionMgrClass _TheDefinitionMgr
#define WWMEMLOG(category)