20 #if defined(__unix__) && defined(__clang__)
31 #include <unordered_map>
35 #define CB_DLL_EXPORT __declspec(dllexport)
36 #define CB_DLL_IMPORT __declspec(dllimport)
43 #define FMT_HEADER_ONLY
45 #include <fmt/chrono.h>
46 #include <fmt/ranges.h>
48 #include <fmt/color.h>
50 #include <rapidjson/document.h>
51 #include <rapidjson/writer.h>
52 #include <rapidjson/reader.h>
53 #include <rapidjson/stringbuffer.h>
59 enum class _log_type {
all = 0, debug, warn, info, err };
63 static std::ostream& make_stream(
const char* file,
int line,
const _log_type& t) {
65 case _log_type::warn: {
66 std::cout <<
"[Warn] [" << file <<
"(" << line <<
", 0)"
70 case _log_type::err: {
71 std::cerr <<
"[Err] [" << file <<
"(" << line <<
", 0)"
75 case _log_type::debug: {
76 std::cout <<
"[Debug] [" << file <<
"(" << line <<
", 0)"
81 std::cout <<
"[Info] [" << file <<
"(" << line <<
", 0)"
89 #define LOG_INFO _log_stream::make_stream(__FILE__, __LINE__, _log_type::info)
90 #define LOG_ERR _log_stream::make_stream(__FILE__, __LINE__, _log_type::err)
91 #define LOG_WARN _log_stream::make_stream(__FILE__, __LINE__, _log_type::warn)
92 #define LOG_DEBUG _log_stream::make_stream(__FILE__, __LINE__, _log_type::debug)
93 #define LOG _log_stream::make_stream(__FILE__, __LINE__, _log_type::all)
96 inline std::ostream& operator,(std::ostream& out,
const T& t) {
101 inline std::ostream& operator,(std::ostream& out, std::ostream& (*f)(std::ostream&)) {
109 #define LOG_CHECK(x, ...) \
111 LOG_ERR << "Failed when testing " << #x << "\n"; \
112 std::cerr, __VA_ARGS__, std::endl; \
116 #define CHECK_LOWER_THAN(x, y, ...) LOG_CHECK((x) < (y), __VA_ARGS__)
117 #define CHECK_GREATER_THAN(x, y, ...) LOG_CHECK((x) > (y), __VA_ARGS__)
118 #define CHECK_EQUAL(x, y, ...) LOG_CHECK((x) == (y), __VA_ARGS__)
119 #define CHECK_LOWER_EQUAL(x, y, ...) LOG_CHECK((x) <= (y), __VA_ARGS__)
120 #define CHECK_GREATER_EQUAL(x, y, ...) LOG_CHECK((x) >= (y), __VA_ARGS__)
121 #define CHECK_NOT_EQUAL(x, y, ...) LOG_CHECK((x) != (y), __VA_ARGS__)
122 #define CHECK_NULL(x, ...) LOG_CHECK((x) != NULL, __VA_ARGS__)
125 #include <glog/logging.h>
127 #define LOG_INFO LOG(INFO)
128 #define LOG_ERR LOG(ERROR)
129 #define LOG_WARN LOG(WARN)
130 #define LOG_FATAL LOG(FATAL)
132 #define LOG_CHECK(x, ...) \
134 LOG_ERR << "Failed when testing " << #x << "\n"; \
135 std::cerr, __VA_ARGS__, std::endl; \
139 #define CHECK_LOWER_THAN(x, y, ...) LOG_CHECK((x) < (y), __VA_ARGS__)
140 #define CHECK_GREATER_THAN(x, y, ...) LOG_CHECK((x) > (y), __VA_ARGS__)
141 #define CHECK_EQUAL(x, y, ...) LOG_CHECK((x) == (y), __VA_ARGS__)
142 #define CHECK_LOWER_EQUAL(x, y, ...) LOG_CHECK((x) <= (y), __VA_ARGS__)
143 #define CHECK_GREATER_EQUAL(x, y, ...) LOG_CHECK((x) >= (y), __VA_ARGS__)
144 #define CHECK_NOT_EQUAL(x, y, ...) LOG_CHECK((x) != (y), __VA_ARGS__)
145 #define CHECK_NULL(x, ...) LOG_CHECK((x) != NULL, __VA_ARGS__)
157 #define CB_ALIGNED(x) __attribute__((aligned(x)))
161 #error "You can not predefine CB_INLINE. It's used in this lib."
163 #define CB_FORCE_INLINE inline __attribute__((always_inline))
164 #define CB_INLINE_CPU CB_FORCE_INLINE
165 #define CB_INLINE_NORMAL inline
168 #define CB_CONSTEXPR constexpr
170 #define CB_IS_NAN(func) std::isnan(func)
171 #define CB_IS_INF(func) std::isinf(func)
173 #define NO_TYPE_PTR void*
175 #define CB_SHAPE_ERROR_EXIT 1
176 #define CB_TYPE_ERROR_EXIT 2
177 #define CB_MEM_ERROR_EXIT 3
178 #define CB_OTHER_ERROR_EXIT 4
180 #define CB_USE_SOL true
182 #define MAKE_SHARED(x) std::make_shared<x>
183 #define SHARED_PTR(x) std::shared_ptr<x>
185 #endif //! __PCH_HPP_