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