blib.h
Go to the documentation of this file.00001 #ifndef CTL_BLIB_H
00002 #define CTL_BLIB_H
00003
00009 typedef struct BLIB
00010 {
00011 uint8 magic[4];
00012 uint32 userID;
00013 uint32 count;
00014 uint32 offsets[1];
00015 } BLIB;
00016
00017
00018
00019
00020
00021
00022
00023
00025 #define BLIB_MAGIC "BLIB"
00026
00028 #define BLIB_USER( blib ) ( (blib)->userID )
00029
00031 #define BLIB_COUNT( blib ) ( (blib)->count )
00032
00034 #define BLIB_SIZE( blib ) ( (blib)->offsets[(blib)->count] )
00035
00037 #define BLIB_ELEMENT_PTR( blib, index ) ( (blib)->magic + (blib)->offsets[index] )
00038
00040 #define BLIB_ELEMENT_SIZE( blib, index ) ( (blib)->offsets[(index)+1]-(blib)->offsets[index] )
00041
00043 #define BLIB_VALID( blib ) ( (blib) && (*((uint32 *)((blib)->magic)) == *((uint32 *)BLIB_MAGIC)) )
00044
00046 #define BLIB_INDEX_VALID( blib, index ) ( ((uint32)(index) < BLIB_SIZE( blib )) )
00047
00051 #define BLIB_foreach(blib,iterator)\
00052 const uint32* offCurr = (blib)->offsets;\
00053 const uint32* offEnd = offCurr + (blib)->count;\
00054 const void* iterator = (blib)->magic + *offCurr;\
00055 assert( BLIB_VALID( blib ) );\
00056 for( ; offCurr < offEnd; iterator = (blib)->magic + *++offCurr )
00057
00058
00059
00060
00061
00062 uint32 BLIB_Size( const BLIB *lib );
00063 uint32 BLIB_Count( const BLIB *lib );
00064 uint32 BLIB_User( const BLIB *lib );
00065 bool BLIB_Valid( const BLIB *lib, uint32 libSize );
00066 uint32 BLIB_ElementSize( const BLIB *lib, int index );
00067 const void *BLIB_ElementPointer( const BLIB *lib, int index );
00068 uint32 BLIB_ElementCopyData( const BLIB *lib, int index, void *data, uint32 dataSize );
00069
00070
00071
00072
00073 BLIB* BLIB_Create( uint32 userID );
00074 BLIB* BLIB_Copy( const BLIB *lib );
00075 void BLIB_Destroy( BLIB **lib );
00076 bool BLIB_ElementAdd( BLIB **lib, const void *data, uint32 dataSize );
00077 bool BLIB_ElementReplace( BLIB **lib, int index, const void *data, uint32 dataSize );
00078 bool BLIB_ElementInsert( BLIB **lib, int index, const void *data, uint32 dataSize );
00079 bool BLIB_ElementDelete( BLIB **lib, int index );
00080
00081
00082 #endif
00083