5 char* win_realpath(
const char* name,
char* restrict resolved);
22 #include "../extern/blowfish/blowfish.h"
31 std::string WideToUTF8(
const std::wstring& src);
32 std::wstring UTF8ToWide(
const std::string& src);
35 typedef wchar_t SystemChar;
36 typedef std::wstring SystemString;
37 static inline void ToLower(SystemString& str)
38 {std::transform(str.begin(), str.end(), str.begin(), towlower);}
39 static inline void ToUpper(SystemString& str)
40 {std::transform(str.begin(), str.end(), str.begin(), towupper);}
45 SystemUTF8View(
const SystemString& str)
46 : m_utf8(WideToUTF8(str)) {}
47 inline const std::string& utf8_str() {
return m_utf8;}
49 class SystemStringView
53 SystemStringView(
const std::string& str)
54 : m_sys(UTF8ToWide(str)) {}
55 inline const std::wstring& sys_str() {
return m_sys;}
58 #define _S(val) L ## val
61 typedef char SystemChar;
62 typedef std::string SystemString;
63 static inline void ToLower(SystemString& str)
64 {std::transform(str.begin(), str.end(), str.begin(), tolower);}
65 static inline void ToUpper(SystemString& str)
66 {std::transform(str.begin(), str.end(), str.begin(), toupper);}
69 const std::string& m_utf8;
73 inline const std::string& utf8_str() {
return m_utf8;}
77 const std::string& m_sys;
81 inline const std::string& sys_str() {
return m_sys;}
92 std::string m_utf8what;
95 Exception(
const SystemString& what) noexcept
99 m_utf8what = WideToUTF8(what);
102 const char* what()
const noexcept
105 return m_utf8what.c_str();
107 return m_what.c_str();
110 inline const SystemChar* swhat()
const noexcept {
return m_what.c_str();}
113 static inline void MakeDir(
const SystemString& dir)
117 if (!CreateDirectory(dir.c_str(), NULL))
118 if ((err = GetLastError()) != ERROR_ALREADY_EXISTS)
119 throw std::error_code(err, std::system_category());
121 if (mkdir(dir.c_str(), 0755))
123 throw std::error_code(errno, std::system_category());
127 static inline SystemChar* Getcwd(SystemChar* buf,
int maxlen)
130 return wgetcwd(buf, maxlen);
132 return getcwd(buf, maxlen);
142 static inline FILE* Fopen(
const SystemChar* path,
const SystemChar* mode, FileLockType lock=LNONE)
145 FILE* fp = wfopen(path, mode);
147 FILE* fp = fopen(path, mode);
150 throw std::error_code(errno, std::system_category());
155 HANDLE fhandle = (HANDLE)fileno(fp);
157 LockFileEx(fhandle, (lock == LWRITE) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov);
161 (short)((lock == LREAD) ? F_RDLCK : F_WRLCK),
164 fcntl(fileno(fp), F_SETLK, &lk);
171 static inline int Stat(
const SystemChar* path,
struct stat* statOut)
174 return wstat(path, statOut);
176 return stat(path, statOut);
180 static inline void Printf(
const SystemChar* format, ...)
183 va_start(va, format);
185 vwprintf(format, va);
192 static inline void FPrintf(FILE* fp,
const SystemChar* format, ...)
195 va_start(va, format);
197 vfwprintf(fp, format, va);
199 vfprintf(fp, format, va);
204 typedef std::basic_regex<SystemChar> SystemRegex;
205 typedef std::regex_token_iterator<SystemString::const_iterator> SystemRegexTokenIterator;
206 typedef std::match_results<SystemString::const_iterator> SystemRegexMatch;
208 class ProjectRootPath;
223 typedef std::function<void(LogType, std::string&)> FLogger;
243 : num(*(uint32_t*)name) {}
244 inline bool operator==(
const FourCC& other)
const {
return num == other.num;}
245 inline bool operator!=(
const FourCC& other)
const {
return num != other.num;}
246 inline bool operator==(
const char* other)
const {
return num == *(uint32_t*)other;}
247 inline bool operator!=(
const char* other)
const {
return num != *(uint32_t*)other;}
248 inline std::string toString()
const {
return std::string(fcc, 4);}
261 Hash(
const void* buf,
size_t len)
262 : hash(Blowfish_hash(buf, len)) {}
263 Hash(
const std::string& str)
264 : hash(Blowfish_hash(str.data(), str.size())) {}
267 Hash(
const Hash& other) {hash = other.hash;}
268 inline Hash& operator=(
const Hash& other) {hash = other.hash;
return *
this;}
269 inline bool operator==(
const Hash& other)
const {
return hash == other.hash;}
270 inline bool operator!=(
const Hash& other)
const {
return hash != other.hash;}
271 inline bool operator<(
const Hash& other)
const {
return hash < other.hash;}
272 inline bool operator>(
const Hash& other)
const {
return hash > other.hash;}
273 inline bool operator<=(
const Hash& other)
const {
return hash <= other.hash;}
274 inline bool operator>=(
const Hash& other)
const {
return hash >= other.hash;}
284 Time() : ts(time(NULL)) {}
285 Time(time_t ti) : ts(ti) {}
286 Time(
const Time& other) {ts = other.ts;}
287 inline time_t getTs()
const {
return ts;}
288 inline Time& operator=(
const Time& other) {ts = other.ts;
return *
this;}
289 inline bool operator==(
const Time& other)
const {
return ts == other.ts;}
290 inline bool operator!=(
const Time& other)
const {
return ts != other.ts;}
291 inline bool operator<(
const Time& other)
const {
return ts < other.ts;}
292 inline bool operator>(
const Time& other)
const {
return ts > other.ts;}
293 inline bool operator<=(
const Time& other)
const {
return ts <= other.ts;}
294 inline bool operator>=(
const Time& other)
const {
return ts >= other.ts;}
313 SystemString m_absPath;
314 SystemString m_relPath;
317 std::string m_utf8AbsPath;
318 const char* m_utf8RelPath;
321 bool _canonAbsPath(
const SystemString& path);
334 inline bool isRoot()
const {
return m_relPath.empty();}
348 if (m_relPath.size())
350 static const SystemString dot = _S(
".");
361 return m_utf8AbsPath;
367 inline const std::string& getRelativePathUTF8()
const
370 return m_utf8RelPath;
413 inline size_t hash()
const {
return m_hash;}
414 inline bool operator==(
const ProjectPath& other)
const {
return m_hash == other.m_hash;}
415 inline bool operator!=(
const ProjectPath& other)
const {
return m_hash != other.m_hash;}
429 {_canonAbsPath(path);}
441 template <
typename T>
442 static inline T bswap16(T val)
445 return __builtin_bswap16(val);
447 return _byteswap_ushort(val);
449 return (val = (val << 8) | ((val >> 8) & 0xFF));
453 template <
typename T>
454 static inline T bswap32(T val)
457 return __builtin_bswap32(val);
459 return _byteswap_ulong(val);
461 val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
462 val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8;
467 template <
typename T>
468 static inline T bswap64(T val)
471 return __builtin_bswap64(val);
473 return _byteswap_uint64(val);
475 return ((val & 0xFF00000000000000ULL) >> 56) |
476 ((val & 0x00FF000000000000ULL) >> 40) |
477 ((val & 0x0000FF0000000000ULL) >> 24) |
478 ((val & 0x000000FF00000000ULL) >> 8) |
479 ((val & 0x00000000FF000000ULL) << 8) |
480 ((val & 0x0000000000FF0000ULL) << 24) |
481 ((val & 0x000000000000FF00ULL) << 40) |
482 ((val & 0x00000000000000FFULL) << 56);
487 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
488 static inline int16_t ToBig(int16_t val) {
return bswap16(val);}
489 static inline uint16_t ToBig(uint16_t val) {
return bswap16(val);}
490 static inline int32_t ToBig(int32_t val) {
return bswap32(val);}
491 static inline uint32_t ToBig(uint32_t val) {
return bswap32(val);}
492 static inline int64_t ToBig(int64_t val) {
return bswap64(val);}
493 static inline uint64_t ToBig(uint64_t val) {
return bswap64(val);}
495 static inline int16_t ToLittle(int16_t val) {
return val;}
496 static inline uint16_t ToLittle(uint16_t val) {
return val;}
497 static inline int32_t ToLittle(int32_t val) {
return val;}
498 static inline uint32_t ToLittle(uint32_t val) {
return val;}
499 static inline int64_t ToLittle(int64_t val) {
return val;}
500 static inline uint64_t ToLittle(uint64_t val) {
return val;}
502 static inline int16_t ToLittle(int16_t val) {
return bswap16(val);}
503 static inline uint16_t ToLittle(uint16_t val) {
return bswap16(val);}
504 static inline int32_t ToLittle(int32_t val) {
return bswap32(val);}
505 static inline uint32_t ToLittle(uint32_t val) {
return bswap32(val);}
506 static inline int64_t ToLittle(int64_t val) {
return bswap64(val);}
507 static inline uint64_t ToLittle(uint64_t val) {
return bswap64(val);}
509 static inline int16_t ToBig(int16_t val) {
return val;}
510 static inline uint16_t ToBig(uint16_t val) {
return val;}
511 static inline int32_t ToBig(int32_t val) {
return val;}
512 static inline uint32_t ToBig(uint32_t val) {
return val;}
513 static inline int64_t ToBig(int64_t val) {
return val;}
514 static inline uint64_t ToBig(uint64_t val) {
return val;}
521 template <>
struct hash<
HECL::ProjectPath>
Time getModtime() const
Get time of last modification with special behaviors for directories and glob-paths.
bool isRoot() const
Determine if ProjectPath represents project root directory.
Definition: HECL.hpp:334
FourCC representation used within HECL's database.
Definition: HECL.hpp:232
const std::string & getAbsolutePathUTF8() const
Access fully-canonicalized absolute path in UTF-8.
Definition: HECL.hpp:358
Timestamp representation used for comparing modtimes of cooked resources.
Definition: HECL.hpp:280
const SystemString & getRelativePath() const
Access fully-canonicalized project-relative path.
Definition: HECL.hpp:346
size_t hash() const
C++11 compatible runtime hash (NOT USED IN PACKAGES!!)
Definition: HECL.hpp:413
Special ProjectRootPath subclass for opening HECLDatabase::IProject instances.
Definition: HECL.hpp:425
PathType
Type of path.
Definition: HECL.hpp:379
const SystemString & getAbsolutePath() const
Access fully-canonicalized absolute path.
Definition: HECL.hpp:340
PathType getPathType() const
Get type of path based on syntax and filesystem queries.
void getGlobResults(std::vector< SystemString > &outPaths) const
Insert glob matches into existing vector.
Canonicalized project path representation using POSIX conventions.
Definition: HECL.hpp:310
Hash representation used for all storable and comparable objects.
Definition: HECL.hpp:257