nlib
Config.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_CONFIG_H_
17 #define INCLUDE_NN_NLIB_CONFIG_H_
18 
19 // NOTE:
20 // DO NOT INCLUDE THE STANDARD C/C++ LIBRARY HEADERS
21 // on the line always included in this header.
22 // This would make it difficult to avoid compile errors
23 // on the environment which lacks the standard headers.
24 
25 #include "nn/nlib/Platform.h"
26 
27 #if defined(_MSC_VER)
28 #if defined(n_EXPORTS)
29 #undef NLIB_VIS_PUBLIC
30 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
31 #elif defined(nx_misc_EXPORTS)
32 #undef NLIB_VIS_PUBLIC
33 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
34 #endif
35 #endif
36 
37 #ifndef NLIB_NAMESPACE_BEGIN
38 #define NLIB_NAMESPACE_BEGIN namespace nn { namespace nlib {
39 #endif
40 
41 #ifndef NLIB_NAMESPACE_END
42 #define NLIB_NAMESPACE_END }}
43 #endif
44 
45 #ifndef NLIB_NS
46 #define NLIB_NS ::nn::nlib
47 #endif
48 
49 NLIB_NAMESPACE_BEGIN
50 NLIB_NAMESPACE_END
51 namespace nlib_ns = NLIB_NS;
52 
53 #if defined(CAFE)
54 # include "nn/nlib/Config_cafe.h" // NOLINT
55 #elif defined(NN_PLATFORM_CTR)
56 # include "nn/nlib/Config_ctr.h" // NOLINT
57 #elif defined(__NX__)
58 # include "nn/nlib/Config_nx.h" // NOLINT
59 #elif defined(_MSC_VER)
60 # include "nn/nlib/Config_win32.h" // NOLINT
61 #elif defined(__CYGWIN__)
62 # include "nn/nlib/Config_cygwin.h" // NOLINT
63 #elif defined(__linux__)
64 # include "nn/nlib/Config_linux.h" // NOLINT
65 #elif defined(__FreeBSD__)
66 # include "nn/nlib/Config_freebsd.h" // NOLINT
67 #elif defined(__APPLE__) && defined(__MACH__)
68 # include "nn/nlib/Config_osx.h" // NOLINT
69 #endif
70 
71 #ifdef NLIB_CXX11_STDLIB_ATOMIC
72 // NOTE: redefine them to use std C++ library for memory barrier
73 # undef NLIB_MEMORY_ORDER_RELEASE
74 # undef NLIB_MEMORY_ORDER_ACQUIRE
75 # undef NLIB_MEMORY_ORDER_ACQ_REL
76 # include <atomic> // NOLINT
77 # define NLIB_MEMORY_ORDER_RELEASE ::std::atomic_thread_fence(::std::memory_order_release)
78 # define NLIB_MEMORY_ORDER_ACQUIRE ::std::atomic_thread_fence(::std::memory_order_acquire)
79 # define NLIB_MEMORY_ORDER_ACQ_REL ::std::atomic_thread_fence(::std::memory_order_acq_rel)
80 #endif
81 
82 #ifdef NLIB_CXX11_RVALUE_REFERENCES
83 # define NLIB_RREF &&
84 # define NLIB_FWD(T, v) std::forward<T>(v)
85 # define NLIB_MOVE(x) std::move(x)
86 #else
87 # define NLIB_RREF &
88 # define NLIB_FWD(T, v) (v)
89 # define NLIB_MOVE(x) (x)
90 #endif
91 
92 #ifdef NLIB_CXX11_CONSTEXPR
93 # define NLIB_CEXPR constexpr
94 #else
95 # define NLIB_CEXPR
96 #endif
97 
98 #ifdef NLIB_DOXYGEN
99 #define NLIB_NOEXCEPT noexcept
100 #define NLIB_NOEXCEPT_FUNCPTR
101 #endif
102 
103 #ifndef NLIB_NOEXCEPT
104 # define NLIB_NOEXCEPT
105 #elif defined(__INTELLISENSE__)
106 # undef NLIB_NOEXCEPT
107 # define NLIB_NOEXCEPT
108 #endif
109 
110 #ifndef NLIB_NOEXCEPT_FUNCPTR
111 #define NLIB_NOEXCEPT_FUNCPTR
112 #endif
113 
114 struct nlib_unwind_exception {}; // Do not throw this directly
115 #ifndef NLIB_RETHROW_UNWIND
116 # define NLIB_RETHROW_UNWIND catch (nlib_unwind_exception&)
117 #endif
118 
119 #ifndef NLIB_ASSERT_NOERR
120 # define NLIB_ASSERT_NOERR(e) NLIB_ASSERT((e) == 0)
121 #endif
122 
123 #ifdef NLIB_EXCEPTION_ENABLED
124 # define NLIB_TRY try
125 # define NLIB_CATCH(x) catch(x)
126 # define NLIB_THROW throw
127 #else
128 # define NLIB_TRY if (true)
129 # define NLIB_CATCH(x) if (false)
130 # define NLIB_THROW
131 #endif
132 
133 #ifndef NLIB_STATIC_ASSERT
134 #ifndef NLIB_CXX11_STATIC_ASSERTIONS
135 NLIB_NAMESPACE_BEGIN
136 namespace detail {
137 template <bool>
138 struct STATIC_ASSERTION_FAILURE;
139 template <>
140 struct STATIC_ASSERTION_FAILURE<true> {};
141 template <int x>
142 struct static_assert_test {};
143 } // namespace detail
144 NLIB_NAMESPACE_END
145 
146 #define NLIB_ASSERT_H_STRING_JOIN_(X, Y) NLIB_ASSERT_H_STRING_JOIN1_(X, Y)
147 #define NLIB_ASSERT_H_STRING_JOIN1_(X, Y) X##Y
148 
149 #define NLIB_STATIC_ASSERT(exp) \
150  typedef ::nlib_ns::detail::static_assert_test< \
151  sizeof(::nlib_ns::detail::STATIC_ASSERTION_FAILURE<(exp) != 0>)> \
152  NLIB_ASSERT_H_STRING_JOIN_(nn_static_assert_typedef_, __LINE__)
153 #else
154 # define NLIB_STATIC_ASSERT(exp) static_assert((exp), "NLIB_STATIC_ASSERT error: " #exp)
155 #endif
156 #endif
157 
158 #ifndef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
159 #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
160 TypeName(const TypeName&); \
161 void operator=(const TypeName&)
162 #else
163 #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
164 TypeName(const TypeName&) = delete; \
165 void operator=(const TypeName&) = delete
166 #endif
167 
168 #ifndef NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS
169 #define NLIB_SAFE_BOOL(class_name, exp) \
170 private: \
171  typedef void (class_name::*bool_type)() const; \
172  void this_type_does_not_support_comparisons() const NLIB_NOEXCEPT {} \
173 public: \
174  operator bool_type() const NLIB_NOEXCEPT { \
175  return (exp) ? &class_name::this_type_does_not_support_comparisons : 0; \
176  }
177 #else
178 #define NLIB_SAFE_BOOL(class_name, exp) \
179 public: \
180  explicit NLIB_ALWAYS_INLINE operator bool() const NLIB_NOEXCEPT { return (exp); }
181 #endif
182 
183 #include <wchar.h> // NOLINT
184 #if defined(WCHAR_MIN) && defined(WCHAR_MAX)
185 # if WCHAR_MAX <= 0xFFFF
186 # define NLIB_WCHAR_SIZE (2)
187 NLIB_STATIC_ASSERT(sizeof(wchar_t) == 2);
188 # else
189 # define NLIB_WCHAR_SIZE (4)
190 NLIB_STATIC_ASSERT(sizeof(wchar_t) == 4);
191 # endif
192 #else
193 # error WCHAR_MIN, WCHAR_MAX not defined
194 #endif
195 
196 #ifndef NLIB_CXX11_NULL_POINTER_CONSTANT
197 NLIB_NAMESPACE_BEGIN
198 class nullptr_t {
199  public:
200  template <class T>
201  operator T*() const {
202  return 0;
203  }
204  template <class C, class T>
205  operator T C::*() const {
206  return 0;
207  }
208 
209  private:
210  void operator&() const; // NOLINT
211 };
212 #ifndef nullptr
213 // if nullptr macro is defined, just use it.
214 const nullptr_t nullptr = {};
215 #endif
216 NLIB_NAMESPACE_END
217 #else
218 #include <cstddef> // NOLINT this is because stddef.h does not define std::nullptr_t
219 NLIB_NAMESPACE_BEGIN
220 typedef std::nullptr_t nullptr_t;
221 NLIB_NAMESPACE_END
222 #endif
223 
224 #ifndef NLIB_CXX11_EXPLICIT_VIRTUAL_OVERRIDES
225 # define NLIB_OVERRIDE
226 # define NLIB_FINAL
227 #else
228 # define NLIB_OVERRIDE override
229 # define NLIB_FINAL final
230 #endif
231 
232 #ifdef NLIB_CXX11_ALIGNMENT_SUPPORT
233 # ifdef NLIB_ALIGNAS
234 # undef NLIB_ALIGNAS
235 # endif
236 # ifdef NLIB_ALIGNOF
237 # undef NLIB_ALIGNOF
238 # endif
239 # define NLIB_ALIGNAS(x) alignas(x)
240 # define NLIB_ALIGNOF(tp) alignof(tp)
241 #endif
242 
243 #ifdef NLIB_CXX11_RVALUE_REFERENCES
244 // for std::move
245 # include <utility> // NOLINT
246 #endif
247 
248 NLIB_NAMESPACE_BEGIN
249 struct move_tag {};
250 NLIB_NAMESPACE_END
251 
252 #define NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
253  NLIB_ALWAYS_INLINE \
254  tp& assign(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT { /* NOLINT */ \
255  tp().swap(*this); \
256  this->swap(rhs); \
257  return *this; \
258  }
259 
260 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_1(tp, mem1) \
261  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
262  NLIB_ALWAYS_INLINE \
263  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : mem1() /* NOLINT */ \
264  { \
265  this->swap(rhs); \
266  }
267 
268 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_2(tp, mem1, mem2) \
269  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
270  NLIB_ALWAYS_INLINE \
271  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : mem1(), /* NOLINT */ \
272  mem2() \
273  { \
274  this->swap(rhs); \
275  }
276 
277 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_3(tp, mem1, mem2, mem3) \
278  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
279  NLIB_ALWAYS_INLINE \
280  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
281  mem1(), \
282  mem2(), \
283  mem3() { \
284  this->swap(rhs); \
285  }
286 
287 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_4(tp, mem1, mem2, mem3, mem4) \
288  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
289  NLIB_ALWAYS_INLINE \
290  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
291  mem1(), \
292  mem2(), \
293  mem3(), \
294  mem4() { \
295  this->swap(rhs); \
296  }
297 
298 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_5(tp, mem1, mem2, mem3, mem4, mem5) \
299  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
300  NLIB_ALWAYS_INLINE \
301  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
302  mem1(), \
303  mem2(), \
304  mem3(), \
305  mem4(), \
306  mem5() { \
307  this->swap(rhs); \
308  }
309 
310 #define NLIB_MOVE_MEMBER_HELPER_WITHTAG_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
311  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
312  NLIB_ALWAYS_INLINE \
313  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : /* NOLINT */ \
314  mem1(), \
315  mem2(), \
316  mem3(), \
317  mem4(), \
318  mem5(), \
319  mem6() { \
320  this->swap(rhs); \
321  }
322 
323 #ifdef NLIB_CXX11_RVALUE_REFERENCES
324 #define NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp) \
325  NLIB_ALWAYS_INLINE \
326  tp& operator=(tp&& rhs) NLIB_NOEXCEPT { \
327  tp tmp(std::move(rhs)); \
328  this->swap(tmp); \
329  return *this; \
330  }
331 
332 #ifdef NLIB_CXX11_DELEGATING_CONSTRUCTORS
333 #define NLIB_MOVE_MEMBER_HELPER_(tp) \
334  NLIB_MOVE_MEMBER_HELPER_COMMON(tp) \
335  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp) \
336  NLIB_ALWAYS_INLINE \
337  tp(tp&& rhs) NLIB_NOEXCEPT : tp() { this->swap(rhs); } \
338  NLIB_ALWAYS_INLINE \
339  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : tp() { this->swap(rhs); } // NOLINT
340 
341 #define NLIB_MOVE_MEMBER_HELPER_1(tp, mem1) NLIB_MOVE_MEMBER_HELPER_(tp)
342 #define NLIB_MOVE_MEMBER_HELPER_2(tp, mem1, mem2) NLIB_MOVE_MEMBER_HELPER_(tp)
343 #define NLIB_MOVE_MEMBER_HELPER_3(tp, mem1, mem2, mem3) NLIB_MOVE_MEMBER_HELPER_(tp)
344 #define NLIB_MOVE_MEMBER_HELPER_4(tp, mem1, mem2, mem3, mem4) NLIB_MOVE_MEMBER_HELPER_(tp)
345 #define NLIB_MOVE_MEMBER_HELPER_5(tp, mem1, mem2, mem3, mem4, mem5) NLIB_MOVE_MEMBER_HELPER_(tp)
346 #define NLIB_MOVE_MEMBER_HELPER_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
347  NLIB_MOVE_MEMBER_HELPER_(tp)
348 
349 #else
350 #define NLIB_MOVE_MEMBER_HELPER_1(tp, mem1) \
351  NLIB_ALWAYS_INLINE \
352  tp(tp&& rhs) NLIB_NOEXCEPT : mem1() { this->swap(rhs); } \
353  NLIB_MOVE_MEMBER_HELPER_WITHTAG_1(tp, mem1) \
354  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
355 
356 #define NLIB_MOVE_MEMBER_HELPER_2(tp, mem1, mem2) \
357  NLIB_ALWAYS_INLINE \
358  tp(tp&& rhs) : mem1(), mem2() { this->swap(rhs); } \
359  NLIB_MOVE_MEMBER_HELPER_WITHTAG_2(tp, mem1, mem2) \
360  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
361 
362 #define NLIB_MOVE_MEMBER_HELPER_3(tp, mem1, mem2, mem3) \
363  NLIB_ALWAYS_INLINE \
364  tp(tp&& rhs) : mem1(), mem2(), mem3() { this->swap(rhs); } \
365  NLIB_MOVE_MEMBER_HELPER_WITHTAG_3(tp, mem1, mem2, mem3) \
366  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
367 
368 #define NLIB_MOVE_MEMBER_HELPER_4(tp, mem1, mem2, mem3, mem4) \
369  NLIB_ALWAYS_INLINE \
370  tp(tp&& rhs) : mem1(), mem2(), mem3(), mem4() { this->swap(rhs); } \
371  NLIB_MOVE_MEMBER_HELPER_WITHTAG_4(tp, mem1, mem2, mem3, mem4) \
372  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
373 
374 #define NLIB_MOVE_MEMBER_HELPER_5(tp, mem1, mem2, mem3, mem4, mem5) \
375  NLIB_ALWAYS_INLINE \
376  tp(tp&& rhs) : mem1(), mem2(), mem3(), mem4(), mem5() { this->swap(rhs); } \
377  NLIB_MOVE_MEMBER_HELPER_WITHTAG_5(tp, mem1, mem2, mem3, mem4, mem5) \
378  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
379 
380 #define NLIB_MOVE_MEMBER_HELPER_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
381  NLIB_ALWAYS_INLINE \
382  tp(tp&& rhs) : mem1(), mem2(), mem3(), mem4(), mem5(), mem6() { this->swap(rhs); } \
383  NLIB_MOVE_MEMBER_HELPER_WITHTAG_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
384  NLIB_MOVE_MEMBER_HELPER_X_COMMON(tp)
385 
386 #endif
387 #else
388 #define NLIB_MOVE_MEMBER_HELPER_1(tp, mem1) NLIB_MOVE_MEMBER_HELPER_WITHTAG_1(tp, mem1)
389 
390 #define NLIB_MOVE_MEMBER_HELPER_2(tp, mem1, mem2) NLIB_MOVE_MEMBER_HELPER_WITHTAG_2(tp, mem1, mem2)
391 
392 #define NLIB_MOVE_MEMBER_HELPER_3(tp, mem1, mem2, mem3) \
393  NLIB_MOVE_MEMBER_HELPER_WITHTAG_3(tp, mem1, mem2, mem3)
394 
395 #define NLIB_MOVE_MEMBER_HELPER_4(tp, mem1, mem2, mem3, mem4) \
396  NLIB_MOVE_MEMBER_HELPER_WITHTAG_4(tp, mem1, mem2, mem3, mem4)
397 
398 #define NLIB_MOVE_MEMBER_HELPER_5(tp, mem1, mem2, mem3, mem4, mem5) \
399  NLIB_MOVE_MEMBER_HELPER_WITHTAG_5(tp, mem1, mem2, mem3, mem4, mem5)
400 
401 #define NLIB_MOVE_MEMBER_HELPER_6(tp, mem1, mem2, mem3, mem4, mem5, mem6) \
402  NLIB_MOVE_MEMBER_HELPER_WITHTAG_6(tp, mem1, mem2, mem3, mem4, mem5, mem6)
403 
404 #endif
405 
406 #ifndef NLIB_MEMCHECKER
407 # define NLIB_MEMCHECKER NLIB_STATIC_ASSERT(sizeof(char) == 1) // NOLINT
408 # define NLIB_MEMCHECKER_START NLIB_STATIC_ASSERT(sizeof(char) == 1) // NOLINT
409 # define NLIB_MEMCHECKER_CHECK true
410 #endif
411 
412 // The following macro "NLIB_NOEMPTYFILE()" can be put into a file
413 // in order suppress the MS Visual C++ Linker warning 4221
414 #ifndef NLIB_NOEMPTYFILE
415 # define NLIB_NOEMPTYFILE()
416 #endif
417 
418 #ifdef NLIB_SOCKET_ENABLED
419 # ifdef _MSC_VER
420 # ifndef NLIB_WINDLL
421 # ifdef _DEBUG
422 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 50)
423 # else
424 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER)
425 # endif
426 # else
427 # ifdef _DEBUG
428 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 75)
429 # else
430 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 25)
431 # endif
432 # endif
433 # elif defined(__clang__)
434 # ifdef NDEBUG
435 # define NLIB_SOCKPORT_SAMPLE (18174)
436 # else
437 # define NLIB_SOCKPORT_SAMPLE (18074)
438 # endif
439 # else
440 # ifdef NDEBUG
441 # define NLIB_SOCKPORT_SAMPLE (17874)
442 # else
443 # define NLIB_SOCKPORT_SAMPLE (17974)
444 # endif
445 # endif
446 #endif
447 
448 //
449 // You can reduce the loopcount for the performance test
450 // when it runs on on a continuous integration system like Jenkins.
451 //
452 // for (int i = 0; i < NLIB_TESTLOOPCOUNT(10000); ++i) {
453 // .....
454 // }
455 //
456 #if !defined(NLIB_CIBUILD) && defined(NDEBUG)
457 # define NLIB_TESTLOOPCOUNT(x) (x)
458 #else
459 # define NLIB_TESTLOOPCOUNT(x) (1)
460 #endif
461 
462 #ifndef NLIB_OVERRIDE_NEW
463 #define NLIB_OVERRIDE_NEW \
464  static void* operator new(size_t size); \
465  static void operator delete(void* ptr); \
466  static void* operator new(size_t size, void* ptr) NLIB_NOEXCEPT; \
467  static void operator delete(void* mem, void* ptr) NLIB_NOEXCEPT; \
468  static void* operator new(size_t size, const std::nothrow_t& nt) NLIB_NOEXCEPT; \
469  static void operator delete(void* mem, const std::nothrow_t& nt) NLIB_NOEXCEPT
470 #endif
471 
472 #ifndef NLIB_OVERRIDE_NEW_LIBNEW_CPP
473 #define NLIB_OVERRIDE_NEW_LIBNEW_CPP(type) \
474  void* type::operator new(size_t size) { return ::operator new(size); } \
475  void type::operator delete(void* ptr) { ::operator delete(ptr); } \
476  void* type::operator new(size_t size, void* ptr) NLIB_NOEXCEPT { \
477  return ::operator new(size, ptr); \
478  } \
479  void type::operator delete(void* mem, void* ptr) NLIB_NOEXCEPT { \
480  ::operator delete(mem, ptr); \
481  } \
482  void* type::operator new(size_t size, const std::nothrow_t& nt) NLIB_NOEXCEPT { \
483  return ::operator new(size, nt); \
484  } \
485  void type::operator delete(void* mem, const std::nothrow_t& nt) NLIB_NOEXCEPT { \
486  NLIB_UNUSED(nt); \
487  ::operator delete(mem); \
488  }
489 #endif
490 
491 NLIB_NAMESPACE_BEGIN
493  public:
494  ErrnoT() NLIB_NOEXCEPT {}
495  NLIB_CEXPR ErrnoT(errno_t e) NLIB_NOEXCEPT : vs_errno_(e) {} // NOLINT
496  ErrnoT& operator=(errno_t e) NLIB_NOEXCEPT {
497  vs_errno_ = e;
498  return *this;
499  }
500  operator errno_t() const NLIB_NOEXCEPT { return vs_errno_; }
501  // const char* c_str() const NLIB_NOEXCEPT { return nlib_error_string(vs_errno_); }
502 
503  private:
504  // to suppress the mix-up with boolean value
505  bool operator!() const; // FORBIDDEN
506  // operator bool() const; // FORBIDDEN
507  errno_t vs_errno_;
508 };
509 
511  return lhs.operator errno_t() == rhs;
512 }
513 
515  return rhs.operator errno_t() == lhs;
516 }
517 
519  return lhs.operator errno_t() != rhs;
520 }
521 
523  return rhs.operator errno_t() != lhs;
524 }
525 
527  public:
528  Utf8Ptr() NLIB_NOEXCEPT : str_(NULL) {}
529  Utf8Ptr(const char* str) NLIB_NOEXCEPT : str_(str) {} // NOLINT
530  operator const char*() const NLIB_NOEXCEPT { return str_; }
531  Utf8Ptr& operator=(const char* str) NLIB_NOEXCEPT { str_ = str; return *this; }
532  const char& operator[](size_t idx) const NLIB_NOEXCEPT { return str_[idx]; }
533 
534  private:
535  const char* str_;
536 };
537 
538 template<size_t N>
540  public:
542  operator char*() NLIB_NOEXCEPT { return &str_[0]; }
543  operator const char*() const NLIB_NOEXCEPT { return &str_[0]; }
544  const char& operator[](size_t idx) const NLIB_NOEXCEPT { return str_[idx]; }
545  char& operator[](size_t idx) NLIB_NOEXCEPT { return str_[idx]; }
546 
547  private:
548  char str_[N];
549 };
550 NLIB_NAMESPACE_END
551 
552 //
553 // C++ functions in global namespace
554 //
555 #ifdef __cplusplus
556 template <size_t N>
558  size_t* count,
559  char (&buf)[N],
560  _Printf_format_string_ const char* fmt,
561  va_list args) NLIB_NOEXCEPT {
562  return nlib_vsnprintf(count, buf, N, fmt, args);
563 }
564 
565 template<size_t N>
567  size_t* count,
568  char (&buf)[N],
569  _Printf_format_string_ const char* fmt,
570  ...) NLIB_NOEXCEPT {
571  va_list args;
572  va_start(args, fmt);
573  errno_t e = nlib_vsnprintf(count, buf, N, fmt, args);
574  va_end(args);
575  return e;
576 }
577 
578 template <size_t N>
580  size_t* count,
581  wchar_t (&buf)[N],
582  _Printf_format_string_ const wchar_t* fmt,
583  va_list args) NLIB_NOEXCEPT {
584  return nlib_vsnwprintf(count, buf, N, fmt, args);
585 }
586 
587 template<size_t N>
589  size_t* count,
590  wchar_t(&buf)[N],
591  _Printf_format_string_ const wchar_t* fmt,
592  ...) NLIB_NOEXCEPT {
593  va_list args;
594  va_start(args, fmt);
595  errno_t e = nlib_vsnwprintf(count, buf, N, fmt, args);
596  va_end(args);
597  return e;
598 }
599 
600 template <size_t N>
601 NLIB_ALWAYS_INLINE errno_t nlib_vsnprintf_fallback(
602  size_t* count,
603  char (&buf)[N],
604  _Printf_format_string_ const char* fmt,
605  va_list args) NLIB_NOEXCEPT {
606  return nlib_vsnprintf_fallback(count, buf, N, fmt, args);
607 }
608 
609 template<size_t N>
610 inline NLIB_VIS_HIDDEN errno_t nlib_snprintf_fallback(
611  size_t* count,
612  char (&buf)[N],
613  _Printf_format_string_ const char* fmt,
614  ...) NLIB_NOEXCEPT {
615  va_list args;
616  va_start(args, fmt);
617  errno_t e = nlib_vsnprintf_fallback(count, buf, N, fmt, args);
618  va_end(args);
619  return e;
620 }
621 
622 template <size_t N>
623 NLIB_ALWAYS_INLINE errno_t nlib_vsnwprintf_fallback(
624  size_t* count,
625  wchar_t (&buf)[N],
626  _Printf_format_string_ const wchar_t* fmt,
627  va_list args) NLIB_NOEXCEPT {
628  return nlib_vsnwprintf_fallback(count, buf, N, fmt, args);
629 }
630 
631 template<size_t N>
632 inline NLIB_VIS_HIDDEN errno_t nlib_snwprintf_fallback(
633  size_t* count,
634  wchar_t(&buf)[N],
635  _Printf_format_string_ const wchar_t* fmt,
636  ...) NLIB_NOEXCEPT {
637  va_list args;
638  va_start(args, fmt);
639  errno_t e = nlib_vsnwprintf_fallback(count, buf, N, fmt, args);
640  va_end(args);
641  return e;
642 }
643 
644 template <size_t N>
646  char (&s1)[N],
647  const char* s2) NLIB_NOEXCEPT {
648  return nlib_strcpy(&s1[0], N, s2);
649 }
650 
651 template<size_t N>
652 NLIB_ALWAYS_INLINE size_t nlib_strlcpy(char (&s1)[N], const char* s2) NLIB_NOEXCEPT {
653  // CTR armcc needs cast
654  return nlib_strlcpy((char*)&s1[0], (const char*)s2, N); // NOLINT
655 }
656 
657 template <size_t N>
659  char (&s1)[N],
660  const char* s2,
661  size_t n) NLIB_NOEXCEPT {
662  return nlib_strncpy(&s1[0], N, s2, n);
663 }
664 
665 template <size_t N>
667  wchar_t (&s1)[N],
668  const wchar_t* s2) NLIB_NOEXCEPT {
669  return nlib_wcscpy(&s1[0], N, s2);
670 }
671 
672 template <size_t N>
674  wchar_t (&s1)[N],
675  const wchar_t* s2,
676  size_t n) NLIB_NOEXCEPT {
677  return nlib_wcsncpy(&s1[0], N, s2, n);
678 }
679 
680 template<size_t N>
682  const wchar_t* wcstr) NLIB_NOEXCEPT {
683  return nlib_wide_to_utf8(result, &utf8[0], N, wcstr);
684 }
685 
686 template<size_t N>
687 NLIB_ALWAYS_INLINE errno_t nlib_utf8_to_wide(size_t* result, wchar_t (&wcstr)[N],
688  const nlib_utf8_t* utf8) NLIB_NOEXCEPT {
689  return nlib_utf8_to_wide(result, &wcstr[0], N, utf8);
690 }
691 
692 template<size_t N>
694  const nlib_utf16_t* utf16) NLIB_NOEXCEPT {
695  return nlib_utf16_to_utf8(utf8count, &utf8[0], N, utf16);
696 }
697 
698 template<size_t N>
700  const nlib_utf8_t* utf8) NLIB_NOEXCEPT {
701  return nlib_utf8_to_utf16(utf16count, &utf16[0], N, utf8);
702 }
703 
704 template<size_t N>
706  const nlib_utf32_t* utf32) NLIB_NOEXCEPT {
707  return nlib_utf32_to_utf8(utf8count, &utf8[0], N, utf32);
708 }
709 
710 template<size_t N>
712  const nlib_utf8_t* utf8) NLIB_NOEXCEPT {
713  return nlib_utf8_to_utf32(utf32count, &utf32[0], N, utf8);
714 }
715 
716 template<size_t N>
718  size_t* to_count, size_t* from_count,
719  nlib_utf8_t (&to)[N],
720  const nlib_utf16_t* from, size_t from_size) NLIB_NOEXCEPT {
721  return nlib_memutf16_to_utf8(to_count, from_count, &to[0], N, from, from_size);
722 }
723 template<size_t N>
725  size_t* to_count, size_t* from_count,
726  nlib_utf16_t (&to)[N],
727  const nlib_utf8_t* from, size_t from_size) NLIB_NOEXCEPT {
728  return nlib_memutf8_to_utf16(to_count, from_count, &to[0], N, from, from_size);
729 }
730 template<size_t N>
732  size_t* to_count, size_t* from_count,
733  nlib_utf8_t (&to)[N],
734  const nlib_utf32_t* from, size_t from_size) NLIB_NOEXCEPT {
735  return nlib_memutf32_to_utf8(to_count, from_count, &to[0], N, from, from_size);
736 }
737 template<size_t N>
739  size_t* to_count, size_t* from_count,
740  nlib_utf32_t (&to)[N],
741  const nlib_utf8_t* from, size_t from_size) NLIB_NOEXCEPT {
742  return nlib_memutf8_to_utf32(to_count, from_count, &to[0], N, from, from_size);
743 }
744 template<size_t N>
746  size_t* to_count, size_t* from_count,
747  nlib_utf8_t (&to)[N],
748  const wchar_t* from, size_t from_size) NLIB_NOEXCEPT {
749  return nlib_memwide_to_utf8(to_count, from_count, &to[0], N, from, from_size);
750 }
751 template<size_t N>
753  size_t* to_count, size_t* from_count,
754  wchar_t (&to)[N],
755  const nlib_utf8_t* from, size_t from_size) NLIB_NOEXCEPT {
756  return nlib_memutf8_to_wide(to_count, from_count, &to[0], N, from, from_size);
757 }
758 
759 #if !defined(NN_PLATFORM_CTR) && !defined(CAFE)
760 // This may throw C++ exception defined by nlib, See also nlib_thread_exit()
762 #endif
763 
764 NLIB_ALWAYS_INLINE bool nlib_is_error(bool result) NLIB_NOEXCEPT { return !result; }
765 NLIB_ALWAYS_INLINE bool nlib_is_error(errno_t e) NLIB_NOEXCEPT { return e != 0; }
766 NLIB_ALWAYS_INLINE bool nlib_is_error(const NLIB_NS::ErrnoT& e) NLIB_NOEXCEPT { return e != 0; }
767 template<class T>
769 #ifdef NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS
770  return !obj.operator bool();
771 #else
772  return !obj;
773 #endif
774 }
775 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
776 template<class T>
777 bool nlib_is_error(T*) = delete; // NOLINT
778 #else
779 template<class T>
780 bool nlib_is_error(T*); // NOLINT
781 #endif
782 
783 #endif // __cplusplus
784 
785 #if defined(_MSC_VER)
786 #if defined(n_EXPORTS)
787 #undef NLIB_VIS_PUBLIC
788 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
789 #elif defined(nx_misc_EXPORTS)
790 #undef NLIB_VIS_PUBLIC
791 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
792 #endif
793 #endif
794 
795 #endif // INCLUDE_NN_NLIB_CONFIG_H_
errno_t nlib_utf32_to_utf8(size_t *utf8count, nlib_utf8_t(&utf8)[N], const nlib_utf32_t *utf32) noexcept
The function template version of nlib_utf32_to_utf8.
Definition: Config.h:705
#define NLIB_NORETURN
Indicates that the process will not return from functions.
Class that wraps the char array storing UTF-8. This class improves visual representations of UTF-8 in...
Definition: Config.h:539
errno_t nlib_memutf16_to_utf8(size_t *to_count, size_t *from_count, nlib_utf8_t(&to)[N], const nlib_utf16_t *from, size_t from_size) noexcept
The function template version of nlib_memutf16_to_utf8().
Definition: Config.h:717
errno_t nlib_utf8_to_wide(size_t *result, wchar_t(&wcstr)[N], const nlib_utf8_t *utf8) noexcept
The function template version of nlib_utf8_to_wide.
Definition: Config.h:687
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:97
errno_t nlib_memutf8_to_wide(size_t *to_count, size_t *from_count, wchar_t(&to)[N], const nlib_utf8_t *from, size_t from_size) noexcept
The function template version of nlib_memutf8_to_wide().
Definition: Config.h:752
errno_t nlib_vsnwprintf(size_t *count, wchar_t(&buf)[N], const wchar_t *fmt, va_list args) noexcept
The function template version of nlib_vsnwprintf.
Definition: Config.h:579
errno_t nlib_utf8_to_utf16(size_t *utf16count, nlib_utf16_t(&utf16)[N], const nlib_utf8_t *utf8) noexcept
The function template version of nlib_utf8_to_utf16.
Definition: Config.h:699
errno_t nlib_strncpy(char(&s1)[N], const char *s2, size_t n) noexcept
The function template version of nlib_strncpy.
Definition: Config.h:658
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are equal.
Definition: NMalloc.h:145
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are not equal.
Definition: NMalloc.h:150
errno_t nlib_memutf32_to_utf8(size_t *to_count, size_t *from_count, nlib_utf8_t(&to)[N], const nlib_utf32_t *from, size_t from_size) noexcept
The function template version of nlib_memutf32_to_utf8().
Definition: Config.h:731
errno_t nlib_snwprintf(size_t *count, wchar_t(&buf)[N], const wchar_t *fmt,...) noexcept
The function template version of nlib_snwprintf.
Definition: Config.h:588
#define NLIB_VIS_HIDDEN
Symbols for functions and classes are not made available outside of the library.
Definition: Platform_unix.h:88
Basic APIs are declared with a C linkage.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
errno_t nlib_snprintf(size_t *count, char(&buf)[N], const char *fmt,...) noexcept
The function template version of nlib_snprintf.
Definition: Config.h:566
errno_t nlib_utf16_to_utf8(size_t *utf8count, nlib_utf8_t(&utf8)[N], const nlib_utf16_t *utf16) noexcept
The function template version of nlib_utf16_to_utf8.
Definition: Config.h:693
uint32_t nlib_utf32_t
Uses typedef to define as char32_t if that can be used. If not, it uses typedef to define as uint32_t...
Definition: Platform.h:286
errno_t nlib_utf8_to_utf32(size_t *utf32count, nlib_utf32_t(&utf32)[N], const nlib_utf8_t *utf8) noexcept
The function template version of nlib_utf8_to_utf32.
Definition: Config.h:711
errno_t nlib_memutf8_to_utf32(size_t *to_count, size_t *from_count, nlib_utf32_t(&to)[N], const nlib_utf8_t *from, size_t from_size) noexcept
The function template version of nlib_memutf8_to_utf32().
Definition: Config.h:738
An empty structure indicating that an argument to a function needs to be moved.
Definition: Config.h:249
uint16_t nlib_utf16_t
Uses typedef to define as char16_t if that can be used. If not, it uses typedef to define as uint16_t...
Definition: Platform.h:285
Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger...
Definition: Config.h:492
errno_t nlib_memutf8_to_utf16(size_t *to_count, size_t *from_count, nlib_utf16_t(&to)[N], const nlib_utf8_t *from, size_t from_size) noexcept
The function template version of nlib_memutf8_to_utf16().
Definition: Config.h:724
Implements stream-related classes usually commonly used, various containers, and other gadget classes...
Definition: Base64.h:21
errno_t nlib_memwide_to_utf8(size_t *to_count, size_t *from_count, nlib_utf8_t(&to)[N], const wchar_t *from, size_t from_size) noexcept
The function template version of nlib_memwide_to_utf8().
Definition: Config.h:745
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:93
Class that wraps const char* storing UTF-8. This class improves visual representations of UTF-8 in th...
Definition: Config.h:526
errno_t nlib_vsnprintf(size_t *count, char(&buf)[N], const char *fmt, va_list args) noexcept
The function template version of nlib_vsnprintf.
Definition: Config.h:557
errno_t nlib_wcscpy(wchar_t(&s1)[N], const wchar_t *s2) noexcept
The function template version of nlib_wcscpy.
Definition: Config.h:666
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
#define NLIB_STATIC_ASSERT(exp)
Defines a static assertion. Uses static_assert if it is available for use.
Definition: Config.h:154
size_t nlib_strlcpy(char(&s1)[N], const char *s2) noexcept
Calls the nlib_strlcpy(s1, s2, N) function.
Definition: Config.h:652
#define nlib_thread_exit_cpp
Ends the called thread.
errno_t nlib_wcsncpy(wchar_t(&s1)[N], const wchar_t *s2, size_t n) noexcept
The function template version of nlib_wcsncpy.
Definition: Config.h:673
errno_t nlib_strcpy(char(&s1)[N], const char *s2) noexcept
The function template version of nlib_strcpy.
Definition: Config.h:645
bool nlib_is_error(const T &obj) noexcept
Returns true when the process result or object status is in an erroneous condition.
Definition: Config.h:768
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:300
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37
errno_t nlib_wide_to_utf8(size_t *result, nlib_utf8_t(&utf8)[N], const wchar_t *wcstr) noexcept
The function template version of nlib_wide_to_utf8.
Definition: Config.h:681