Covalent Bond  0.0.1-alpha
'covalent bond' is a data middle office. As a 2022-2023 Fall SWE final project.
pch.hpp
Go to the documentation of this file.
1 
11 #ifndef __PCH_HPP_
12 #define __PCH_HPP_
13 
14 #ifdef _WIN32
15 #if _MSC_VER > 1000
16 #pragma once
17 #endif
18 #endif
19 
20 #if defined(__unix__) && defined(__clang__)
21 #pragma once
22 #endif
23 
24 #include <iostream>
25 #include <string>
26 #include <cmath>
27 #include <sstream>
28 #include <fstream>
29 #include <vector>
30 #include <cstdint>
31 #include <unordered_map>
32 #include <functional>
33 
34 #ifdef _WIN32
35 #define CB_DLL_EXPORT __declspec(dllexport)
36 #define CB_DLL_IMPORT __declspec(dllimport)
37 #endif
38 #ifdef __unix__
39 #define CB_DLL_EXPORT
40 #define CB_DLL_IMPORT
41 #endif
42 
43 #define FMT_HEADER_ONLY
44 #include <fmt/core.h>
45 #include <fmt/chrono.h>
46 #include <fmt/ranges.h>
47 #include <fmt/os.h>
48 #include <fmt/color.h>
49 
50 #include <rapidjson/document.h>
51 #include <rapidjson/writer.h>
52 #include <rapidjson/reader.h>
53 #include <rapidjson/stringbuffer.h>
54 
55 // log system used is Google log
56 #define CB_GLOG 1
57 
58 #if CB_GLOG == 0
59 enum class _log_type { all = 0, debug, warn, info, err };
60 
61 class _log_stream {
62  public:
63  static std::ostream& make_stream(const char* file, int line, const _log_type& t) {
64  switch (t) {
65  case _log_type::warn: {
66  std::cout << "[Warn] [" << file << "(" << line << ", 0)"
67  << "] ";
68  return std::cout;
69  }
70  case _log_type::err: {
71  std::cerr << "[Err] [" << file << "(" << line << ", 0)"
72  << "] ";
73  return std::cerr;
74  }
75  case _log_type::debug: {
76  std::cout << "[Debug] [" << file << "(" << line << ", 0)"
77  << "] ";
78  return std::cout;
79  }
80  default: {
81  std::cout << "[Info] [" << file << "(" << line << ", 0)"
82  << "] ";
83  return std::cout;
84  }
85  }
86  }
87 };
88 
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)
94 
95 template<typename T>
96 inline std::ostream& operator,(std::ostream& out, const T& t) {
97  out << t;
98  return out;
99 }
100 
101 inline std::ostream& operator,(std::ostream& out, std::ostream& (*f)(std::ostream&)) {
102  out << f;
103  return out;
104 }
105 
109 #define LOG_CHECK(x, ...) \
110  if (!(x)) { \
111  LOG_ERR << "Failed when testing " << #x << "\n"; \
112  std::cerr, __VA_ARGS__, std::endl; \
113  std::exit(1); \
114  }
115 
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__)
123 
124 #else
125 #include <glog/logging.h>
126 
127 #define LOG_INFO LOG(INFO)
128 #define LOG_ERR LOG(ERROR)
129 #define LOG_WARN LOG(WARN)
130 #define LOG_FATAL LOG(FATAL)
131 
132 #define LOG_CHECK(x, ...) \
133  if (!(x)) { \
134  LOG_ERR << "Failed when testing " << #x << "\n"; \
135  std::cerr, __VA_ARGS__, std::endl; \
136  std::exit(1); \
137  }
138 
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__)
146 
147 #endif
148 
149 
157 #define CB_ALIGNED(x) __attribute__((aligned(x)))
158 
159 // inline symbol for template code used in both gpu and cpu
160 #ifdef CB_INLINE
161 #error "You can not predefine CB_INLINE. It's used in this lib."
162 #endif
163 #define CB_FORCE_INLINE inline __attribute__((always_inline))
164 #define CB_INLINE_CPU CB_FORCE_INLINE
165 #define CB_INLINE_NORMAL inline
166 
167 // defined the const exp
168 #define CB_CONSTEXPR constexpr
169 
170 #define CB_IS_NAN(func) std::isnan(func)
171 #define CB_IS_INF(func) std::isinf(func)
172 
173 #define NO_TYPE_PTR void*
174 
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
179 
180 #define CB_USE_SOL true
181 
182 #define MAKE_SHARED(x) std::make_shared<x>
183 #define SHARED_PTR(x) std::shared_ptr<x>
184 
185 #endif //! __PCH_HPP_
cbTableSlice::all
@ all