| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef DMLC_BASE_H_ |
| 7 |
#define DMLC_BASE_H_ |
| 8 |
|
| 9 |
|
| 10 |
#ifndef DMLC_USE_GLOG |
| 11 |
#define DMLC_USE_GLOG 0 |
| 12 |
#endif |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#ifndef DMLC_LOG_FATAL_THROW |
| 34 |
#define DMLC_LOG_FATAL_THROW 1 |
| 35 |
#endif |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#ifndef DMLC_LOG_BEFORE_THROW |
| 42 |
#define DMLC_LOG_BEFORE_THROW 0 |
| 43 |
#endif |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#ifndef DMLC_LOG_CUSTOMIZE |
| 50 |
#define DMLC_LOG_CUSTOMIZE 0 |
| 51 |
#endif |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#ifndef DMLC_LOG_DEBUG |
| 57 |
#ifdef NDEBUG |
| 58 |
#define DMLC_LOG_DEBUG 0 |
| 59 |
#else |
| 60 |
#define DMLC_LOG_DEBUG 1 |
| 61 |
#endif |
| 62 |
#endif |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
#ifndef DMLC_LOG_NODATE |
| 68 |
#define DMLC_LOG_NODATE 0 |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
#ifndef DMLC_USE_HDFS |
| 73 |
#define DMLC_USE_HDFS 0 |
| 74 |
#endif |
| 75 |
|
| 76 |
|
| 77 |
#ifndef DMLC_USE_S3 |
| 78 |
#define DMLC_USE_S3 0 |
| 79 |
#endif |
| 80 |
|
| 81 |
|
| 82 |
#ifndef DMLC_USE_PS |
| 83 |
#define DMLC_USE_PS 0 |
| 84 |
#endif |
| 85 |
|
| 86 |
|
| 87 |
#ifndef DMLC_USE_CXX11 |
| 88 |
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER) |
| 89 |
#define DMLC_USE_CXX11 1 |
| 90 |
#else |
| 91 |
#define DMLC_USE_CXX11 (__cplusplus >= 201103L) |
| 92 |
#endif |
| 93 |
#endif |
| 94 |
|
| 95 |
|
| 96 |
#ifndef DMLC_STRICT_CXX11 |
| 97 |
#if defined(_MSC_VER) |
| 98 |
#define DMLC_STRICT_CXX11 1 |
| 99 |
#else |
| 100 |
#define DMLC_STRICT_CXX11 (__cplusplus >= 201103L) |
| 101 |
#endif |
| 102 |
#endif |
| 103 |
|
| 104 |
|
| 105 |
#ifndef DMLC_CXX11_THREAD_LOCAL |
| 106 |
#if defined(_MSC_VER) |
| 107 |
#define DMLC_CXX11_THREAD_LOCAL (_MSC_VER >= 1900) |
| 108 |
#elif defined(__clang__) |
| 109 |
#define DMLC_CXX11_THREAD_LOCAL (__has_feature(cxx_thread_local)) |
| 110 |
#else |
| 111 |
#define DMLC_CXX11_THREAD_LOCAL (__cplusplus >= 201103L) |
| 112 |
#endif |
| 113 |
#endif |
| 114 |
|
| 115 |
|
| 116 |
#ifndef DMLC_MODERN_THREAD_LOCAL |
| 117 |
#define DMLC_MODERN_THREAD_LOCAL 1 |
| 118 |
#endif |
| 119 |
|
| 120 |
|
| 121 |
#ifndef DMLC_ENABLE_RTTI |
| 122 |
#define DMLC_ENABLE_RTTI 1 |
| 123 |
#endif |
| 124 |
|
| 125 |
|
| 126 |
#ifndef DMLC_USE_FOPEN64 |
| 127 |
#define DMLC_USE_FOPEN64 1 |
| 128 |
#endif |
| 129 |
|
| 130 |
|
| 131 |
#if DMLC_USE_CXX11 |
| 132 |
#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1900) |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
#pragma message("Compiling without c++11, some features may be disabled") |
| 137 |
#undef DMLC_USE_CXX11 |
| 138 |
#define DMLC_USE_CXX11 0 |
| 139 |
|
| 140 |
#endif |
| 141 |
#endif |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
#ifndef DMLC_IO_USE_LITTLE_ENDIAN |
| 148 |
#define DMLC_IO_USE_LITTLE_ENDIAN 1 |
| 149 |
#endif |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
#ifndef DMLC_ENABLE_STD_THREAD |
| 156 |
#define DMLC_ENABLE_STD_THREAD DMLC_USE_CXX11 |
| 157 |
#endif |
| 158 |
|
| 159 |
|
| 160 |
#ifndef DMLC_USE_REGEX |
| 161 |
#define DMLC_USE_REGEX DMLC_STRICT_CXX11 |
| 162 |
#endif |
| 163 |
|
| 164 |
|
| 165 |
#if defined(__GNUC__) |
| 166 |
#define DMLC_ATTRIBUTE_UNUSED __attribute__((unused)) |
| 167 |
#else |
| 168 |
#define DMLC_ATTRIBUTE_UNUSED |
| 169 |
#endif |
| 170 |
|
| 171 |
|
| 172 |
#if defined(__clang__) |
| 173 |
#define DMLC_SUPPRESS_UBSAN __attribute__((no_sanitize("undefined"))) |
| 174 |
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409) |
| 175 |
#define DMLC_SUPPRESS_UBSAN __attribute__((no_sanitize_undefined)) |
| 176 |
#else |
| 177 |
#define DMLC_SUPPRESS_UBSAN |
| 178 |
#endif |
| 179 |
|
| 180 |
|
| 181 |
#define DMLC_STR_CONCAT_(__x, __y) __x##__y |
| 182 |
#define DMLC_STR_CONCAT(__x, __y) DMLC_STR_CONCAT_(__x, __y) |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
#ifndef DISALLOW_COPY_AND_ASSIGN |
| 193 |
#if DMLC_USE_CXX11 |
| 194 |
#define DISALLOW_COPY_AND_ASSIGN(T) \ |
| 195 |
T(T const &) = delete; \ |
| 196 |
T(T &&) = delete; \ |
| 197 |
T &operator=(T const &) = delete; \ |
| 198 |
T &operator=(T &&) = delete |
| 199 |
#else |
| 200 |
#define DISALLOW_COPY_AND_ASSIGN(T) \ |
| 201 |
T(T const &); \ |
| 202 |
T &operator=(T const &) |
| 203 |
#endif |
| 204 |
#endif |
| 205 |
|
| 206 |
#ifdef __APPLE__ |
| 207 |
#define off64_t off_t |
| 208 |
#endif |
| 209 |
|
| 210 |
#ifdef _MSC_VER |
| 211 |
#if _MSC_VER < 1900 |
| 212 |
|
| 213 |
|
| 214 |
#define snprintf sprintf_s |
| 215 |
#define vsnprintf vsprintf_s |
| 216 |
#endif |
| 217 |
#else |
| 218 |
#ifdef _FILE_OFFSET_BITS |
| 219 |
#if _FILE_OFFSET_BITS == 32 |
| 220 |
#pragma message("Warning: FILE OFFSET BITS defined to be 32 bit") |
| 221 |
#endif |
| 222 |
#endif |
| 223 |
|
| 224 |
extern "C" { |
| 225 |
#include <sys/types.h> |
| 226 |
} |
| 227 |
#endif |
| 228 |
|
| 229 |
#ifdef _MSC_VER |
| 230 |
|
| 231 |
typedef signed char int8_t; |
| 232 |
typedef __int16 int16_t; |
| 233 |
typedef __int32 int32_t; |
| 234 |
typedef __int64 int64_t; |
| 235 |
typedef unsigned char uint8_t; |
| 236 |
typedef unsigned __int16 uint16_t; |
| 237 |
typedef unsigned __int32 uint32_t; |
| 238 |
typedef unsigned __int64 uint64_t; |
| 239 |
|
| 240 |
#else |
| 241 |
#include <inttypes.h> |
| 242 |
#endif |
| 243 |
#include <string> |
| 244 |
#include <vector> |
| 245 |
|
| 246 |
#if defined(_MSC_VER) && _MSC_VER < 1900 |
| 247 |
#define noexcept_true throw() |
| 248 |
#define noexcept_false |
| 249 |
#define noexcept(a) noexcept_##a |
| 250 |
#endif |
| 251 |
|
| 252 |
#if defined(_MSC_VER) |
| 253 |
#define DMLC_NO_INLINE __declspec(noinline) |
| 254 |
#else |
| 255 |
#define DMLC_NO_INLINE __attribute__((noinline)) |
| 256 |
#endif |
| 257 |
|
| 258 |
#if defined(__GNUC__) || defined(__clang__) |
| 259 |
#define DMLC_ALWAYS_INLINE inline __attribute__((__always_inline__)) |
| 260 |
#elif defined(_MSC_VER) |
| 261 |
#define DMLC_ALWAYS_INLINE __forceinline |
| 262 |
#else |
| 263 |
#define DMLC_ALWAYS_INLINE inline |
| 264 |
#endif |
| 265 |
|
| 266 |
#if DMLC_USE_CXX11 |
| 267 |
#define DMLC_THROW_EXCEPTION noexcept(false) |
| 268 |
#define DMLC_NO_EXCEPTION noexcept(true) |
| 269 |
#else |
| 270 |
#define DMLC_THROW_EXCEPTION |
| 271 |
#define DMLC_NO_EXCEPTION |
| 272 |
#endif |
| 273 |
|
| 274 |
|
| 275 |
namespace dmlc { |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
template <typename T> |
| 282 |
inline T *BeginPtr(std::vector<T> &vec) { |
| 283 |
if (vec.size() == 0) { |
| 284 |
return NULL; |
| 285 |
} else { |
| 286 |
return &vec[0]; |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
template <typename T> |
| 295 |
inline const T *BeginPtr(const std::vector<T> &vec) { |
| 296 |
if (vec.size() == 0) { |
| 297 |
return NULL; |
| 298 |
} else { |
| 299 |
return &vec[0]; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
inline char *BeginPtr(std::string &str) { |
| 308 |
if (str.length() == 0) { |
| 309 |
return NULL; |
| 310 |
} |
| 311 |
return &str[0]; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
inline const char *BeginPtr(const std::string &str) { |
| 319 |
if (str.length() == 0) { |
| 320 |
return NULL; |
| 321 |
} |
| 322 |
return &str[0]; |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
#if defined(_MSC_VER) && _MSC_VER < 1900 |
| 327 |
#define constexpr const |
| 328 |
#define alignof __alignof |
| 329 |
#endif |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
#ifdef DMLC_CORE_USE_CMAKE |
| 336 |
#include <dmlc/build_config.h> |
| 337 |
#else |
| 338 |
#include <dmlc/build_config_default.h> |
| 339 |
#endif |
| 340 |
|
| 341 |
#endif |