2020-03-25 18:07:36 +00:00
|
|
|
#ifndef CREATURELIB_CORE_HPP
|
|
|
|
#define CREATURELIB_CORE_HPP
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <exception>
|
2020-07-26 15:22:36 +00:00
|
|
|
#include <sstream>
|
2020-03-25 18:07:36 +00:00
|
|
|
#include <string>
|
2020-07-24 08:14:10 +00:00
|
|
|
#define export extern "C" [[maybe_unused]]
|
2020-03-25 18:07:36 +00:00
|
|
|
|
2020-07-31 08:51:03 +00:00
|
|
|
#define CreatureLibException 2;
|
2020-07-26 15:22:36 +00:00
|
|
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
2020-04-14 13:43:30 +00:00
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
class ExceptionHandler {
|
2020-07-28 17:37:03 +00:00
|
|
|
static std::string _creatureLibLastException;
|
2020-03-25 18:07:36 +00:00
|
|
|
|
|
|
|
public:
|
2020-07-26 15:29:06 +00:00
|
|
|
static void SetLastException(std::string function, const std::exception& e) {
|
2020-07-26 15:22:36 +00:00
|
|
|
std::stringstream ss;
|
2020-07-26 15:29:06 +00:00
|
|
|
ss << "[" << function << "] " << e.what();
|
2020-07-28 17:37:03 +00:00
|
|
|
_creatureLibLastException = ss.str();
|
2020-07-26 15:22:36 +00:00
|
|
|
}
|
2020-07-28 17:37:03 +00:00
|
|
|
static const char* GetLastException() { return _creatureLibLastException.c_str(); }
|
2020-03-25 18:07:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define Try(data) \
|
|
|
|
try { \
|
|
|
|
data; \
|
|
|
|
return 0; \
|
|
|
|
} catch (const std::exception& e) { \
|
2020-07-26 15:29:06 +00:00
|
|
|
ExceptionHandler::SetLastException(__FUNCTION__, e); \
|
2020-07-31 08:51:03 +00:00
|
|
|
return CreatureLibException; \
|
2020-03-25 18:07:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 13:33:43 +00:00
|
|
|
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
|
|
|
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
|
|
|
|
#define BORROWED_GET_FUNC(type, name, returnType) \
|
|
|
|
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().GetRaw(); }
|
|
|
|
#define SMART_GET_FUNC(type, name, returnType) \
|
|
|
|
export returnType CreatureLib_##type##_##name(const type* p) { return p->name().get(); }
|
2020-08-07 09:51:43 +00:00
|
|
|
#define DESTRUCTOR(type) \
|
|
|
|
export void CreatureLib_##type##_Destruct(const type* p) { delete p; }
|
2020-07-07 13:33:43 +00:00
|
|
|
|
2020-03-25 18:07:36 +00:00
|
|
|
#endif // CREATURELIB_CORE_HPP
|