nlib
Config.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_CONFIG_H_
4 #define INCLUDE_NN_NLIB_CONFIG_H_
5 
6 // NOTE:
7 // DO NOT INCLUDE THE STANDARD C/C++ LIBRARY HEADERS
8 // on the line always included in this header.
9 // This would make it difficult to avoid compile errors
10 // on the environment which lacks the standard headers.
11 
12 #include "nn/nlib/Platform.h"
13 
14 #ifndef NLIB_NAMESPACE_BEGIN
15 #define NLIB_NAMESPACE_BEGIN namespace nn { namespace nlib {
16 #endif
17 
18 #ifndef NLIB_NAMESPACE_END
19 #define NLIB_NAMESPACE_END }}
20 #endif
21 
22 #ifndef NLIB_NS
23 #define NLIB_NS ::nn::nlib
24 #endif
25 
26 NLIB_NAMESPACE_BEGIN
27 NLIB_NAMESPACE_END
28 namespace nlib_ns = NLIB_NS;
29 
30 #if defined(CAFE)
31 # include "nn/nlib/Config_cafe.h" // NOLINT
32 #elif defined(NN_PLATFORM_CTR)
33 # include "nn/nlib/Config_ctr.h" // NOLINT
34 #elif defined(_MSC_VER)
35 # include "nn/nlib/Config_win32.h" // NOLINT
36 #elif defined(__CYGWIN__)
37 # include "nn/nlib/Config_cygwin.h" // NOLINT
38 #elif defined(__linux__)
39 # include "nn/nlib/Config_linux.h" // NOLINT
40 #elif defined(__FreeBSD__)
41 # include "nn/nlib/Config_freebsd.h" // NOLINT
42 #elif defined(__APPLE__) && defined(__MACH__)
43 # include "nn/nlib/Config_osx.h" // NOLINT
44 #endif
45 
46 #ifdef NLIB_CXX11_STDLIB_ATOMIC
47 // NOTE: redefine them to use std C++ library for memory barrier
48 # undef NLIB_MEMORY_ORDER_RELEASE
49 # undef NLIB_MEMORY_ORDER_ACQUIRE
50 # undef NLIB_MEMORY_ORDER_ACQ_REL
51 # include <atomic> // NOLINT
52 # define NLIB_MEMORY_ORDER_RELEASE ::std::atomic_thread_fence(::std::memory_order_release)
53 # define NLIB_MEMORY_ORDER_ACQUIRE ::std::atomic_thread_fence(::std::memory_order_acquire)
54 # define NLIB_MEMORY_ORDER_ACQ_REL ::std::atomic_thread_fence(::std::memory_order_acq_rel)
55 #endif
56 
57 #ifdef NLIB_CXX11_RVALUE_REFERENCES
58 # define NLIB_RREF &&
59 # define NLIB_FWD(T, v) std::forward<T>(v)
60 # define NLIB_MOVE(x) std::move(x)
61 #else
62 # define NLIB_RREF &
63 # define NLIB_FWD(T, v) (v)
64 # define NLIB_MOVE(x) (x)
65 #endif
66 
67 #ifdef NLIB_CXX11_CONSTEXPR
68 # define NLIB_CEXPR constexpr
69 #else
70 # define NLIB_CEXPR
71 #endif
72 
73 #ifndef NLIB_NOEXCEPT
74 # define NLIB_NOEXCEPT
75 #endif
76 
77 struct nlib_unwind_exception {}; // Do not throw this directly
78 #ifndef NLIB_RETHROW_UNWIND
79 # define NLIB_RETHROW_UNWIND catch (nlib_unwind_exception&)
80 #endif
81 
82 #ifndef NLIB_ASSERT_NOERR
83 # define NLIB_ASSERT_NOERR(e) NLIB_ASSERT((e) == 0)
84 #endif
85 
86 #ifdef NLIB_EXCEPTION_ENABLED
87 # define NLIB_TRY try
88 # define NLIB_CATCH(x) catch(x)
89 # define NLIB_THROW throw
90 #else
91 # define NLIB_TRY if (true)
92 # define NLIB_CATCH(x) if (false)
93 # define NLIB_THROW
94 #endif
95 
96 #ifndef NLIB_STATIC_ASSERT
97 #ifndef NLIB_CXX11_STATIC_ASSERTIONS
98 NLIB_NAMESPACE_BEGIN
99 namespace detail {
100 template <bool>
101 struct STATIC_ASSERTION_FAILURE;
102 template <>
103 struct STATIC_ASSERTION_FAILURE<true> {};
104 template <int x>
105 struct static_assert_test {};
106 } // namespace detail
107 NLIB_NAMESPACE_END
108 
109 #define NLIB_ASSERT_H_STRING_JOIN_(X, Y) NLIB_ASSERT_H_STRING_JOIN1_(X, Y)
110 #define NLIB_ASSERT_H_STRING_JOIN1_(X, Y) X##Y
111 
112 #define NLIB_STATIC_ASSERT(exp) \
113  typedef ::nlib_ns::detail::static_assert_test< \
114  sizeof(::nlib_ns::detail::STATIC_ASSERTION_FAILURE<(exp) != 0>)> \
115  NLIB_ASSERT_H_STRING_JOIN_(nn_static_assert_typedef_, __LINE__)
116 #else
117 # define NLIB_STATIC_ASSERT(exp) static_assert((exp), "NLIB_STATIC_ASSERT error: " #exp)
118 #endif
119 #endif
120 
121 #ifndef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
122 #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
123 TypeName(const TypeName&); \
124 void operator=(const TypeName&)
125 #else
126 #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
127 TypeName(const TypeName&) = delete; \
128 void operator=(const TypeName&) = delete
129 #endif
130 
131 #ifndef NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS
132 #define NLIB_SAFE_BOOL(class_name, exp) \
133 private: \
134  typedef void (class_name::*bool_type)() const; \
135  void this_type_does_not_support_comparisons() const NLIB_NOEXCEPT {} \
136 public: \
137  operator bool_type() const NLIB_NOEXCEPT { \
138  return (exp) ? &class_name::this_type_does_not_support_comparisons : 0; \
139  }
140 #else
141 #define NLIB_SAFE_BOOL(class_name, exp) \
142 public: \
143  explicit NLIB_ALWAYS_INLINE operator bool() const NLIB_NOEXCEPT { return (exp); }
144 #endif
145 
146 #include <wchar.h> // NOLINT
147 #if defined(WCHAR_MIN) && defined(WCHAR_MAX)
148 # if WCHAR_MAX <= 0xFFFF
149 # define NLIB_WCHAR_SIZE (2)
150 NLIB_STATIC_ASSERT(sizeof(wchar_t) == 2);
151 # else
152 # define NLIB_WCHAR_SIZE (4)
153 NLIB_STATIC_ASSERT(sizeof(wchar_t) == 4);
154 # endif
155 #else
156 # error WCHAR_MIN, WCHAR_MAX not defined
157 #endif
158 
159 // nlib_ns::utf16_t, nlib_ns::utf32_t might be deprecated in the future
160 // use nlib_utf16_t, nlib_utf32_t instead
161 NLIB_NAMESPACE_BEGIN
164 NLIB_NAMESPACE_END
165 
166 #ifndef NLIB_CXX11_NULL_POINTER_CONSTANT
167 NLIB_NAMESPACE_BEGIN
168 class nullptr_t {
169  public:
170  template <class T>
171  operator T*() const {
172  return 0;
173  }
174  template <class C, class T>
175  operator T C::*() const {
176  return 0;
177  }
178 
179  private:
180  void operator&() const; // NOLINT
181 };
182 #ifndef nullptr
183 // if nullptr macro is defined, just use it.
184 const nullptr_t nullptr = {};
185 #endif
186 NLIB_NAMESPACE_END
187 #else
188 #include <cstddef> // NOLINT this is because stddef.h does not define std::nullptr_t
189 NLIB_NAMESPACE_BEGIN
190 typedef std::nullptr_t nullptr_t;
191 NLIB_NAMESPACE_END
192 #endif
193 
194 #ifndef NLIB_CXX11_EXPLICIT_VIRTUAL_OVERRIDES
195 # define NLIB_OVERRIDE
196 # define NLIB_FINAL
197 #else
198 # define NLIB_OVERRIDE override
199 # define NLIB_FINAL final
200 #endif
201 
202 #ifdef NLIB_CXX11_ALIGNMENT_SUPPORT
203 # ifdef NLIB_ALIGNAS
204 # undef NLIB_ALIGNAS
205 # endif
206 # ifdef NLIB_ALIGNOF
207 # undef NLIB_ALIGNOF
208 # endif
209 # define NLIB_ALIGNAS(x) alignas(x)
210 # define NLIB_ALIGNOF(tp) alignof(tp)
211 #endif
212 
213 #ifdef NLIB_CXX11_RVALUE_REFERENCES
214 // for std::move
215 # include <utility> // NOLINT
216 #endif
217 
218 NLIB_NAMESPACE_BEGIN
219 struct move_tag {};
220 NLIB_NAMESPACE_END
221 
222 #define NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
223  NLIB_ALWAYS_INLINE \
224  tp& assign(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT { /* NOLINT */ \
225  tp().swap(*this); \
226  this->swap(rhs); \
227  return *this; \
228  }
229 
230 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_1(tp, mem1) \
231  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
232  NLIB_ALWAYS_INLINE \
233  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : mem1() /* NOLINT */ \
234  { \
235  this->swap(rhs); \
236  }
237 
238 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_2(tp, mem1, mem2) \
239  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
240  NLIB_ALWAYS_INLINE \
241  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : mem1(), /* NOLINT */ \
242  mem2() \
243  { \
244  this->swap(rhs); \
245  }
246 
247 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_3(tp, mem1, mem2, mem3) \
248  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
249  NLIB_ALWAYS_INLINE \
250  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
251  mem1(), \
252  mem2(), \
253  mem3() { \
254  this->swap(rhs); \
255  }
256 
257 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_4(tp, mem1, mem2, mem3, mem4) \
258  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
259  NLIB_ALWAYS_INLINE \
260  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
261  mem1(), \
262  mem2(), \
263  mem3(), \
264  mem4() { \
265  this->swap(rhs); \
266  }
267 
268 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_5(tp, mem1, mem2, mem3, mem4, mem5) \
269  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
270  NLIB_ALWAYS_INLINE \
271  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
272  mem1(), \
273  mem2(), \
274  mem3(), \
275  mem4(), \
276  mem5() { \
277  this->swap(rhs); \
278  }
279 
280 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
281  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
282  NLIB_ALWAYS_INLINE \
283  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
284  mem1(), \
285  mem2(), \
286  mem3(), \
287  mem4(), \
288  mem5(), \
289  mem6() { \
290  this->swap(rhs); \
291  }
292 
293 #ifdef NLIB_CXX11_RVALUE_REFERENCES
294 #define NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp) \
295  NLIB_ALWAYS_INLINE \
296  tp& operator=(tp&& rhs) NLIB_NOEXCEPT { \
297  tp tmp(std::move(rhs)); \
298  this->swap(tmp); \
299  return *this; \
300  }
301 
302 #ifdef NLIB_CXX11_DELEGATING_CONSTRUCTORS
303 #define NLIB_MOVE_MEMBER_HELPER_(tp) \
304  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
305  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp) \
306  NLIB_ALWAYS_INLINE \
307  tp(tp&& rhs) NLIB_NOEXCEPT : tp() { this->swap(rhs); } \
308  NLIB_ALWAYS_INLINE \
309  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : tp() { this->swap(rhs); } // NOLINT
310 
311 #define NLIB_MOVE_MEMBER_HELPER_1(tp, mem1) NLIB_MOVE_MEMBER_HELPER_(tp)
312 #define NLIB_MOVE_MEMBER_HELPER_2(tp, mem1, mem2) NLIB_MOVE_MEMBER_HELPER_(tp)
313 #define NLIB_MOVE_MEMBER_HELPER_3(tp, mem1, mem2, mem3) NLIB_MOVE_MEMBER_HELPER_(tp)
314 #define NLIB_MOVE_MEMBER_HELPER_4(tp, mem1, mem2, mem3, mem4) NLIB_MOVE_MEMBER_HELPER_(tp)
315 #define NLIB_MOVE_MEMBER_HELPER_5(tp, mem1, mem2, mem3, mem4, mem5) NLIB_MOVE_MEMBER_HELPER_(tp)
316 #define NLIB_MOVE_MEMBER_HELPER_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
317  NLIB_MOVE_MEMBER_HELPER_(tp)
318 
319 #else
320 #define NLIB_MOVE_MEMBER_HELPER_1(tp, mem1) \
321  NLIB_ALWAYS_INLINE \
322  tp(tp&& rhs) NLIB_NOEXCEPT : mem1() { this->swap(rhs); } \
323  NLIB_MOVE_MEMBER_HELPER_WITHTAG_1(tp, mem1) \
324  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
325 
326 #define NLIB_MOVE_MEMBER_HELPER_2(tp, mem1, mem2) \
327  NLIB_ALWAYS_INLINE \
328  tp(tp&& rhs) : mem1(), mem2() { this->swap(rhs); } \
329  NLIB_MOVE_MEMBER_HELPER_WITHTAG_2(tp, mem1, mem2) \
330  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
331 
332 #define NLIB_MOVE_MEMBER_HELPER_3(tp, mem1, mem2, mem3) \
333  NLIB_ALWAYS_INLINE \
334  tp(tp&& rhs) : mem1(), mem2(), mem3() { this->swap(rhs); } \
335  NLIB_MOVE_MEMBER_HELPER_WITHTAG_3(tp, mem1, mem2, mem3) \
336  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
337 
338 #define NLIB_MOVE_MEMBER_HELPER_4(tp, mem1, mem2, mem3, mem4) \
339  NLIB_ALWAYS_INLINE \
340  tp(tp&& rhs) : mem1(), mem2(), mem3(), mem4() { this->swap(rhs); } \
341  NLIB_MOVE_MEMBER_HELPER_WITHTAG_4(tp, mem1, mem2, mem3, mem4) \
342  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
343 
344 #define NLIB_MOVE_MEMBER_HELPER_5(tp, mem1, mem2, mem3, mem4, mem5) \
345  NLIB_ALWAYS_INLINE \
346  tp(tp&& rhs) : mem1(), mem2(), mem3(), mem4(), mem5() { this->swap(rhs); } \
347  NLIB_MOVE_MEMBER_HELPER_WITHTAG_5(tp, mem1, mem2, mem3, mem4, mem5) \
348  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
349 
350 #define NLIB_MOVE_MEMBER_HELPER_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
351  NLIB_ALWAYS_INLINE \
352  tp(tp&& rhs) : mem1(), mem2(), mem3(), mem4(), mem5(), mem6() { this->swap(rhs); } \
353  NLIB_MOVE_MEMBER_HELPER_WITHTAG_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
354  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
355 
356 #endif
357 #else
358 #define NLIB_MOVE_MEMBER_HELPER_1(tp, mem1) NLIB_MOVE_MEMBER_HELPER_WITHTAG_1(tp, mem1)
359 
360 #define NLIB_MOVE_MEMBER_HELPER_2(tp, mem1, mem2) NLIB_MOVE_MEMBER_HELPER_WITHTAG_2(tp, mem1, mem2)
361 
362 #define NLIB_MOVE_MEMBER_HELPER_3(tp, mem1, mem2, mem3) \
363  NLIB_MOVE_MEMBER_HELPER_WITHTAG_3(tp, mem1, mem2, mem3)
364 
365 #define NLIB_MOVE_MEMBER_HELPER_4(tp, mem1, mem2, mem3, mem4) \
366  NLIB_MOVE_MEMBER_HELPER_WITHTAG_4(tp, mem1, mem2, mem3, mem4)
367 
368 #define NLIB_MOVE_MEMBER_HELPER_5(tp, mem1, mem2, mem3, mem4, mem5) \
369  NLIB_MOVE_MEMBER_HELPER_WITHTAG_5(tp, mem1, mem2, mem3, mem4, mem5)
370 
371 #define NLIB_MOVE_MEMBER_HELPER_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
372  NLIB_MOVE_MEMBER_HELPER_WITHTAG_6(tp, mem1, mem2, mem3, mem4, mem5, mem6)
373 
374 #endif
375 
376 #ifdef NLIB_HAS_STDHEADER_TIME
377 // Do not include ctime.
378 // Some compilers does not have std::time_t
379 // Now, this is only for DateTime.h
380 # include <time.h> // NOLINT
381 #endif
382 
383 #ifndef NLIB_MEMCHECKER
384 # define NLIB_MEMCHECKER NLIB_STATIC_ASSERT(sizeof(char) == 1) // NOLINT
385 # define NLIB_MEMCHECKER_START NLIB_STATIC_ASSERT(sizeof(char) == 1) // NOLINT
386 # define NLIB_MEMCHECKER_CHECK true
387 #endif
388 
389 #ifndef NLIB_UNUSED
390 # define NLIB_UNUSED(x) (void)(x)
391 #endif
392 
393 // The following macro "NLIB_NOEMPTYFILE()" can be put into a file
394 // in order suppress the MS Visual C++ Linker warning 4221
395 #ifndef NLIB_NOEMPTYFILE
396 # define NLIB_NOEMPTYFILE()
397 #endif
398 
399 #ifdef NLIB_SOCKET_ENABLED
400 # ifdef _MSC_VER
401 # ifdef _DEBUG
402 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 50)
403 # else
404 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER)
405 # endif
406 # elif defined(__clang__)
407 # ifdef NDEBUG
408 # define NLIB_SOCKPORT_SAMPLE (18174)
409 # else
410 # define NLIB_SOCKPORT_SAMPLE (18074)
411 # endif
412 # else
413 # ifdef NDEBUG
414 # define NLIB_SOCKPORT_SAMPLE (17874)
415 # else
416 # define NLIB_SOCKPORT_SAMPLE (17974)
417 # endif
418 # endif
419 #endif
420 
421 //
422 // You can reduce the loopcount for the performance test
423 // when it runs on on a continuous integration system like Jenkins.
424 //
425 // for (int i = 0; i < NLIB_TESTLOOPCOUNT(10000); ++i) {
426 // .....
427 // }
428 //
429 #if !defined(NLIB_CIBUILD) && defined(NDEBUG)
430 # define NLIB_TESTLOOPCOUNT(x) (x)
431 #else
432 # define NLIB_TESTLOOPCOUNT(x) (1)
433 #endif
434 
435 #endif // INCLUDE_NN_NLIB_CONFIG_H_
nlib_utf16_t utf16_t
UTF16の文字に対する型です。 nlib_utf16_tにtypedefされています。
Definition: Config.h:162
基本的なAPIがCベースで宣言されています。
uint32_t nlib_utf32_t
char32_tが利用できる場合はchar32_tに、そうでない場合はuint32_tにtypedefされます。 ...
Definition: Platform.h:2161
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
Definition: Config.h:219
uint16_t nlib_utf16_t
char16_tが利用できる場合はchar16_tに、そうでない場合はuint16_tにtypedefされます。 ...
Definition: Platform.h:2160
共通して使われる機能やプラットフォームへの依存度が高い機能が実装されます。 nlib Platform APIs も御覧...
nlib_utf32_t utf32_t
UTF32の文字に対する型です。 nlib_utf32_tにtypedefされています。
Definition: Config.h:163
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
Definition: Config.h:117