8 #include "athena/Global.hpp" 9 #include "athena/Types.hpp" 15 inline bool isEmpty(atInt8* buf, atUint32 size) {
return !memcmp(buf, buf + 1, size - 1);}
16 inline bool isSystemBigEndian() {
return (*(atUint16*)
"\xFE\xFF" == 0xFEFF);}
18 inline atInt16 swap16(atInt16 val)
21 return __builtin_bswap16(val);
23 return _byteswap_ushort(val);
25 return (val = (val << 8) | ((val >> 8) & 0xFF));
28 inline atUint16 swapU16(atUint16 val) {
return (atUint16)swap16(val);}
29 inline atInt32 swap32(atInt32 val)
32 return __builtin_bswap32(val);
34 return _byteswap_ulong(val);
36 val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
37 val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
41 inline atUint32 swapU32(atUint32 val) {
return (atUint32)swap32(val);}
42 inline atInt64 swap64(atInt64 val)
45 return __builtin_bswap64(val);
47 return _byteswap_uint64(val);
49 return (val = ((atInt64)((((atInt64)(val) & 0xFF00000000000000ULL) >> 56) |
50 (((atInt64)(val) & 0x00FF000000000000ULL) >> 40) |
51 (((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) |
52 (((atInt64)(val) & 0x000000FF00000000ULL) >> 8) |
53 (((atInt64)(val) & 0x00000000FF000000ULL) << 8) |
54 (((atInt64)(val) & 0x0000000000FF0000ULL) << 24) |
55 (((atInt64)(val) & 0x000000000000FF00ULL) << 40) |
56 (((atInt64)(val) & 0x00000000000000FFULL) << 56))));
59 inline atUint64 swapU64(atUint64 val) {
return (atUint64)swap64(val);}
60 inline float swapFloat(
float val)
62 atInt32 ival = swap32(*((atInt32*)(&val)));
63 return *((
float*)(&ival));
65 inline double swapDouble(
double val)
67 atInt64 ival = swap64(*((atInt64*)(&val)));
68 return *((
double*)(&ival));
70 inline atInt16 LittleInt16(atInt16& val)
72 if (athena::utility::isSystemBigEndian())
73 val = athena::utility::swap16(val);
77 inline atUint16 LittleUint16(atUint16& val)
85 inline atInt16 BigInt16(atInt16& val)
87 if (!athena::utility::isSystemBigEndian())
88 val = athena::utility::swap16(val);
92 inline atUint16 BigUint16(atUint16& val)
100 inline atInt32 LittleInt32(atInt32& val)
102 if (athena::utility::isSystemBigEndian())
103 val = athena::utility::swap32(val);
107 inline atUint32 LittleUint32(atUint32& val)
115 inline atInt32 BigInt32(atInt32& val)
117 if (!athena::utility::isSystemBigEndian())
118 val = athena::utility::swap32(val);
122 inline atUint32 BigUint32(atUint32& val)
130 inline atInt64 LittleInt64(atInt64& val)
132 if (athena::utility::isSystemBigEndian())
133 val = athena::utility::swap64(val);
137 inline atUint64 LittleUint64(atUint64& val)
145 inline atInt64 BigInt64(atInt64& val)
147 if (!athena::utility::isSystemBigEndian())
148 val = athena::utility::swap64(val);
152 inline atUint64 BigUint64(atUint64& val)
161 inline float LittleFloat(
float& val)
163 if (athena::utility::isSystemBigEndian())
164 val = athena::utility::swapFloat(val);
168 inline float BigFloat(
float& val)
170 if (!athena::utility::isSystemBigEndian())
171 val = athena::utility::swapFloat(val);
175 inline double LittleDouble(
double& val)
177 if (athena::utility::isSystemBigEndian())
178 val = athena::utility::swapDouble(val);
182 inline double BigDouble(
double& val)
184 if (!athena::utility::isSystemBigEndian())
185 val = athena::utility::swapDouble(val);
190 void fillRandom(atUint8 * rndArea, atUint64 count);
191 std::vector<std::string> split(
const std::string &s,
char delim);
193 std::string join(
const std::vector<std::string>& elems,
const std::string& delims);
194 void tolower(std::string& str);
195 void toupper(std::string& str);
196 std::string vsprintf(
const char* fmt, va_list list);
197 std::string sprintf(
const char* fmt, ...);
198 bool parseBool(
const std::string&
boolean,
bool* valid = NULL);
200 int countChar(
const std::string& str,
const char chr,
int* lastOccur = NULL);
203 std::string& ltrim(std::string& s);
206 std::string& rtrim(std::string& s);
209 std::string& trim(std::string& s);
210 atUint64 fileSize(
const std::string& filename);
212 atUint64 fileSize(
const std::wstring& filename);
215 std::string wideToUtf8(
const std::wstring& src);
217 std::wstring utf8ToWide(
const std::string& src);