24 #include "Athena/Global.hpp"
25 #include "Athena/Types.hpp"
31 inline bool isEmpty(atInt8* buf, atUint32 size) {
return !memcmp(buf, buf + 1, size - 1);}
32 bool isSystemBigEndian();
34 inline atInt16 swap16(atInt16 val)
37 return __builtin_bswap16(val);
39 return _byteswap_ushort(val);
41 return (val = (val << 8) | ((val >> 8) & 0xFF));
44 inline atUint16 swapU16(atUint16 val) {
return (atUint16)swap16(val);}
45 inline atInt32 swap32(atInt32 val)
48 return __builtin_bswap32(val);
50 return _byteswap_ulong(val);
52 val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
53 val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
57 inline atUint32 swapU32(atUint32 val) {
return (atUint32)swap32(val);}
58 inline atInt64 swap64(atInt64 val)
61 return __builtin_bswap64(val);
63 return _byteswap_uint64(val);
65 return (val = ((atInt64)((((atInt64)(val) & 0xFF00000000000000ULL) >> 56) |
66 (((atInt64)(val) & 0x00FF000000000000ULL) >> 40) |
67 (((atInt64)(val) & 0x0000FF0000000000ULL) >> 24) |
68 (((atInt64)(val) & 0x000000FF00000000ULL) >> 8) |
69 (((atInt64)(val) & 0x00000000FF000000ULL) << 8) |
70 (((atInt64)(val) & 0x0000000000FF0000ULL) << 24) |
71 (((atInt64)(val) & 0x000000000000FF00ULL) << 40) |
72 (((atInt64)(val) & 0x00000000000000FFULL) << 56))));
75 inline atUint64 swapU64(atUint64 val) {
return (atUint64)swap64(val);}
76 inline float swapFloat(
float val)
78 atInt32 ival = swap64(static_cast<atInt32>(val));
79 return static_cast<float>(ival);
81 inline double swapDouble(
double val)
83 atInt64 ival = swap64(static_cast<atInt64>(val));
84 return static_cast<double>(ival);
86 inline atInt16 LittleInt16(atInt16& val)
88 if (Athena::utility::isSystemBigEndian())
89 val = Athena::utility::swap16(val);
93 inline atUint16 LittleUint16(atUint16& val)
101 inline atInt16 BigInt16(atInt16& val)
103 if (!Athena::utility::isSystemBigEndian())
104 val = Athena::utility::swap16(val);
108 inline atUint16 BigUint16(atUint16& val)
116 inline atInt32 LittleInt32(atInt32& val)
118 if (Athena::utility::isSystemBigEndian())
119 val = Athena::utility::swap32(val);
123 inline atUint32 LittleUint32(atUint32& val)
131 inline atInt32 BigInt32(atInt32& val)
133 if (!Athena::utility::isSystemBigEndian())
134 val = Athena::utility::swap32(val);
138 inline atUint32 BigUint32(atUint32& val)
146 inline atInt64 LittleInt64(atInt64& val)
148 if (Athena::utility::isSystemBigEndian())
149 val = Athena::utility::swap64(val);
153 inline atUint64 LittleUint64(atUint64& val)
161 inline atInt64 BigInt64(atInt64& val)
163 if (!Athena::utility::isSystemBigEndian())
164 val = Athena::utility::swap64(val);
168 inline atUint64 BigUint64(atUint64& val)
177 inline float LittleFloat(
float& val)
179 if (Athena::utility::isSystemBigEndian())
180 val = Athena::utility::swapFloat(val);
184 inline float BigFloat(
float& val)
186 if (!Athena::utility::isSystemBigEndian())
187 val = Athena::utility::swapFloat(val);
191 inline double LittleDouble(
double& val)
193 if (Athena::utility::isSystemBigEndian())
194 val = Athena::utility::swapDouble(val);
198 inline double BigDouble(
double& val)
200 if (!Athena::utility::isSystemBigEndian())
201 val = Athena::utility::swapDouble(val);
206 void fillRandom(atUint8 * rndArea, atUint64 count);
207 std::vector<std::string> split(
const std::string &s,
char delim);
209 std::string join(
const std::vector<std::string>& elems,
const std::string& delims);
210 void tolower(std::string& str);
211 void toupper(std::string& str);
212 std::string vsprintf(
const char* fmt, va_list list);
213 std::string sprintf(
const char* fmt, ...);
214 bool parseBool(
const std::string&
boolean,
bool* valid = NULL);
216 int countChar(
const std::string& str,
const char chr,
int* lastOccur = NULL);
219 std::string& ltrim(std::string& s);
222 std::string& rtrim(std::string& s);
225 std::string& trim(std::string& s);
226 atUint64 fileSize(
const std::string& filename);