Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

strblock.h File Reference

#include "basetype.h"
#include "vfile.h"

Go to the source code of this file.

Typedefs

typedef geStrBlock geStrBlock

Functions

geStrBlock *GENESISCC geStrBlock_Create (void)
void GENESISCC geStrBlock_Destroy (geStrBlock **SB)
geBoolean GENESISCC geStrBlock_Append (geStrBlock **ppSB, const char *String)
void GENESISCC geStrBlock_Delete (geStrBlock **ppSB, int Nth)
const char *GENESISCC geStrBlock_GetString (const geStrBlock *SB, int Index)
geBoolean GENESISCC geStrBlock_FindString (const geStrBlock *pSB, const char *String, int *pIndex)
int GENESISCC geStrBlock_GetCount (const geStrBlock *SB)
int GENESISCC geStrBlock_GetChecksum (const geStrBlock *SB)
geStrBlock *GENESISCC geStrBlock_CreateFromFile (geVFile *pFile)
geBoolean GENESISCC geStrBlock_WriteToFile (const geStrBlock *SB, geVFile *pFile)
geBoolean GENESISCC geStrBlock_WriteToBinaryFile (const geStrBlock *SB, geVFile *pFile)


Typedef Documentation

typedef struct geStrBlock geStrBlock
 

Definition at line 33 of file strblock.h.


Function Documentation

geBoolean GENESISCC geStrBlock_Append geStrBlock **  ppSB,
const char *  String
 

Definition at line 314 of file strblock.c.

References B, ERR_STRBLOCK_ENOMEM, ERR_STRBLOCK_STRLEN, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, GENESISCC, geRam_Realloc, geStrBlock_BlockSize(), NULL, geStrBlock::SanityCheck, and STRBLOCK_MAX_STRINGLEN.

Referenced by geBody_AddBone(), geBody_AddMaterial(), geMotion_AddPath(), gePose_AddJoint(), and geStrBlock_CreateFromFile().

00315 {
00316         int BlockSize;
00317         assert(  ppSB  != NULL );
00318         assert( *ppSB  != NULL );
00319         assert( String != NULL );
00320         assert( (*ppSB)->SanityCheck == (*ppSB) );
00321 
00322         if (strlen(String)>=STRBLOCK_MAX_STRINGLEN)
00323                 {
00324                         geErrorLog_Add(ERR_STRBLOCK_STRLEN, NULL);
00325                         return GE_FALSE;
00326                 }
00327 
00328         BlockSize = geStrBlock_BlockSize(*ppSB);
00329 
00330         {
00331                 geStrBlock * NewgeStrBlock;
00332 
00333                 NewgeStrBlock = geRam_Realloc( *ppSB, 
00334                         BlockSize                               // size of data block
00335                         + sizeof(geStrBlock)            // size of strblock structure
00336                         + strlen(String) + 1            // size of new string
00337                         + sizeof(int) );                // size of new index to string
00338                 if ( NewgeStrBlock == NULL )
00339                         {
00340                                 geErrorLog_Add(ERR_STRBLOCK_ENOMEM, NULL);
00341                                 return GE_FALSE;
00342                         }
00343                 *ppSB = NewgeStrBlock;
00344                 (*ppSB)->SanityCheck = NewgeStrBlock;
00345         }
00346 
00347         {
00348                 geStrBlock *B = *ppSB;
00349                 int i;
00350                 for (i=0; i<B->Count; i++)
00351                         {
00352                                 B->Data.IntArray[i] += sizeof(int);
00353                         }
00354                 if (B->Count > 0)
00355                         {
00356                                 memmove(&(B->Data.IntArray[B->Count+1]),
00357                                                 &(B->Data.IntArray[B->Count]),
00358                                                 BlockSize - sizeof(int) * B->Count);
00359                         }
00360                 B->Data.IntArray[B->Count] = BlockSize + sizeof(int);
00361                 strcpy(&(B->Data.CharArray[B->Data.IntArray[B->Count]]),String);
00362         }
00363         (*ppSB)->Count++;
00364         return GE_TRUE;
00365 }

geStrBlock* GENESISCC geStrBlock_Create void   ) 
 

Definition at line 75 of file strblock.c.

References geStrBlock::Count, ERR_STRBLOCK_ENOMEM, GE_RAM_ALLOCATE_STRUCT, geErrorLog_Add, GENESISCC, NULL, and geStrBlock::SanityCheck.

Referenced by geBody_Create(), geMotion_InitNodeAsLeaf(), gePose_Create(), and geStrBlock_CreateFromFile().

00076 {
00077         geStrBlock *SB;
00078         
00079         SB = GE_RAM_ALLOCATE_STRUCT(geStrBlock);
00080 
00081         if ( SB == NULL )
00082                 {
00083                         geErrorLog_Add(ERR_STRBLOCK_ENOMEM, NULL);
00084                         return NULL;
00085                 }
00086         SB->Count=0;
00087         SB->SanityCheck = SB;
00088         return SB;
00089 }

geStrBlock* GENESISCC geStrBlock_CreateFromFile geVFile pFile  ) 
 

Definition at line 396 of file strblock.c.

References ERR_STRBLOCK_ENOMEM, ERR_STRBLOCK_FILE_PARSE, ERR_STRBLOCK_FILE_READ, GE_FALSE, geErrorLog_Add, GENESISCC, geStrBlock_Append(), geStrBlock_Create(), geStrBlock_CreateFromBinaryFile(), geStrBlock_Destroy(), geVFile_GetS(), geVFile_Read(), NULL, STRBLOCK_ASCII_FILE_TYPE, STRBLOCK_BIN_FILE_TYPE, STRBLOCK_FILE_VERSION, STRBLOCK_MAX_STRINGLEN, STRBLOCK_NUM_ASCII_IDS, STRBLOCK_STRINGARRAY_ID, uint32, and v.

Referenced by geBody_ReadGeometry(), geMotion_CreateFromFile(), and geMotion_ReadBinaryLeaf().

00397 {
00398         uint32 u, v;
00399         geStrBlock* SB;
00400         char    VersionString[32];
00401 
00402         assert( pFile != NULL );
00403 
00404         if(geVFile_Read(pFile, &u, sizeof(u)) == GE_FALSE)
00405         {
00406                 geErrorLog_Add( ERR_STRBLOCK_FILE_READ , NULL);
00407                 return NULL;
00408         }
00409 
00410         if(u == STRBLOCK_ASCII_FILE_TYPE)
00411         {
00412                 int NumItemsNeeded=0;
00413                 int NumItemsRead = 0;
00414                 char line[STRBLOCK_MAX_STRINGLEN];
00415 
00416                 SB = geStrBlock_Create();
00417                 if( SB == NULL )
00418                 {
00419                         geErrorLog_Add(ERR_STRBLOCK_ENOMEM, NULL);
00420                         return NULL;
00421                 }
00422 
00423                 // Read and build the version.  Then determine the number of items to read.
00424                 if      (geVFile_GetS(pFile, VersionString, sizeof(VersionString)) == GE_FALSE)
00425                 {
00426                         geErrorLog_Add( ERR_STRBLOCK_FILE_READ , NULL);
00427                         return NULL;
00428                 }
00429                 if      (sscanf(VersionString, "%X.%X\n", &u, &v) != 2)
00430                 {
00431                         geErrorLog_Add( ERR_STRBLOCK_FILE_READ , NULL);
00432                         return NULL;
00433                 }
00434                 v |= (u << 8);
00435                 if(v >= STRBLOCK_FILE_VERSION)
00436                 {
00437                         NumItemsNeeded = STRBLOCK_NUM_ASCII_IDS;
00438                 }
00439 
00440                 while(NumItemsRead < NumItemsNeeded)
00441                 {
00442                         if(geVFile_GetS(pFile, line, STRBLOCK_MAX_STRINGLEN) == GE_FALSE)
00443                                 {
00444                                         geErrorLog_Add( ERR_STRBLOCK_FILE_READ , NULL);
00445                                         break; // got to read something
00446                                 }
00447                         else if(strnicmp(line, STRBLOCK_STRINGARRAY_ID, sizeof(STRBLOCK_STRINGARRAY_ID)-1) == 0)
00448                         {
00449                                 int i,Count;
00450                                 if(sscanf(line + sizeof(STRBLOCK_STRINGARRAY_ID)-1, "%d", &Count) != 1)
00451                                         {                                               
00452                                                 geErrorLog_Add( ERR_STRBLOCK_FILE_READ , NULL);
00453                                                 break;           
00454                                         }
00455                                 for (i=0; i<Count;i++)
00456                                         {
00457                                                 if(geVFile_GetS(pFile, line, STRBLOCK_MAX_STRINGLEN) == GE_FALSE)
00458                                                         {
00459                                                                 geErrorLog_Add( ERR_STRBLOCK_FILE_READ , NULL);
00460                                                                 break; // got to read something
00461                                                         }
00462                                                 if ( line[0] != 0 )
00463                                                         line[strlen(line)-1] = 0;       // remove trailing /n  (textmode)
00464                                                 if ( line[0] != 0 )
00465                                                         {
00466                                                                 int len = strlen(line)-1;
00467                                                                 if (line[len] == 13)  // remove trailing /r  (binary file mode)
00468                                                                         {
00469                                                                                 line[len] = 0;
00470                                                                         }
00471                                                         }
00472                                                 if (geStrBlock_Append(&SB,line)==GE_FALSE)
00473                                                         {
00474                                                                 break; // error logged in _Append
00475                                                         }
00476                                         }
00477                                 NumItemsRead++;
00478                         }
00479 
00480                         
00481                 }
00482 
00483                 if(NumItemsNeeded == NumItemsRead)
00484                 {
00485                         return SB;
00486                 }
00487                 else
00488                 {
00489                         geErrorLog_Add( ERR_STRBLOCK_FILE_PARSE , NULL);
00490                         geStrBlock_Destroy(&SB); // try to destroy it
00491                         return NULL;
00492                 }
00493         }
00494         else
00495         {
00496                 if (u!=STRBLOCK_BIN_FILE_TYPE)
00497                         {
00498                                 geErrorLog_Add( ERR_STRBLOCK_FILE_PARSE , NULL);
00499                                 return NULL;
00500                         }
00501                 return geStrBlock_CreateFromBinaryFile(pFile);
00502         }
00503                         
00504         geErrorLog_Add( ERR_STRBLOCK_FILE_PARSE , NULL);
00505         return NULL;
00506 }

void GENESISCC geStrBlock_Delete geStrBlock **  ppSB,
int  Nth
 

Definition at line 118 of file strblock.c.

References B, geStrBlock::Count, GENESISCC, geRam_Realloc, geStrBlock_BlockSize(), geStrBlock_GetString(), NULL, and geStrBlock::SanityCheck.

00119 {
00120         int BlockSize;
00121         int StringLen;
00122         int CloseSize;
00123         const char *String;
00124         assert(  ppSB  != NULL );
00125         assert( *ppSB  != NULL );
00126         assert( Nth >=0 );
00127         assert( Nth < (*ppSB)->Count );
00128         assert( (*ppSB)->SanityCheck == (*ppSB) );
00129 
00130         String = geStrBlock_GetString(*ppSB,Nth);
00131         assert( String != NULL );
00132         StringLen = strlen(String) + 1;
00133                 
00134         BlockSize = geStrBlock_BlockSize(*ppSB);
00135 
00136         {
00137                 geStrBlock *B = *ppSB;
00138                 char *ToBeReplaced;
00139                 char *Replacement=NULL;
00140                 int i;
00141                 ToBeReplaced = &((*ppSB)->Data.CharArray[(*ppSB)->Data.IntArray[Nth]]);
00142                 if (Nth< (*ppSB)->Count-1)
00143                         Replacement  = &((*ppSB)->Data.CharArray[(*ppSB)->Data.IntArray[Nth+1]]);
00144                 for (i=Nth+1,CloseSize = 0; i<(*ppSB)->Count ; i++)
00145                         {
00146                                 CloseSize += strlen(&((*ppSB)->Data.CharArray[(*ppSB)->Data.IntArray[i]])) +1;
00147                                 B->Data.IntArray[i] -= StringLen;
00148                         }
00149                 for (i=0; i<(*ppSB)->Count ; i++)
00150                         {
00151                                 B->Data.IntArray[i] -= sizeof(int);
00152                         }
00153                 // crunch out Nth string
00154                 if (Nth< (*ppSB)->Count-1)
00155                         memmove(ToBeReplaced,Replacement,CloseSize);
00156                 // crunch out Nth index
00157                 memmove(&(B->Data.IntArray[Nth]),
00158                                 &(B->Data.IntArray[Nth+1]),
00159                                 BlockSize - ( sizeof(int) *  (Nth+1) ) );
00160 
00161         }
00162         
00163         {
00164                 geStrBlock * NewgeStrBlock;
00165 
00166                 NewgeStrBlock = geRam_Realloc( *ppSB, 
00167                         BlockSize                               // size of data block
00168                         + sizeof(geStrBlock)            // size of strblock structure
00169                         - StringLen                             // size of dying string
00170                         - sizeof(int) );                // size of new index to string
00171                 if ( NewgeStrBlock != NULL )
00172                         {
00173                                 *ppSB = NewgeStrBlock;
00174                                 (*ppSB)->SanityCheck = NewgeStrBlock;
00175                         }
00176         }
00177 
00178         (*ppSB)->Count--;
00179 }

void GENESISCC geStrBlock_Destroy geStrBlock **  SB  ) 
 

Definition at line 92 of file strblock.c.

References GENESISCC, geRam_Free, and NULL.

Referenced by geBody_DestroyPossiblyIncompleteBody(), geMotion_RemoveNames(), gePose_Create(), gePose_Destroy(), and geStrBlock_CreateFromFile().

00093 {
00094         assert( (*SB)->SanityCheck == (*SB) );
00095         assert(  SB != NULL );
00096         assert( *SB != NULL );  
00097         geRam_Free( *SB );
00098         *SB = NULL;
00099 }

geBoolean GENESISCC geStrBlock_FindString const geStrBlock pSB,
const char *  String,
int *  pIndex
 

Definition at line 289 of file strblock.c.

References GE_FALSE, GE_TRUE, geBoolean, GENESISCC, geStrBlock_GetCount(), geStrBlock_GetString(), NULL, and geStrBlock::SanityCheck.

Referenced by geBody_AddMaterial(), and geBody_GetBoneByName().

00290 {
00291         int i;
00292         int Count;
00293         const char *Str;
00294 
00295         assert(pSB != NULL);
00296         assert(String != NULL);
00297         assert(pIndex != NULL);
00298         assert( pSB->SanityCheck == pSB );
00299 
00300         Count = geStrBlock_GetCount(pSB);
00301         for (i=0; i<Count; i++)
00302         {
00303                 Str = geStrBlock_GetString(pSB,i);
00304                 if(strcmp(String, Str) == 0)
00305                 {
00306                         *pIndex = i;
00307                         return GE_TRUE;
00308                 }
00309         }
00310         return GE_FALSE;
00311 }

int GENESISCC geStrBlock_GetChecksum const geStrBlock SB  ) 
 

Definition at line 51 of file strblock.c.

References GENESISCC, geStrBlock_GetCount(), geStrBlock_GetString(), and NULL.

Referenced by geBody_GetBoneNameChecksum(), geMotion_AddPath(), and gePose_AddJoint().

00052 {
00053         int Count;
00054         int Len;
00055         int i,j;
00056         const char *Str;
00057         int Checksum=0;
00058         assert( SB != NULL );
00059 
00060         Count = geStrBlock_GetCount(SB);
00061         for (i=0; i<Count; i++)
00062                 {
00063                         Str = geStrBlock_GetString(SB,i);
00064                         assert(Str!=NULL);
00065                         Len = strlen(Str);
00066                         for (j=0; j<Len; j++)
00067                                  {
00068                                         Checksum += (int)Str[j];
00069                                 }
00070                         Checksum = Checksum*3;
00071                 }
00072         return Checksum;
00073 }

int GENESISCC geStrBlock_GetCount const geStrBlock SB  ) 
 

Definition at line 377 of file strblock.c.

References geStrBlock::Count, GENESISCC, NULL, and geStrBlock::SanityCheck.

Referenced by geBody_SanityCheck(), gePose_AddJoint(), gePose_Destroy(), geStrBlock_FindString(), geStrBlock_GetChecksum(), and geStrBlock_WriteToFile().

00378 {
00379         assert( SB != NULL);
00380         assert( SB->SanityCheck == SB );
00381         return SB->Count;
00382 }

const char* GENESISCC geStrBlock_GetString const geStrBlock SB,
int  Index
 

Definition at line 368 of file strblock.c.

References geStrBlock::Data, GENESISCC, NULL, and geStrBlock::SanityCheck.

Referenced by geBody_GetBone(), geBody_GetMaterial(), geMotion_GetNameOfPath(), geMotion_GetPathNamed(), gePose_AccumulateCoverage(), gePose_BlendMotion(), gePose_FindNamedJointIndex(), gePose_GetJointName(), gePose_SetMotion(), gePose_SetMotionForABoneRecursion(), geStrBlock_Delete(), geStrBlock_FindString(), geStrBlock_GetChecksum(), and geStrBlock_WriteToFile().

00369 {
00370         assert( SB != NULL );
00371         assert( Index >= 0 );
00372         assert( Index < SB->Count );
00373         assert( SB->SanityCheck == SB );
00374         return &(SB->Data.CharArray[SB->Data.IntArray[Index]]);
00375 }

geBoolean GENESISCC geStrBlock_WriteToBinaryFile const geStrBlock SB,
geVFile pFile
 

Definition at line 589 of file strblock.c.

References geStrBlock::Count, geStrBlock_BinaryFileHeader::Count, geStrBlock::Data, ERR_STRBLOCK_FILE_WRITE, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, GENESISCC, geStrBlock_BlockSize(), geVFile_Write(), NULL, geStrBlock::SanityCheck, geStrBlock_BinaryFileHeader::Size, STRBLOCK_BIN_FILE_TYPE, and uint32.

Referenced by geBody_WriteGeometry(), and geMotion_WriteBinaryLeaf().

00590 {
00591         uint32 u;
00592         geStrBlock_BinaryFileHeader Header;
00593 
00594         assert( SB != NULL );
00595         assert( pFile != NULL );
00596         assert( SB->SanityCheck == SB );
00597 
00598         // Write the format flag
00599         u = STRBLOCK_BIN_FILE_TYPE;
00600         if(geVFile_Write(pFile, &u, sizeof(u)) == GE_FALSE)
00601                 {
00602                         geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00603                         return GE_FALSE;
00604                 }
00605 
00606         Header.Size = geStrBlock_BlockSize(SB);
00607         Header.Count = SB->Count;
00608 
00609         if(geVFile_Write(pFile, &Header, sizeof(geStrBlock_BinaryFileHeader)) == GE_FALSE)
00610                 {
00611                         geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00612                         return GE_FALSE;
00613                 }
00614         
00615         if (geVFile_Write(pFile, &(SB->Data),Header.Size) == GE_FALSE)
00616                 {
00617                         geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00618                         return GE_FALSE;
00619                 }
00620                 
00621         return GE_TRUE;
00622 }

geBoolean GENESISCC geStrBlock_WriteToFile const geStrBlock SB,
geVFile pFile
 

Definition at line 508 of file strblock.c.

References count, ERR_STRBLOCK_FILE_WRITE, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, GENESISCC, geStrBlock_GetCount(), geStrBlock_GetString(), geVFile_Printf(), geVFile_Write(), NULL, geStrBlock::SanityCheck, STRBLOCK_ASCII_FILE_TYPE, STRBLOCK_FILE_VERSION, STRBLOCK_MAX_STRINGLEN, STRBLOCK_STRINGARRAY_ID, and uint32.

Referenced by geMotion_WriteLeaf().

00509 {
00510         uint32 u;
00511         int i,count;
00512 
00513         assert( SB != NULL );
00514         assert( pFile != NULL );
00515         assert( SB->SanityCheck == SB );
00516 
00517 
00518         // Write the format flag
00519         u = STRBLOCK_ASCII_FILE_TYPE;
00520         if(geVFile_Write(pFile, &u, sizeof(u)) == GE_FALSE)
00521         {
00522                 geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00523                 return GE_FALSE;
00524         }
00525 
00526         // Write the version
00527         if      (geVFile_Printf(pFile, " %X.%.2X\n", (STRBLOCK_FILE_VERSION & 0xFF00) >> 8, 
00528                                                                         STRBLOCK_FILE_VERSION & 0x00FF) == GE_FALSE)
00529         {
00530                 geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00531                 return GE_FALSE;
00532         }
00533 
00534         count = geStrBlock_GetCount(SB);
00535         if      (geVFile_Printf(pFile, "%s %d\n", STRBLOCK_STRINGARRAY_ID,count) == GE_FALSE)
00536         {
00537                 geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00538                 return GE_FALSE;
00539         }
00540         for (i=0; i<count; i++)
00541                 {
00542                         assert( strlen(geStrBlock_GetString(SB,i))<STRBLOCK_MAX_STRINGLEN);
00543                         if      (geVFile_Printf(pFile,"%s\n",geStrBlock_GetString(SB,i)) == GE_FALSE)
00544                         {
00545                                 geErrorLog_Add( ERR_STRBLOCK_FILE_WRITE , NULL);
00546                                 return GE_FALSE;
00547                         }
00548                 }
00549         return GE_TRUE;
00550 }


Generated on Tue Sep 30 12:38:10 2003 for GTestAndEngine by doxygen 1.3.2