67 return( malloc(size) );
73 return( calloc(num, size) );
79 return( realloc(memblock, new_size) );
107 return( HeapAlloc(GetProcessHeap(), 0, size) );
112 return( HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, num * size) );
115void *
SG_Realloc(
void *memblock,
size_t new_size)
121 return( HeapReAlloc(GetProcessHeap(), 0, memblock, new_size) );
125 return( HeapAlloc(GetProcessHeap(), 0, new_size) );
140 HeapFree(GetProcessHeap(), 0, memblock);
159 pB = pA + nBytes - 1;
179 int Value = *(
int *)Buffer;
196 *((
int *)Buffer) = Value;
202 double Value = *(
double *)Buffer;
219 *(
double *)Buffer = Value;
236 m_Value_Size =
sizeof(char);
254 m_Value_Size = Array.m_Value_Size;
255 m_Growth = Array.m_Growth;
257 if( Array.m_nValues > 0 &&
Get_Array(Array.m_nValues) )
259 memcpy(m_Values, Array.m_Values, Array.m_nValues * Array.m_Value_Size);
272 Create(Value_Size, nValues, Growth);
279 m_Value_Size = Value_Size;
312 if( nValues >= m_nValues && nValues <= m_nBuffer )
319 if( nValues < m_nValues && !bShrink )
343 nBuffer = nValues < 10 ? nValues
344 : nValues < 100 ? (1 + nValues / 10) * 10
345 : nValues < 1000 ? (1 + nValues / 100) * 100
346 : nValues < 10000 ? (1 + nValues / 1000) * 1000
347 : (1 + nValues / 10000) * 10000;
351 nBuffer = nValues < 100 ? nValues
352 : nValues < 1000 ? (1 + nValues / 10) * 10
353 : nValues < 10000 ? (1 + nValues / 100) * 100
354 : nValues < 100000 ? (1 + nValues / 1000) * 1000
355 : (1 + nValues / 10000) * 10000;
359 nBuffer = nValues < 1000 ? (1 + nValues / 1000) * 1000
360 : nValues < 10000 ? (1 + nValues / 10000) * 10000
361 : nValues < 100000 ? (1 + nValues / 100000) * 100000
362 : (1 + nValues / 1000000) * 1000000;
376 if( nBuffer == m_nBuffer )
384 void *Values =
SG_Realloc(m_Values, nBuffer * m_Value_Size);
416 return(
Set_Array(m_nValues + nValues) );
421 return(
Set_Array(m_nValues + 1, pArray) );
427 return( m_nValues > 0 ?
Set_Array(m_nValues - 1, bShrink) :
false );
432 return( m_nValues > 0 ?
Set_Array(m_nValues - 1, pArray, bShrink) :
false );
438 if( Index >= 0 && Index < m_nValues )
440 if( Index < m_nValues - 1 )
442 char *ip = (
char *)m_Values + Index * m_Value_Size;
char *jp = ip + m_Value_Size;
444 for(
sLong i=Index, j=Index+1; j<m_nValues; i++, j++, ip+=m_Value_Size, jp+=m_Value_Size)
446 for(
size_t k=0; k<m_Value_Size; k++)
471 m_Array.Create(Array.m_Array);
473 return( (
void **)m_Array.Get_Array() );
479 m_Array.Create(
sizeof(
void *), nValues, Growth);
481 return( (
void **)m_Array.Get_Array() );
502 if(
Add(Array[i]) ==
false )
518 (*this)[Index] = (*this)[i];
534 if( Value == (*
this)[i - 1] &&
Del(i - 1) )
553 m_Array.Create(Array.m_Array);
555 return( (
int *)m_Array.Get_Array() );
561 m_Array.Create(
sizeof(
int), nValues, Growth);
563 return( (
int *)m_Array.Get_Array() );
584 if(
Add(Array[i]) ==
false )
614 m_Array.Create(Array.m_Array);
616 return( (
sLong *)m_Array.Get_Array() );
622 m_Array.Create(
sizeof(
sLong), nValues, Growth);
624 return( (
sLong *)m_Array.Get_Array() );
645 if(
Add(Array[i]) ==
false )
697 return(
Set_Data(Buffer.m_Data, Buffer.m_Size) );
738 else if( Size > m_Size || (Size < m_Size && bShrink) )
740 char *Data = (
char *)
SG_Realloc(m_Data, Size *
sizeof(
char));
757 if( !Data || !Size || !
Set_Size(Size, bShrink) )
762 memcpy(m_Data, Data, m_Size);
820 return(
Add((
void *)Bytes, nBytes,
false) );
858bool CSG_Bytes::_Inc_Array(
int nBytes)
860 if( m_nBuffer < m_nBytes + nBytes )
862 int nBuffer = m_nBuffer + nBytes + 1024;
863 BYTE *Bytes = (BYTE *)
SG_Realloc(m_Bytes, nBuffer *
sizeof(BYTE));
889 if( _Inc_Array(Bytes.m_nBytes) )
891 memcpy(m_Bytes, Bytes.m_Bytes, m_nBytes);
907 return(
Add(Bytes.m_Bytes, Bytes.m_nBytes,
false) );
913 int Offset = m_nBytes;
915 if( _Inc_Array(nBytes) )
917 memcpy(m_Bytes + Offset, Bytes, nBytes);
940 case '1':
return( 1 );
941 case '2':
return( 2 );
942 case '3':
return( 3 );
943 case '4':
return( 4 );
944 case '5':
return( 5 );
945 case '6':
return( 6 );
946 case '7':
return( 7 );
947 case '8':
return( 8 );
948 case '9':
return( 9 );
949 case 'a':
case 'A':
return( 10 );
950 case 'b':
case 'B':
return( 11 );
951 case 'c':
case 'C':
return( 12 );
952 case 'd':
case 'D':
return( 13 );
953 case 'e':
case 'E':
return( 14 );
954 case 'f':
case 'F':
return( 15 );
970 for(
int i=0; i<m_nBytes; i++)
985 for(
size_t i=0; i<HexString.
Length(); i+=2, s+=2)
1019 for(
int i=0; i<m_nBytes; i++)
1021 delete(m_pBytes[i]);
1037 if( m_nBytes >= m_nBuffer )
1050 return( m_pBytes[m_nBytes++] =
new CSG_Bytes );
@ SG_ARRAY_GROWTH_FIX_256
@ SG_ARRAY_GROWTH_FIX_512
@ SG_ARRAY_GROWTH_FIX_1024
@ SG_ARRAY_GROWTH_FIX_128
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
#define SG_FREE_SAFE(PTR)
SAGA_API_DLL_EXPORT void SG_Swap_Bytes(void *Buffer, int nBytes)
void * SG_Calloc(size_t num, size_t size)
void SG_Mem_Set_Int(char *Buffer, int Value, bool bSwapBytes)
void SG_Mem_Set_Double(char *Buffer, double Value, bool bSwapBytes)
double SG_Mem_Get_Double(const char *Buffer, bool bSwapBytes)
void SG_Swap_Bytes(void *Buffer, int nBytes)
BYTE SG_Hex_to_Byte(const SG_Char Hex)
void SG_Free(void *memblock)
void * SG_Realloc(void *memblock, size_t new_size)
void * SG_Malloc(size_t size)
int SG_Mem_Get_Int(const char *Buffer, bool bSwapBytes)
sLong Get_Size(void) const
CSG_Array_Int(const CSG_Array_Int &Array)
int * Create(const CSG_Array_Int &Array)
int * Get_Array(void) const
bool Inc_Array(sLong nValues=1)
sLong Get_Size(void) const
void ** Get_Array(void) const
bool Dec_Array(bool bShrink=true)
void ** Create(const CSG_Array_Pointer &Array)
bool Inc_Array(sLong nValues=1)
CSG_Array_Pointer(const CSG_Array_Pointer &Array)
CSG_Array_sLong(const CSG_Array_sLong &Array)
sLong Get_Size(void) const
sLong * Get_Array(void) const
sLong * Create(const CSG_Array_sLong &Array)
bool Inc_Array(sLong nValues=1)
void * Create(const CSG_Array &Array)
bool Set_Array(sLong nValues, bool bShrink=true)
bool Inc_Array(sLong nValues=1)
bool Dec_Array(bool bShrink=true)
bool Set_Growth(TSG_Array_Growth Growth)
bool Del_Entry(sLong Index, bool bShrink=true)
void * Get_Array(void) const
virtual ~CSG_Buffer(void)
bool Set_Size(size_t Size, bool bShrink=true)
bool Set_Data(const char *Data, size_t Size, bool bShrink=true)
virtual ~CSG_Bytes_Array(void)
bool fromHexString(const CSG_String &HexString)
CSG_String toHexString(void) const
bool Assign(const CSG_Bytes &Bytes)
bool Add(const CSG_Bytes &Bytes)
size_t Length(void) const
static CSG_String Format(const char *Format,...)
const SG_Char * c_str(void) const