2020-04-14 14:36:54 +00:00
|
|
|
#ifndef PKMNLIB_CORE_HPP
|
|
|
|
#define PKMNLIB_CORE_HPP
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <exception>
|
|
|
|
#include <string>
|
2020-08-04 16:33:27 +00:00
|
|
|
#define export extern "C" [[maybe_unused]]
|
2020-04-14 14:36:54 +00:00
|
|
|
|
2020-07-30 18:06:41 +00:00
|
|
|
#define PkmnLibException 4
|
2020-04-14 14:36:54 +00:00
|
|
|
|
|
|
|
class ExceptionHandler {
|
2020-07-30 18:06:41 +00:00
|
|
|
static std::string _pkmnLibLastException;
|
2020-04-14 14:36:54 +00:00
|
|
|
|
|
|
|
public:
|
2020-07-30 18:06:41 +00:00
|
|
|
static void SetLastException(const std::exception& e) { _pkmnLibLastException = std::string(e.what()); }
|
|
|
|
static const char* GetLastException() { return _pkmnLibLastException.c_str(); }
|
2020-04-14 14:36:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define Try(data) \
|
|
|
|
try { \
|
|
|
|
data; \
|
|
|
|
return 0; \
|
|
|
|
} catch (const std::exception& e) { \
|
|
|
|
ExceptionHandler::SetLastException(e); \
|
2020-04-28 12:48:56 +00:00
|
|
|
return PkmnLibException; \
|
2020-04-14 14:36:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 13:54:25 +00:00
|
|
|
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
|
|
|
export returnType PkmnLib_##type##_##name(const type* p) { return p->name(); }
|
|
|
|
#define SIMPLE_GET_FUNC_SMART_PTR(type, name, returnType) \
|
|
|
|
export returnType PkmnLib_##type##_##name(const type* p) { return p->name().GetRaw(); }
|
2020-08-11 17:36:18 +00:00
|
|
|
#define DESTRUCTOR(type) \
|
|
|
|
export void PkmnLib_##type##_Destruct(const type* p) { delete p; }
|
2020-07-07 13:54:25 +00:00
|
|
|
|
2020-04-14 14:36:54 +00:00
|
|
|
#endif // PKMNLIB_CORE_HPP
|