00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #ifndef __BASICS_H__
00016 #define __BASICS_H__
00017
00018 #include "typedefs.h"
00019
00027 inline SI32 LongFromCharPtr(const unsigned char *p)
00028 {
00029 return (*p<<24) | (*(p+1)<<16) | (*(p+2)<<8) | *(p+3);
00030 }
00031
00039 inline SI16 ShortFromCharPtr(const unsigned char *p)
00040 {
00041 return static_cast<short>((*p<<8) | *(p+1));
00042 }
00043
00051 inline void LongToCharPtr(const UI32 i, unsigned char *p)
00052 {
00053 *p=static_cast<unsigned char>(i>>24);
00054 *(p+1)=static_cast<unsigned char>(i>>16);
00055 *(p+2)=static_cast<unsigned char>(i>>8);
00056 *(p+3)=static_cast<unsigned char>(i);
00057 }
00058
00066 inline void ShortToCharPtr(const UI16 i, unsigned char *p)
00067 {
00068 *p=static_cast<unsigned char>(i>>8);
00069 *(p+1)=static_cast<unsigned char>(i);
00070 }
00071
00073
00083 inline void numtostr(UI32 i, char *ourstring)
00084 {
00085 sprintf(ourstring,"%d",i);
00086 }
00087
00093 inline void hextostr(UI32 i, char *ourstring)
00094 {
00095 sprintf (ourstring, "%x",i);
00096 }
00098
00100
00104 #define BASE_INARRAY -1
00105 #define BASE_AUTO 0
00106 #define BASE_BIN 2
00107 #define BASE_OCT 8
00108 #define BASE_DEC 10
00109 #define BASE_HEX 16
00110
00111
00112
00120 int str2num(char* sz, int base = BASE_AUTO);
00121
00129 int str2num( wchar_t* sz, int base = BASE_AUTO);
00130
00137 inline int hex2num (char *sz)
00138 {
00139 return str2num(sz, BASE_HEX);
00140 }
00141
00143
00156 inline int str2num ( std::string& s, int base = BASE_AUTO )
00157 {
00158 return str2num( const_cast< char* >( s.c_str() ), base );
00159 }
00160
00168 inline int str2num ( std::wstring& s, int base = BASE_AUTO )
00169 {
00170 return str2num( const_cast< wchar_t* >(s.c_str()), base );
00171 }
00172
00173
00180 inline int hex2num ( std::string& s )
00181 {
00182 return str2num( const_cast< char* >( s.c_str() ), BASE_HEX );
00183 }
00185
00186 int fillIntArray(char* str, int *array, int maxsize, int defval = -1, int base = BASE_AUTO);
00187 void readSplitted(FILE* F, char* script1, char* script2);
00188 int RandomNum(int nLowNum, int nHighNum);
00189 char *RealTime(char *time_str);
00190 Location Loc(UI16 x, UI16 y, SI08 z, SI08 dispz=0);
00191
00192 #endif //__BASICS_H__