nlib
Config.h
[詳解]
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 __cpp_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 __cpp_constexpr
93 # define NLIB_CEXPR constexpr
94 # if __cpp_constexpr >= 201304L
95 # define NLIB_CEXPR14 constexpr
96 # else
97 # define NLIB_CEXPR14
98 # endif
99 #else
100 # define NLIB_CEXPR
101 # define NLIB_CEXPR14
102 #endif
103 
104 #ifdef NLIB_DOXYGEN
105 #define NLIB_NOEXCEPT noexcept
106 #define NLIB_NOEXCEPT_FUNCPTR
107 #define NLIB_CEXPR constexpr
108 #define NLIB_CEXPR14 constexpr
109 #define NLIB_DEPRECATED [[deprecated]] // NOLINT
110 #define NLIB_DEPRECATED_MSG(x) [[deprecated(x)]] // NOLINT
111 #endif
112 
113 #ifndef NLIB_NOEXCEPT
114 #ifdef NLIB_CXX11_NOEXCEPT
115 # define NLIB_NOEXCEPT noexcept
116 #else
117 # define NLIB_NOEXCEPT throw()
118 #endif
119 #elif defined(__INTELLISENSE__)
120 # undef NLIB_NOEXCEPT
121 # define NLIB_NOEXCEPT
122 #endif
123 
124 #ifndef NLIB_NOEXCEPT_FUNCPTR
125 #define NLIB_NOEXCEPT_FUNCPTR
126 #endif
127 
128 struct nlib_unwind_exception {}; // Do not throw this directly
129 #ifndef NLIB_RETHROW_UNWIND
130 # define NLIB_RETHROW_UNWIND catch (nlib_unwind_exception&)
131 #endif
132 
133 #ifndef NLIB_ASSERT_NOERR
134 # define NLIB_ASSERT_NOERR(e) NLIB_ASSERT((e) == 0)
135 #endif
136 
137 #ifdef __cpp_exceptions
138 # define NLIB_TRY try
139 # define NLIB_CATCH(x) catch(x)
140 # define NLIB_THROW throw
141 #else
142 # define NLIB_TRY if (true)
143 # define NLIB_CATCH(x) if (false)
144 # define NLIB_THROW
145 #endif
146 
147 #ifndef NLIB_STATIC_ASSERT
148 #ifndef __cpp_static_assert
149 NLIB_NAMESPACE_BEGIN
150 namespace detail {
151 template <bool>
152 struct STATIC_ASSERTION_FAILURE;
153 template <>
154 struct STATIC_ASSERTION_FAILURE<true> {};
155 template <int x>
156 struct static_assert_test {};
157 } // namespace detail
158 NLIB_NAMESPACE_END
159 
160 #define NLIB_ASSERT_H_STRING_JOIN_(X, Y) NLIB_ASSERT_H_STRING_JOIN1_(X, Y)
161 #define NLIB_ASSERT_H_STRING_JOIN1_(X, Y) X##Y
162 
163 #define NLIB_STATIC_ASSERT(exp) \
164  typedef ::nlib_ns::detail::static_assert_test< \
165  sizeof(::nlib_ns::detail::STATIC_ASSERTION_FAILURE<(exp) != 0>)> \
166  NLIB_ASSERT_H_STRING_JOIN_(nn_static_assert_typedef_, __LINE__)
167 #elif __cpp_static_assert >= 201411L
168 # define NLIB_STATIC_ASSERT(exp) static_assert(exp)
169 #else
170 # define NLIB_STATIC_ASSERT(exp) static_assert((exp), "NLIB_STATIC_ASSERT error: " #exp)
171 #endif
172 #endif
173 
174 #ifndef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
175 #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
176 TypeName(const TypeName&); \
177 void operator=(const TypeName&)
178 #else
179 #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName) \
180 TypeName(const TypeName&) = delete; \
181 void operator=(const TypeName&) = delete
182 #endif
183 
184 #ifndef NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS
185 #define NLIB_SAFE_BOOL(class_name, exp) \
186 private: \
187  typedef void (class_name::*bool_type)() const; \
188  void this_type_does_not_support_comparisons() const NLIB_NOEXCEPT {} \
189 public: \
190  operator bool_type() const NLIB_NOEXCEPT { \
191  return (exp) ? &class_name::this_type_does_not_support_comparisons : 0; \
192  }
193 #else
194 #define NLIB_SAFE_BOOL(class_name, exp) \
195 public: \
196  explicit NLIB_ALWAYS_INLINE operator bool() const NLIB_NOEXCEPT { return (exp); }
197 #endif
198 
199 #include <wchar.h> // NOLINT
200 #if defined(WCHAR_MIN) && defined(WCHAR_MAX)
201 # if WCHAR_MAX <= 0xFFFF
202 # define NLIB_WCHAR_SIZE (2)
203 NLIB_STATIC_ASSERT(sizeof(wchar_t) == 2);
204 # else
205 # define NLIB_WCHAR_SIZE (4)
206 NLIB_STATIC_ASSERT(sizeof(wchar_t) == 4);
207 # endif
208 #else
209 # error WCHAR_MIN, WCHAR_MAX not defined
210 #endif
211 
212 #ifndef NLIB_CXX11_NULL_POINTER_CONSTANT
213 NLIB_NAMESPACE_BEGIN
214 class nullptr_t {
215  public:
216  template <class T>
217  operator T*() const {
218  return 0;
219  }
220  template <class C, class T>
221  operator T C::*() const {
222  return 0;
223  }
224 
225  private:
226  void operator&() const; // NOLINT
227 };
228 #ifndef nullptr
229 // if nullptr macro is defined, just use it.
230 const nullptr_t nullptr = {};
231 #endif
232 NLIB_NAMESPACE_END
233 #else
234 #include <cstddef> // NOLINT this is because stddef.h does not define std::nullptr_t
235 NLIB_NAMESPACE_BEGIN
236 typedef std::nullptr_t nullptr_t;
237 NLIB_NAMESPACE_END
238 #endif
239 
240 #ifndef NLIB_CXX11_EXPLICIT_VIRTUAL_OVERRIDES
241 # define NLIB_OVERRIDE
242 # define NLIB_FINAL
243 #else
244 # define NLIB_OVERRIDE override
245 # define NLIB_FINAL final
246 #endif
247 
248 #ifdef NLIB_CXX11_ALIGNMENT_SUPPORT
249 # ifdef NLIB_ALIGNAS
250 # undef NLIB_ALIGNAS
251 # endif
252 # ifdef NLIB_ALIGNOF
253 # undef NLIB_ALIGNOF
254 # endif
255 # define NLIB_ALIGNAS(x) alignas(x)
256 # define NLIB_ALIGNOF(tp) alignof(tp)
257 #endif
258 
259 #ifdef __cpp_rvalue_references
260 // for std::move
261 # include <utility> // NOLINT
262 #endif
263 
264 NLIB_NAMESPACE_BEGIN
265 struct move_tag {};
266 NLIB_NAMESPACE_END
267 
268 #ifdef __cpp_rvalue_references
269 #define NLIB_DEFMOVE_PIMPL(tp) \
270  NLIB_ALWAYS_INLINE tp(tp&& rhs) NLIB_NOEXCEPT : prv_(rhs.prv_) { \
271  rhs.prv_ = nullptr; \
272  } \
273  NLIB_ALWAYS_INLINE tp& operator=(tp&& rhs) NLIB_NOEXCEPT { \
274  Reset(); \
275  prv_ = rhs.prv_; \
276  rhs.prv_ = nullptr; \
277  return *this; \
278  } \
279  NLIB_ALWAYS_INLINE \
280  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : prv_(rhs.prv_) /* NOLINT */ { \
281  rhs.prv_ = nullptr; \
282  } \
283  NLIB_ALWAYS_INLINE \
284  tp& assign(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT { /* NOLINT */ \
285  Reset(); \
286  prv_ = rhs.prv_; \
287  rhs.prv_ = nullptr; \
288  return *this; \
289  }
290 #else
291 #define NLIB_DEFMOVE_PIMPL(tp) \
292  NLIB_ALWAYS_INLINE \
293  tp(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT : prv_(rhs.prv_) /* NOLINT */ { \
294  rhs.prv_ = nullptr; \
295  } \
296  NLIB_ALWAYS_INLINE \
297  tp& assign(tp& rhs, ::nlib_ns::move_tag) NLIB_NOEXCEPT { /* NOLINT */ \
298  Reset(); \
299  prv_ = rhs.prv_; \
300  rhs.prv_ = nullptr; \
301  return *this; \
302  }
303 #endif
304 
305 #ifndef NLIB_MEMCHECKER
306 # define NLIB_MEMCHECKER NLIB_STATIC_ASSERT(sizeof(char) == 1) // NOLINT
307 # define NLIB_MEMCHECKER_START NLIB_STATIC_ASSERT(sizeof(char) == 1) // NOLINT
308 # define NLIB_MEMCHECKER_CHECK true
309 #endif
310 
311 // The following macro "NLIB_NOEMPTYFILE()" can be put into a file
312 // in order suppress the MS Visual C++ Linker warning 4221
313 #ifndef NLIB_NOEMPTYFILE
314 # define NLIB_NOEMPTYFILE()
315 #endif
316 
317 #ifdef NLIB_SOCKET_ENABLED
318 # ifdef _MSC_VER
319 # ifndef NLIB_WINDLL
320 # ifdef _DEBUG
321 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 50)
322 # else
323 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER)
324 # endif
325 # else
326 # ifdef _DEBUG
327 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 75)
328 # else
329 # define NLIB_SOCKPORT_SAMPLE (17974 + _MSC_VER + 25)
330 # endif
331 # endif
332 # elif defined(__clang__)
333 # ifdef NDEBUG
334 # define NLIB_SOCKPORT_SAMPLE (18174)
335 # else
336 # define NLIB_SOCKPORT_SAMPLE (18074)
337 # endif
338 # else
339 # ifdef NDEBUG
340 # define NLIB_SOCKPORT_SAMPLE (17874)
341 # else
342 # define NLIB_SOCKPORT_SAMPLE (17974)
343 # endif
344 # endif
345 #endif
346 
347 //
348 // You can reduce the loopcount for the performance test
349 // when it runs on on a continuous integration system like Jenkins.
350 //
351 // for (int i = 0; i < NLIB_TESTLOOPCOUNT(10000); ++i) {
352 // .....
353 // }
354 //
355 #if !defined(NLIB_CIBUILD) && defined(NDEBUG)
356 # define NLIB_TESTLOOPCOUNT(x) (x)
357 #else
358 # define NLIB_TESTLOOPCOUNT(x) (1)
359 #endif
360 
361 #ifndef NLIB_OVERRIDE_NEW
362 #define NLIB_OVERRIDE_NEW \
363  static void* operator new(size_t size); \
364  static void operator delete(void* ptr); \
365  static void* operator new(size_t size, void* ptr) NLIB_NOEXCEPT; \
366  static void operator delete(void* mem, void* ptr) NLIB_NOEXCEPT; \
367  static void* operator new(size_t size, const std::nothrow_t& nt) NLIB_NOEXCEPT; \
368  static void operator delete(void* mem, const std::nothrow_t& nt) NLIB_NOEXCEPT
369 #endif
370 
371 #ifndef NLIB_OVERRIDE_NEW_LIBNEW_CPP
372 #define NLIB_OVERRIDE_NEW_LIBNEW_CPP(type) \
373  void* type::operator new(size_t size) { return ::operator new(size); } \
374  void type::operator delete(void* ptr) { ::operator delete(ptr); } \
375  void* type::operator new(size_t size, void* ptr) NLIB_NOEXCEPT { \
376  return ::operator new(size, ptr); \
377  } \
378  void type::operator delete(void* mem, void* ptr) NLIB_NOEXCEPT { \
379  ::operator delete(mem, ptr); \
380  } \
381  void* type::operator new(size_t size, const std::nothrow_t& nt) NLIB_NOEXCEPT { \
382  return ::operator new(size, nt); \
383  } \
384  void type::operator delete(void* mem, const std::nothrow_t& nt) NLIB_NOEXCEPT { \
385  NLIB_UNUSED(nt); \
386  ::operator delete(mem); \
387  }
388 #endif
389 
390 #define NLIB_EQUAL_OPERATOR(TP) \
391 NLIB_ALWAYS_INLINE bool operator!=(const TP& lhs, const TP& rhs) NLIB_NOEXCEPT { \
392  return !(lhs == rhs); \
393 }
394 #define NLIB_COMPARE_OPERATOR(TP) \
395 NLIB_ALWAYS_INLINE bool operator>(const TP& lhs, const TP& rhs) NLIB_NOEXCEPT { \
396  return rhs < lhs; \
397 } \
398 NLIB_ALWAYS_INLINE bool operator<=(const TP& lhs, const TP& rhs) NLIB_NOEXCEPT { \
399  return !(rhs < lhs); \
400 } \
401 NLIB_ALWAYS_INLINE bool operator>=(const TP& lhs, const TP& rhs) NLIB_NOEXCEPT { \
402  return !(lhs < rhs); \
403 }
404 
405 NLIB_NAMESPACE_BEGIN
407  public:
408  ErrnoT() NLIB_NOEXCEPT : vs_errno_(0) {}
409  NLIB_CEXPR ErrnoT(errno_t e) NLIB_NOEXCEPT : vs_errno_(e) {} // NOLINT
410  ErrnoT& operator=(errno_t e) NLIB_NOEXCEPT {
411  vs_errno_ = e;
412  return *this;
413  }
414  operator errno_t() const NLIB_NOEXCEPT { return vs_errno_; }
415  // const char* c_str() const NLIB_NOEXCEPT { return nlib_error_string(vs_errno_); }
416 
417  private:
418  // to suppress the mix-up with boolean value
419  bool operator!() const; // FORBIDDEN
420  // operator bool() const; // FORBIDDEN
421  errno_t vs_errno_;
422 };
423 
425  return lhs.operator errno_t() == rhs;
426 }
427 
429  return rhs.operator errno_t() == lhs;
430 }
431 
433  return lhs.operator errno_t() != rhs;
434 }
435 
437  return rhs.operator errno_t() != lhs;
438 }
439 
441  public:
442  Utf8Ptr() NLIB_NOEXCEPT : str_(nullptr) {}
443  Utf8Ptr(const char* str) NLIB_NOEXCEPT : str_(str) {} // NOLINT
444  operator const char*() const NLIB_NOEXCEPT { return str_; }
445  Utf8Ptr& operator=(const char* str) NLIB_NOEXCEPT { str_ = str; return *this; }
446  const char& operator[](size_t idx) const NLIB_NOEXCEPT { return str_[idx]; }
447 
448  private:
449  const char* str_;
450 };
451 
452 template<size_t N>
454  public:
456  operator char*() NLIB_NOEXCEPT { return &str_[0]; }
457  operator const char*() const NLIB_NOEXCEPT { return &str_[0]; }
458  const char& operator[](size_t idx) const NLIB_NOEXCEPT { return str_[idx]; }
459  char& operator[](size_t idx) NLIB_NOEXCEPT { return str_[idx]; }
460 
461  private:
462  char str_[N];
463 };
464 NLIB_NAMESPACE_END
465 
466 //
467 // C++ functions in global namespace
468 //
469 #ifdef __cplusplus
470 template <size_t N>
472  size_t* count,
473  char (&buf)[N],
474  _Printf_format_string_ const char* fmt,
475  va_list args) NLIB_NOEXCEPT {
476  return nlib_vsnprintf(count, buf, N, fmt, args);
477 }
478 
479 template<size_t N>
481  size_t* count,
482  char (&buf)[N],
483  _Printf_format_string_ const char* fmt,
484  ...) NLIB_NOEXCEPT {
485  va_list args;
486  va_start(args, fmt);
487  errno_t e = nlib_vsnprintf(count, buf, N, fmt, args);
488  va_end(args);
489  return e;
490 }
491 
492 template <size_t N>
494  size_t* count,
495  wchar_t (&buf)[N],
496  _Printf_format_string_ const wchar_t* fmt,
497  va_list args) NLIB_NOEXCEPT {
498  return nlib_vsnwprintf(count, buf, N, fmt, args);
499 }
500 
501 template<size_t N>
503  size_t* count,
504  wchar_t(&buf)[N],
505  _Printf_format_string_ const wchar_t* fmt,
506  ...) NLIB_NOEXCEPT {
507  va_list args;
508  va_start(args, fmt);
509  errno_t e = nlib_vsnwprintf(count, buf, N, fmt, args);
510  va_end(args);
511  return e;
512 }
513 
514 template <size_t N>
515 NLIB_ALWAYS_INLINE errno_t nlib_vsnprintf_fallback(
516  size_t* count,
517  char (&buf)[N],
518  _Printf_format_string_ const char* fmt,
519  va_list args) NLIB_NOEXCEPT {
520  return nlib_vsnprintf_fallback(count, buf, N, fmt, args);
521 }
522 
523 template<size_t N>
524 inline NLIB_VIS_HIDDEN errno_t nlib_snprintf_fallback(
525  size_t* count,
526  char (&buf)[N],
527  _Printf_format_string_ const char* fmt,
528  ...) NLIB_NOEXCEPT {
529  va_list args;
530  va_start(args, fmt);
531  errno_t e = nlib_vsnprintf_fallback(count, buf, N, fmt, args);
532  va_end(args);
533  return e;
534 }
535 
536 template <size_t N>
537 NLIB_ALWAYS_INLINE errno_t nlib_vsnwprintf_fallback(
538  size_t* count,
539  wchar_t (&buf)[N],
540  _Printf_format_string_ const wchar_t* fmt,
541  va_list args) NLIB_NOEXCEPT {
542  return nlib_vsnwprintf_fallback(count, buf, N, fmt, args);
543 }
544 
545 template<size_t N>
546 inline NLIB_VIS_HIDDEN errno_t nlib_snwprintf_fallback(
547  size_t* count,
548  wchar_t(&buf)[N],
549  _Printf_format_string_ const wchar_t* fmt,
550  ...) NLIB_NOEXCEPT {
551  va_list args;
552  va_start(args, fmt);
553  errno_t e = nlib_vsnwprintf_fallback(count, buf, N, fmt, args);
554  va_end(args);
555  return e;
556 }
557 
558 template <size_t N>
560  char (&s1)[N],
561  const char* s2) NLIB_NOEXCEPT {
562  return nlib_strcpy(&s1[0], N, s2);
563 }
564 
565 template<size_t N>
566 NLIB_ALWAYS_INLINE size_t nlib_strlcpy(char (&s1)[N], const char* s2) NLIB_NOEXCEPT {
567  // CTR armcc needs cast
568  return nlib_strlcpy((char*)&s1[0], (const char*)s2, N); // NOLINT
569 }
570 
571 template <size_t N>
573  char (&s1)[N],
574  const char* s2,
575  size_t n) NLIB_NOEXCEPT {
576  return nlib_strncpy(&s1[0], N, s2, n);
577 }
578 
579 template <size_t N>
581  wchar_t (&s1)[N],
582  const wchar_t* s2) NLIB_NOEXCEPT {
583  return nlib_wcscpy(&s1[0], N, s2);
584 }
585 
586 template <size_t N>
588  wchar_t (&s1)[N],
589  const wchar_t* s2,
590  size_t n) NLIB_NOEXCEPT {
591  return nlib_wcsncpy(&s1[0], N, s2, n);
592 }
593 
594 template<size_t N>
596  const wchar_t* wcstr) NLIB_NOEXCEPT {
597  return nlib_wide_to_utf8(result, &utf8[0], N, wcstr);
598 }
599 
600 template<size_t N>
601 NLIB_ALWAYS_INLINE errno_t nlib_utf8_to_wide(size_t* result, wchar_t (&wcstr)[N],
602  const nlib_utf8_t* utf8) NLIB_NOEXCEPT {
603  return nlib_utf8_to_wide(result, &wcstr[0], N, utf8);
604 }
605 
606 template<size_t N>
608  const nlib_utf16_t* utf16) NLIB_NOEXCEPT {
609  return nlib_utf16_to_utf8(utf8count, &utf8[0], N, utf16);
610 }
611 
612 template<size_t N>
614  const nlib_utf8_t* utf8) NLIB_NOEXCEPT {
615  return nlib_utf8_to_utf16(utf16count, &utf16[0], N, utf8);
616 }
617 
618 template<size_t N>
620  const nlib_utf32_t* utf32) NLIB_NOEXCEPT {
621  return nlib_utf32_to_utf8(utf8count, &utf8[0], N, utf32);
622 }
623 
624 template<size_t N>
626  const nlib_utf8_t* utf8) NLIB_NOEXCEPT {
627  return nlib_utf8_to_utf32(utf32count, &utf32[0], N, utf8);
628 }
629 
630 template<size_t N>
632  size_t* to_count, size_t* from_count,
633  nlib_utf8_t (&to)[N],
634  const nlib_utf16_t* from, size_t from_size) NLIB_NOEXCEPT {
635  return nlib_memutf16_to_utf8(to_count, from_count, &to[0], N, from, from_size);
636 }
637 template<size_t N>
639  size_t* to_count, size_t* from_count,
640  nlib_utf16_t (&to)[N],
641  const nlib_utf8_t* from, size_t from_size) NLIB_NOEXCEPT {
642  return nlib_memutf8_to_utf16(to_count, from_count, &to[0], N, from, from_size);
643 }
644 template<size_t N>
646  size_t* to_count, size_t* from_count,
647  nlib_utf8_t (&to)[N],
648  const nlib_utf32_t* from, size_t from_size) NLIB_NOEXCEPT {
649  return nlib_memutf32_to_utf8(to_count, from_count, &to[0], N, from, from_size);
650 }
651 template<size_t N>
653  size_t* to_count, size_t* from_count,
654  nlib_utf32_t (&to)[N],
655  const nlib_utf8_t* from, size_t from_size) NLIB_NOEXCEPT {
656  return nlib_memutf8_to_utf32(to_count, from_count, &to[0], N, from, from_size);
657 }
658 template<size_t N>
660  size_t* to_count, size_t* from_count,
661  nlib_utf8_t (&to)[N],
662  const wchar_t* from, size_t from_size) NLIB_NOEXCEPT {
663  return nlib_memwide_to_utf8(to_count, from_count, &to[0], N, from, from_size);
664 }
665 template<size_t N>
667  size_t* to_count, size_t* from_count,
668  wchar_t (&to)[N],
669  const nlib_utf8_t* from, size_t from_size) NLIB_NOEXCEPT {
670  return nlib_memutf8_to_wide(to_count, from_count, &to[0], N, from, from_size);
671 }
672 
673 #if !defined(NN_PLATFORM_CTR) && !defined(CAFE)
674 // This may throw C++ exception defined by nlib, See also nlib_thread_exit()
676 #endif
677 
678 NLIB_ALWAYS_INLINE bool nlib_is_error(bool result) NLIB_NOEXCEPT { return !result; }
679 NLIB_ALWAYS_INLINE bool nlib_is_error(errno_t e) NLIB_NOEXCEPT { return e != 0; }
680 NLIB_ALWAYS_INLINE bool nlib_is_error(const NLIB_NS::ErrnoT& e) NLIB_NOEXCEPT { return e != 0; }
681 template<class T>
683 #ifdef NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS
684  return !obj.operator bool();
685 #else
686  return !obj;
687 #endif
688 }
689 #ifdef NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
690 template<class T>
691 bool nlib_is_error(T*) = delete; // NOLINT
692 #else
693 template<class T>
694 bool nlib_is_error(T*); // NOLINT
695 #endif
696 
697 #endif // __cplusplus
698 
699 #if defined(_MSC_VER)
700 #if defined(n_EXPORTS)
701 #undef NLIB_VIS_PUBLIC
702 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
703 #elif defined(nx_misc_EXPORTS)
704 #undef NLIB_VIS_PUBLIC
705 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
706 #endif
707 #endif
708 
709 #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
nlib_utf32_to_utf8()の関数テンプレート版です。
Definition: Config.h:619
#define NLIB_NORETURN
関数がリターンしないことを示します。
UTF-8を格納するcharの配列をラップするクラスです。Visual Studioのデバッガ上でのUTF-8の表示を改善します...
Definition: Config.h:453
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
nlib_memutf16_to_utf8()の関数テンプレート版です。
Definition: Config.h:631
errno_t nlib_utf8_to_wide(size_t *result, wchar_t(&wcstr)[N], const nlib_utf8_t *utf8) noexcept
nlib_utf8_to_wide()の関数テンプレート版です。
Definition: Config.h:601
#define NLIB_ALWAYS_INLINE
コンパイラに関数をインライン展開するように強く示します。
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
nlib_memutf8_to_wide()の関数テンプレート版です。
Definition: Config.h:666
errno_t nlib_vsnwprintf(size_t *count, wchar_t(&buf)[N], const wchar_t *fmt, va_list args) noexcept
nlib_vsnwprintf()の関数テンプレート版です。
Definition: Config.h:493
errno_t nlib_utf8_to_utf16(size_t *utf16count, nlib_utf16_t(&utf16)[N], const nlib_utf8_t *utf8) noexcept
nlib_utf8_to_utf16()の関数テンプレート版です。
Definition: Config.h:613
errno_t nlib_strncpy(char(&s1)[N], const char *s2, size_t n) noexcept
nlib_strncpy()の関数テンプレート版です。
Definition: Config.h:572
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価ならば、trueを返します。
Definition: NMalloc.h:149
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価でなければ、trueを返します。
Definition: NMalloc.h:154
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
nlib_memutf32_to_utf8()の関数テンプレート版です。
Definition: Config.h:645
errno_t nlib_snwprintf(size_t *count, wchar_t(&buf)[N], const wchar_t *fmt,...) noexcept
nlib_snwprintf()の関数テンプレート版です。
Definition: Config.h:502
#define NLIB_VIS_HIDDEN
関数やクラス等のシンボルをライブラリの外部に公開しません。
Definition: Platform_unix.h:88
基本的なAPIがCリンケージで宣言されています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
errno_t nlib_snprintf(size_t *count, char(&buf)[N], const char *fmt,...) noexcept
nlib_snprintf() の関数テンプレート版です。
Definition: Config.h:480
errno_t nlib_utf16_to_utf8(size_t *utf8count, nlib_utf8_t(&utf8)[N], const nlib_utf16_t *utf16) noexcept
nlib_utf16_to_utf8()の関数テンプレート版です。
Definition: Config.h:607
uint32_t nlib_utf32_t
char32_tが利用できる場合はchar32_tに、そうでない場合はuint32_tにtypedefされます。 ...
Definition: Platform.h:294
errno_t nlib_utf8_to_utf32(size_t *utf32count, nlib_utf32_t(&utf32)[N], const nlib_utf8_t *utf8) noexcept
nlib_utf8_to_utf32()の関数テンプレート版です。
Definition: Config.h:625
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
nlib_memutf8_to_utf32()の関数テンプレート版です。
Definition: Config.h:652
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
Definition: Config.h:265
uint16_t nlib_utf16_t
char16_tが利用できる場合はchar16_tに、そうでない場合はuint16_tにtypedefされます。 ...
Definition: Platform.h:293
errno_tをラップするクラスです。Visual Studioのデバッガ上での表示を改善します。
Definition: Config.h:406
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
nlib_memutf8_to_utf16()の関数テンプレート版です。
Definition: Config.h:638
共通して使われることの多いストリーム関連のクラス群や各種コンテナ、及びガシェットクラスが実装されてい...
Definition: Base64.h:25
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
nlib_memwide_to_utf8()の関数テンプレート版です。
Definition: Config.h:659
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
UTF-8を格納するconst char*をラップするクラスです。Visual Studioのデバッガ上でのUTF-8の表示を改善しま...
Definition: Config.h:440
errno_t nlib_vsnprintf(size_t *count, char(&buf)[N], const char *fmt, va_list args) noexcept
nlib_vsnprintf() の関数テンプレート版です。
Definition: Config.h:471
errno_t nlib_wcscpy(wchar_t(&s1)[N], const wchar_t *s2) noexcept
nlib_wcscpy()の関数テンプレート版です。
Definition: Config.h:580
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
Definition: Config.h:170
size_t nlib_strlcpy(char(&s1)[N], const char *s2) noexcept
nlib_strlcpy(s1, s2, N)を呼び出します。
Definition: Config.h:566
#define nlib_thread_exit_cpp
呼び出しスレッドを終了します。
errno_t nlib_wcsncpy(wchar_t(&s1)[N], const wchar_t *s2, size_t n) noexcept
nlib_wcsncpy()の関数テンプレート版です。
Definition: Config.h:587
errno_t nlib_strcpy(char(&s1)[N], const char *s2) noexcept
nlib_strcpy()の関数テンプレート版です。
Definition: Config.h:559
bool nlib_is_error(const T &obj) noexcept
処理の結果やオブジェクトの状態がエラーである場合にtrueを返します。
Definition: Config.h:682
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:308
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37
errno_t nlib_wide_to_utf8(size_t *result, nlib_utf8_t(&utf8)[N], const wchar_t *wcstr) noexcept
nlib_wide_to_utf8()の関数テンプレート版です。
Definition: Config.h:595