2014-04-20 09:14:15 +00:00
|
|
|
#ifndef GLOBAL_HPP
|
|
|
|
#define GLOBAL_HPP
|
|
|
|
|
2015-07-08 02:53:39 +00:00
|
|
|
#include <iostream>
|
2014-04-20 09:14:15 +00:00
|
|
|
#include "Athena/Types.hpp"
|
|
|
|
#include "Athena/Utility.hpp"
|
|
|
|
|
2014-12-29 04:46:43 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable : 4996)
|
2015-06-20 04:40:15 +00:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
|
|
|
|
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
|
|
|
|
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(S_ISLNK)
|
|
|
|
#define S_ISLNK(m) 0
|
|
|
|
#endif
|
|
|
|
|
2015-11-14 23:59:10 +00:00
|
|
|
#define PRISize "Iu"
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define PRISize "zu"
|
|
|
|
|
2014-12-29 04:46:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef AT_PRETTY_FUNCTION
|
2015-05-04 03:57:00 +00:00
|
|
|
# if defined(__PRETTY_FUNCTION__) || defined(__GNUC__)
|
2014-12-29 04:46:43 +00:00
|
|
|
# define AT_PRETTY_FUNCTION __PRETTY_FUNCTION__
|
|
|
|
# elif defined(__FUNCSIG__)
|
|
|
|
# define AT_PRETTY_FUNCTION __FUNCSIG__
|
2014-06-03 03:09:40 +00:00
|
|
|
# elif defined(__FUNCTION__)
|
2014-12-29 04:46:43 +00:00
|
|
|
# define AT_PRETTY_FUNCTION __FUNCTION__
|
2014-06-03 03:09:40 +00:00
|
|
|
# elif defined(__FUNC__)
|
2014-12-29 04:46:43 +00:00
|
|
|
# define AT_PRETTY_FUNCTION __FUNC__
|
2014-06-03 03:09:40 +00:00
|
|
|
# elif defined(__func__)
|
2014-12-29 04:46:43 +00:00
|
|
|
# define AT_PRETTY_FUNCTION __func__
|
2014-06-03 03:09:40 +00:00
|
|
|
# else
|
2014-12-29 04:46:43 +00:00
|
|
|
# define AT_PRETTY_FUNCTION "<unknown>"
|
2014-06-03 03:09:40 +00:00
|
|
|
# endif
|
2014-05-15 05:42:20 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-21 04:57:27 +00:00
|
|
|
|
|
|
|
#ifdef GEKKO
|
|
|
|
#include "gekko_support.h"
|
|
|
|
typedef struct stat stat64_t;
|
|
|
|
#define stat64 stat
|
2015-06-20 04:40:15 +00:00
|
|
|
#elif _WIN32
|
|
|
|
typedef struct _stat64 stat64_t;
|
2015-09-12 18:25:58 +00:00
|
|
|
#elif __FreeBSD__
|
|
|
|
typedef struct stat stat64_t;
|
|
|
|
#define stat64 stat
|
|
|
|
#define fseeko64 fseeko
|
|
|
|
#define ftello64 ftello
|
2015-05-21 04:57:27 +00:00
|
|
|
#else
|
|
|
|
typedef struct stat64 stat64_t;
|
|
|
|
#endif
|
|
|
|
|
2014-04-20 09:14:15 +00:00
|
|
|
#ifndef BLOCKSZ
|
|
|
|
#define BLOCKSZ 512
|
|
|
|
#endif
|
|
|
|
|
2015-04-11 00:04:13 +00:00
|
|
|
#define ROUND_UP_32(val) (((val) + 31) & ~31)
|
|
|
|
#define ROUND_UP_16(val) (((val) + 15) & ~15)
|
|
|
|
|
2015-11-22 04:20:15 +00:00
|
|
|
#ifndef ENABLE_BITWISE_ENUM
|
2015-11-21 01:11:23 +00:00
|
|
|
#define ENABLE_BITWISE_ENUM(type)\
|
|
|
|
inline type operator|(type a, type b)\
|
|
|
|
{\
|
|
|
|
using T = std::underlying_type_t<type>;\
|
|
|
|
return type(static_cast<T>(a) | static_cast<T>(b));\
|
|
|
|
}\
|
|
|
|
inline type operator&(type a, type b)\
|
|
|
|
{\
|
|
|
|
using T = std::underlying_type_t<type>;\
|
|
|
|
return type(static_cast<T>(a) & static_cast<T>(b));\
|
|
|
|
}\
|
|
|
|
inline type& operator|=(type& a, const type& b)\
|
|
|
|
{\
|
|
|
|
using T = std::underlying_type_t<type>;\
|
|
|
|
a = type(static_cast<T>(a) | static_cast<T>(b));\
|
|
|
|
return a;\
|
|
|
|
}\
|
|
|
|
inline type& operator&=(type& a, const type& b)\
|
|
|
|
{\
|
|
|
|
using T = std::underlying_type_t<type>;\
|
|
|
|
a = type(static_cast<T>(a) & static_cast<T>(b));\
|
|
|
|
return a;\
|
|
|
|
}\
|
|
|
|
inline type operator~(const type& key)\
|
|
|
|
{\
|
|
|
|
using T = std::underlying_type_t<type>;\
|
|
|
|
return type(~static_cast<T>(key));\
|
|
|
|
}
|
2015-11-22 04:20:15 +00:00
|
|
|
#endif
|
2015-11-21 01:11:23 +00:00
|
|
|
|
2014-04-20 09:14:15 +00:00
|
|
|
namespace Athena
|
|
|
|
{
|
2015-07-22 05:37:22 +00:00
|
|
|
namespace error
|
|
|
|
{
|
2015-11-23 03:08:48 +00:00
|
|
|
enum class Level
|
2015-07-22 05:37:22 +00:00
|
|
|
{
|
2015-11-23 03:08:48 +00:00
|
|
|
Message,
|
|
|
|
Warning,
|
|
|
|
Error,
|
|
|
|
Fatal
|
2015-07-22 05:37:22 +00:00
|
|
|
};
|
|
|
|
}
|
2015-06-16 02:29:53 +00:00
|
|
|
enum SeekOrigin
|
2014-04-20 09:14:15 +00:00
|
|
|
{
|
|
|
|
Begin,
|
|
|
|
Current,
|
|
|
|
End
|
|
|
|
};
|
|
|
|
|
2015-06-16 02:29:53 +00:00
|
|
|
enum Endian
|
2014-04-20 09:14:15 +00:00
|
|
|
{
|
|
|
|
LittleEndian,
|
|
|
|
BigEndian
|
|
|
|
};
|
|
|
|
} // Athena
|
|
|
|
|
2015-11-23 03:08:48 +00:00
|
|
|
typedef void (*atEXCEPTION_HANDLER)(Athena::error::Level level, const char* file, const char* function, int line, const char* fmt, ...);
|
2015-05-18 23:28:17 +00:00
|
|
|
|
|
|
|
atEXCEPTION_HANDLER atGetExceptionHandler();
|
|
|
|
void atSetExceptionHandler(atEXCEPTION_HANDLER func);
|
|
|
|
|
2014-04-20 09:14:15 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Athena::SeekOrigin& origin);
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Athena::Endian& endian);
|
2015-07-22 05:37:22 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#define atDebug(fmt, ...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-30 05:07:00 +00:00
|
|
|
__handler(Athena::error::LevelMessage, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
#define atDebug(fmt, ...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define atMessage(fmt, ...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-30 05:07:00 +00:00
|
|
|
__handler(Athena::error::LevelMessage, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define atWarning(fmt, ...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-30 05:07:00 +00:00
|
|
|
__handler(Athena::error::LevelWarning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define atError(fmt, ...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-30 05:07:00 +00:00
|
|
|
__handler(Athena::error::LevelError, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define atFatal(fmt, ...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-30 05:07:00 +00:00
|
|
|
__handler(Athena::error::LevelFatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt, ##__VA_ARGS__); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#define atDebug(fmt...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-31 05:15:06 +00:00
|
|
|
__handler(Athena::error::LevelMessage, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
#else // _MSC_VER
|
|
|
|
#define atDebug(fmt, ...)
|
|
|
|
#endif // NDEBUG
|
|
|
|
|
|
|
|
#define atMessage(fmt...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-11-23 03:08:48 +00:00
|
|
|
__handler(Athena::error::Level::Message, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define atWarning(fmt...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-11-23 03:08:48 +00:00
|
|
|
__handler(Athena::error::Level::Warning, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define atError(fmt...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-11-23 03:08:48 +00:00
|
|
|
__handler(Athena::error::Level::Error, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define atFatal(fmt...) \
|
|
|
|
do { atEXCEPTION_HANDLER __handler = atGetExceptionHandler(); \
|
|
|
|
if (__handler) \
|
2015-08-30 05:07:00 +00:00
|
|
|
__handler(Athena::error::LevelFatal, __FILE__, AT_PRETTY_FUNCTION, __LINE__, fmt); \
|
2015-07-22 05:37:22 +00:00
|
|
|
} while(0)
|
|
|
|
#endif // defined(__GNUC__)
|
|
|
|
|
2014-04-20 09:14:15 +00:00
|
|
|
#endif // GLOBAL_HPP
|