nlib
nn::nlib Namespace Reference

Implements stream-related classes usually commonly used, various containers, and other gadget classes. nlib_ns is an alias. More...

Namespaces

 binary_reader
 Defines functions that are used to read to user-defined classes with the BinaryReader class.
 
 binary_writer
 Defines functions that are used to write user-defined classes with the BinaryWriter class.
 
 exi
 Implements binary XML parsers (and XML parsers).
 
 handle_maker
 Namespace in which a function template to customize the HandleMaker class is defined.
 
 heap
 Namespace for the heap library. Functions such as nmalloc and nfree are defined in the global namespace.
 
 msgpack
 Support for the JSON/msgpack parser and writer, JSON Pointer, JSON Patch, and JSON Schema, etc. has been implemented.
 
 oss
 Implements a library for open-source software (OSS), code derived from OSS, and for accessing OSS.
 
 simd
 Implements the classes and functions for SIMD computations on integers and single-precision, floating-point, numbers.
 
 succinct
 Implements a library of succinct data structure classes related to bit vectors.
 
 testing
 Framework to test C++ code. View the description of List of testing Library Features.
 
 threading
 Unicode related functionality is implemented.
 
 unicode
 Unicode-related functionality is implemented.
 

Classes

class  Base64Decoder
 Decodes Base64. This class supports various variants of Base64. More...
 
class  Base64Encoder
 Encodes Base64. This class supports various variants of Base64. More...
 
class  Base64InputStream
 The class for reading Base64-encoded data. More...
 
class  Base64OutputStream
 The class for writing data after encoding it in Base64. More...
 
class  BinaryReader
 The class for reading binary from streams (from InputStream). More...
 
class  BinaryWriter
 The class for writing binary to streams (to OutputStream). More...
 
class  ConsoleOutputStream
 The class for creating a stream to output to the console as a text string using nlib_printf. More...
 
class  ConstructorForLockFree
 Class template for initializing an object. This should be specialized before use. More...
 
class  CurlInputStream
 The stream class for downloading using libcurl. More...
 
class  DateTime
 The class for representing the date and time. More...
 
struct  DateTimeParams
 The structure for setting date and time information in DateTime and for getting that information from the object. More...
 
class  DestructorForLockFree
 Class template for destructing an object. This should be specialized before use. More...
 
class  DynamicAlignedStorage
 A class for obtaining aligned memory. More...
 
class  ErrnoT
 Class that wraps errno_t. This class improves visual representations in the Visual Studio debugger. More...
 
class  FileInputStream
 The class for file input streams. More...
 
struct  FileInputStreamSettings
 The structure that stores information about the file stream settings. More...
 
class  FileOutputStream
 The class for file output streams. More...
 
struct  FileOutputStreamSettings
 The structure that stores information about the file stream settings. More...
 
class  GroupVarInt32
 Class for encoding and decoding four 32-bit integer values as a unit. More...
 
class  HandleAccess
 An accessor class that can access the handle instance as if it is a pointer. It becomes available after it is specified by the HandlerMaker class. More...
 
class  HandleMaker
 A class supporting the implementation of handles with a 32-bit integer value. More...
 
struct  HandleTable
 A table referencing handle instances used by the HandlerMaker class. More...
 
class  InputConverterStream
 The base class for classes that act internally like InputStream to convert data. More...
 
class  InputConverterStreamTempl
 The class for holding the InputTransform derived class. For more information, see the description of InputConverterStream. More...
 
class  InputStream
 The base class for input streams. This class cannot be instantiated. More...
 
class  LockFreeBroadcastQueue
 The specified number of listeners can obtain elements from the queue. After all the listeners have obtained elements, those elements are deleted from the queue. More...
 
class  LockFreePipe
 When a single sender thread sends data and a single receiver thread receives that data, you can use this class to transfer data in a lock-free manner. More...
 
class  LockFreePriorityQueue
 Wraps nlib_mq with a class implementing a lock-free queue with a priority set. More...
 
class  LockFreeQueue
 This class implements a lock-free queue. More...
 
class  LockFreeStack
 This class implements a lock-free stack. More...
 
class  LockFreeUnitHeap
 A pool allocator that can allocate or free a fixed size of memory region in a lock free manner. More...
 
class  MemoryInputStream
 The class for creating an input stream that makes use of memory. More...
 
class  MemoryOutputStream
 The class for creating an output stream that makes use of memory. More...
 
struct  move_tag
 An empty structure indicating that an argument to a function needs to be moved. More...
 
class  NativePathMapper
 The class for getting the native path string from the URI path notation that is not machine-dependent. More...
 
class  Nflags
 The class for parsing command line flags. More...
 
class  Nlist
 A container-like class similar to std::vector that can store objects that do not have copy constructors. More...
 
class  Nqueue
 A container-like class similar to std::queue that can store objects that do not have copy constructors. More...
 
class  NullInputStream
 The class for streams that always load 0. More...
 
class  NullOutputStream
 The class for OutputStream objects for which no actual writing takes place. More...
 
class  OutputConverterStream
 The base class for classes that act internally like OutputStream to convert data. More...
 
class  OutputConverterStreamTempl
 The class for holding the OutputTransform derived class. More...
 
class  OutputStream
 The base class for output streams. This class cannot be instantiated. More...
 
class  ReallocCstringVec
 The class for realloc-based implementations of C string vectors. More...
 
class  ReallocOutputStream
 The class for output streams written to memory expanded using nlib_realloc or another realloc function. More...
 
class  ReallocQueue
 The class for realloc-based implementations of queues with POD-type elements. More...
 
class  ReallocVec
 The class for realloc-based implementations of vectors with POD-type elements. More...
 
class  SimpleSingleton
 Singleton of the type for implicitly constructing an instance based on a static variable before calling the main function. More...
 
class  Singleton
 Singleton initialized by the object when first used. More...
 
class  SmartBitmap
 The data structure holding bit data operated on by Rank and Select. More...
 
class  SmartBitmapCrtp
 The data structure holding bit data operated on by Rank and Select. More...
 
class  SmartBitmapPtr
 The data structure holding bit data operated on by Rank and Select. More...
 
class  StringView
 The class for using the member functions of std::string without constructing std::string. This class will be defined as the string_view of C++17 using typedef. For more information about free functions taking StringView as the argument, seehere.. More...
 
class  TaggedTextParser
 A simple parser for parsing XML-like tagged text. More...
 
class  TextReader
 The class for reading text from streams. More...
 
class  TextWriter
 The class for writing text to streams. More...
 
class  TimeSpan
 The class for representing the time. More...
 
class  TimeValue
 The class that wraps 64-bit signed integers. More...
 
class  UniquePtr
 In the C++11 environment (which supports alias templates), std::unique_ptr is made an alias template. More...
 
class  Uri
 The class for parsing and constructing regular URIs. More...
 
class  UriQueryDecoder
 The class template to parse URI queries. More...
 
class  UriQueryEncoder
 The class for creating URI queries. More...
 
class  UriTemplate
 The class that supports URI Template (RFC 6570, Level 3). More...
 
class  Utf16InputStream
 The class for reading UTF-16 string streams as UTF-8. More...
 
class  Utf32InputStream
 The class for reading UTF-32 string streams as UTF-8. More...
 
class  Utf8Array
 Class that wraps the char array storing UTF-8. This class improves visual representations of UTF-8 in the Visual Studio debugger. More...
 
class  Utf8Ptr
 Class that wraps const char* storing UTF-8. This class improves visual representations of UTF-8 in the Visual Studio debugger. More...
 
class  WcharInputStream
 The class for reading string streams of wide characters (wchar_t and UTF-16 or UTF-32) as UTF-8. More...
 
class  z
 A dummy class provided for the convenience of creating a document, which does not exist. More...
 
class  ZlibInputStream
 The stream class for reading compressed data using zlib. More...
 
struct  ZlibInputStreamSettings
 The structure that stores the various ZlibInputStream settings. At construction time, the default settings are stored. More...
 
class  ZlibOutputStream
 The class that uses zlib to decompress data and write the data to a stream. More...
 
struct  ZlibOutputStreamSettings
 The structure that stores the various ZlibOutputStream settings. At construction time, the default settings are stored. More...
 

Functions

size_t StrLen (const char *str) noexcept
 Wraps the nlib_strlen function.
 
size_t StrLen (const nlib_utf16_t *str) noexcept
 Wraps the nlib_utf16len function.
 
size_t StrLen (const nlib_utf32_t *str) noexcept
 Wraps the nlib_utf32len function.
 
size_t StrLen (const wchar_t *str) noexcept
 Wraps the nlib_wcslen function.
 
errno_t CodePointCount (const char *str, size_t *count) noexcept
 Wraps the nlib_strcplen function.
 
errno_t CodePointCount (const nlib_utf16_t *str, size_t *count) noexcept
 Wraps the nlib_utf16cplen function.
 
errno_t CodePointCount (const nlib_utf32_t *str, size_t *count) noexcept
 Wraps the nlib_utf32cplen function.
 
errno_t CodePointCount (const wchar_t *str, size_t *count) noexcept
 Wraps the nlib_wcscplen function.
 
int StrCmp (const char *s1, const char *s2) noexcept
 Wraps the strcmp function.
 
int StrCmp (const wchar_t *s1, const wchar_t *s2) noexcept
 Wraps the wcscmp function.
 
int StrCmp (const nlib_utf16_t *s1, const nlib_utf16_t *s2) noexcept
 Compares UTF-16 strings in the same way as the strcmp function.
 
int StrCmp (const nlib_utf32_t *s1, const nlib_utf32_t *s2) noexcept
 Compares UTF-32 strings in the same way as the strcmp function.
 
int StrNcmp (const char *s1, const char *s2, size_t n) noexcept
 Wraps the strncmp function.
 
int StrNcmp (const wchar_t *s1, const wchar_t *s2, size_t n) noexcept
 Wraps the wcsncmp function.
 
int StrNcmp (const nlib_utf16_t *s1, const nlib_utf16_t *s2, size_t n) noexcept
 Compares UTF-16 strings in the same way as the strncmp function.
 
int StrNcmp (const nlib_utf32_t *s1, const nlib_utf32_t *s2, size_t n) noexcept
 Compares UTF-32 strings in the same way as the strncmp function.
 
errno_t StrCpy (char *dest, size_t dest_size, const char *src) noexcept
 Wraps the nlib_strcpy function.
 
errno_t StrCpy (nlib_utf16_t *dest, size_t dest_size, const nlib_utf16_t *src) noexcept
 Wraps the nlib_utf16cpy function.
 
errno_t StrCpy (nlib_utf32_t *dest, size_t dest_size, const nlib_utf32_t *src) noexcept
 Wraps the nlib_utf32cpy function.
 
errno_t StrCpy (wchar_t *dest, size_t dest_size, const wchar_t *src) noexcept
 Wraps the nlib_wcscpy function.
 
template<class T , size_t N>
errno_t StrCpy (T(&dest)[N], const T *src) noexcept
 A template overload of the above function. More...
 
errno_t StrNcpy (char *dest, size_t dest_size, const char *src, size_t n) noexcept
 Wraps the nlib_strncpy function.
 
errno_t StrNcpy (nlib_utf16_t *dest, size_t dest_size, const nlib_utf16_t *src, size_t n) noexcept
 Wraps the nlib_utf16ncpy function.
 
errno_t StrNcpy (nlib_utf32_t *dest, size_t dest_size, const nlib_utf32_t *src, size_t n) noexcept
 Wraps the nlib_utf32ncpy function.
 
errno_t StrNcpy (wchar_t *dest, size_t dest_size, const wchar_t *src, size_t n) noexcept
 Wraps the nlib_wcsncpy function.
 
template<class T , size_t N>
errno_t StrNcpy (T(&dest)[N], const T *src, size_t n) noexcept
 A template overload of the above function. More...
 
template<class T , size_t N>
errno_t StrCat (T(&dest)[N], const T *src) noexcept
 A template overload of the above function. More...
 
template<class T , size_t N>
errno_t StrNcat (T(&dest)[N], const T *src, size_t n) noexcept
 A template overload of the above function. More...
 
int VsnPrintfFallback (char *buf, size_t size, const char *fmt, va_list args) noexcept
 The fallback for VsnPrintf. More...
 
int VsnPrintfFallback (wchar_t *buf, size_t size, const wchar_t *fmt, va_list args) noexcept
 A version that takes a wchar_t string as the argument.
 
int VsnPrintfFallback (nlib_utf16_t *buf, size_t size, const nlib_utf16_t *fmt, va_list args) noexcept
 A version that takes an nlib_utf16_t(char16_t) string as the argument.
 
int VsnPrintfFallback (nlib_utf32_t *buf, size_t size, const nlib_utf32_t *fmt, va_list args) noexcept
 A version that takes an nlib_utf32_t(char32_t) string as the argument.
 
int VsnPrintf (char *buf, size_t size, const char *fmt, va_list args) noexcept
 Executes vsnprintf. More...
 
int VsnPrintf (wchar_t *buf, size_t size, const wchar_t *fmt, va_list args) noexcept
 Executes vsnprintf. More...
 
int VsnPrintf (nlib_utf16_t *buf, size_t size, const nlib_utf16_t *fmt, va_list args) noexcept
 If the wide character is two bytes, VsnPrintf() for wchar_t is used. If the wide character is four bytes, VsnPrintfFallback() is used.
 
int VsnPrintf (nlib_utf32_t *buf, size_t size, const nlib_utf32_t *fmt, va_list args) noexcept
 If the wide character is four bytes, VsnPrintf() for wchar_t is used. If the wide character is two bytes, VsnPrintfFallback() is used.
 
template<size_t N, class CH >
int VsnPrintf (CH(&buf)[N], const CH *fmt, va_list args) noexcept
 A template overload of the above function.
 
template<class CH >
int SnPrintf (CH *buf, size_t size, const CH *fmt,...) noexcept
 Internally runs VsnPrintf().
 
template<size_t N, class CH >
int SnPrintf (CH(&buf)[N], const CH *fmt,...) noexcept
 A template overload of the above function.
 
errno_t GetNintendoTime (int64_t *t) noexcept
 Returns the amount of time that has elapsed, in units of milliseconds, starting from 2000-01-01. More...
 
uint64_t GetTickTime () noexcept
 Returns the time in units of milliseconds that has elapsed since the system started. More...
 
bool operator== (const TimeValue &lhs, const TimeValue &rhs) noexcept
 Performs an equality comparison.
 
bool operator< (const TimeValue &lhs, const TimeValue &rhs) noexcept
 Returns true if the left side is smaller than the right side, or returns false otherwise.
 
TimeValue operator+ (const TimeValue &lhs, const TimeValue &rhs) noexcept
 Adds.
 
TimeValue operator- (const TimeValue &lhs, const TimeValue &rhs) noexcept
 Subtracts.
 
bool operator== (const TimeSpan &lhs, const TimeSpan &rhs) noexcept
 Performs an equality comparison.
 
bool operator< (const TimeSpan &lhs, const TimeSpan &rhs) noexcept
 Returns true if the left side is smaller than the right side, or returns false otherwise.
 
TimeSpan operator+ (const TimeSpan &lhs, const TimeSpan &rhs) noexcept
 Adds.
 
TimeSpan operator- (const TimeSpan &lhs, const TimeSpan &rhs) noexcept
 Subtracts.
 
TimeSpan operator* (int i, const TimeSpan &rhs) noexcept
 Increases rhs by a factor of i.
 
TimeSpan operator* (double d, const TimeSpan &rhs) noexcept
 Increases rhs by a factor of d.
 
TimeSpan operator* (const TimeSpan &lhs, int i) noexcept
 Increases rhs by a factor of i.
 
TimeSpan operator* (const TimeSpan &lhs, double d) noexcept
 Increases rhs by a factor of d.
 
bool operator== (const DateTime &lhs, const DateTime &rhs) noexcept
 Returns true if lhs and rhs represent the same time.
 
bool operator< (const DateTime &lhs, const DateTime &rhs) noexcept
 Returns true if lhs represent a time earlier than the time rhs does.
 
DateTime operator+ (const DateTime &lhs, const TimeSpan &rhs) noexcept
 Returns the time that is the rhs amount of time into the future from lhs.
 
DateTime operator- (const DateTime &lhs, const TimeSpan &rhs) noexcept
 Returns the time that is the rhs amount of time back in the past from lhs.
 
TimeSpan operator- (const DateTime &lhs, const DateTime &rhs) noexcept
 Returns the duration between the times of rhs and lhs.
 
template<class T >
errno_t LockFreeInit (T **ptr) noexcept
 Constructs an object in a thread safe manner. More...
 
bool opeq (const z &lhs, const z &rhs)
 Performs an equality comparison.
 
bool opne (const z &lhs, const z &rhs)
 Performs an inequality comparison.
 
bool oplt (const z &lhs, const z &rhs)
 Returns true if the left side is smaller than the right side, or returns false otherwise.
 
bool opgt (const z &lhs, const z &rhs)
 Returns true if the right side is smaller than the left side, or returns false otherwise.
 
bool ople (const z &lhs, const z &rhs)
 Returns true if the left side is equal to or smaller than the right side, or returns false otherwise.
 
bool opge (const z &lhs, const z &rhs)
 Returns true if the right side is equal to or smaller than the left side, or returns false otherwise.
 
template<class T , class AL1 , class AL2 >
bool operator== (const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
 Checks whether two lists have equal values.
 
template<class T , class AL1 , class AL2 >
bool operator!= (const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
 Checks whether two lists have equal values.
 
template<class T , class AL1 , class AL2 >
bool operator< (const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
 Compares two lists in dictionary order.
 
template<class T , class AL1 , class AL2 >
bool operator> (const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
 Compares two lists in dictionary order.
 
template<class T , class AL1 , class AL2 >
bool operator<= (const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
 Compares two lists in dictionary order.
 
template<class T , class AL1 , class AL2 >
bool operator>= (const Nlist< T, AL1 > &lhs, const Nlist< T, AL2 > &rhs) noexcept
 Compares two lists in dictionary order.
 
bool operator== (const StringView &lhs, const StringView &rhs) noexcept
 Compares strings to check whether they are the same.
 
bool operator< (const StringView &lhs, const StringView &rhs) noexcept
 Compares strings in dictionary order.
 
bool StartsWith (const StringView &str, const StringView &prefix) noexcept
 Returns true if prefix is the prefix of str.
 
bool StartsWith (const StringView &str, char c) noexcept
 Returns true if c is the prefix of str.
 
bool StartsWith (const StringView &str, const char *prefix) noexcept
 Returns true if prefix is the prefix of str.
 
bool EndsWith (const StringView &str, const StringView &suffix) noexcept
 Returns true if suffix is the suffix of str.
 
bool EndsWith (const StringView &str, char c) noexcept
 Returns true if c is the suffix of str.
 
bool EndsWith (const StringView &str, const char *suffix) noexcept
 Returns true if suffix is the suffix of str.
 
bool ToCstring (char *buf, size_t buf_size, const StringView &str) noexcept
 Copies a string as a null terminated string. Returns true if the string was successfully copied.
 
template<size_t N>
bool ToCstring (char(&buf)[N], const StringView &str) noexcept
 A template overload of the above function.
 
UniquePtr< char[]> ToCstring (const StringView &str) noexcept
 Allocates memory and copies a string as a null terminated string. Returns true if the string was successfully copied.
 
std::pair< errno_t, size_t > ToInteger (int8_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_int8_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (int16_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_int16_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (int32_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_int32_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (int64_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_int64_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (uint8_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_uint8_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (uint16_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_uint16_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (uint32_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_uint32_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToInteger (uint64_t *v, const StringView &str, int base) noexcept
 Internally calls nlib_uint64_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToFloat (float *v, const StringView &str) noexcept
 Internally calls nlib_float_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
std::pair< errno_t, size_t > ToDouble (double *v, const StringView &str) noexcept
 Internally calls nlib_double_from_chars() to convert a string to a numerical value. The returned value is a pair of the error value and the number of read characters.
 
template<class T >
std::pair< errno_t, size_t > ToInteger (T *v, const StringView &str) noexcept
 Returns ToInteger(v, str, 10). This means that a character is converted to a decimal numerical value.
 
bool TrimLeft (StringView &str) noexcept
 Removes any white spaces from the beginning of the string. More...
 
bool TrimRight (StringView &str) noexcept
 Removes any white spaces from the end of the string. More...
 
void Trim (StringView &str) noexcept
 Removes any white spaces from the beginning and end of the string.
 
StringView GetLine (StringView &str) noexcept
 Obtains the strings from the start to the end of the line. Its own object ( str) moves to the beginning of the next line. More...
 
bool Proceed (StringView &str, const StringView &prefix) noexcept
 If str starts with prefix, it is allowed to go forward by the length of that string. More...
 
bool Proceed (StringView &str, const char *prefix) noexcept
 If str starts with prefix, it is allowed to go forward by the length of that string. More...
 
bool Proceed (StringView &str, char c) noexcept
 If str starts with c, it is allowed to go forward by the length of that string. More...
 
StringView GetName (StringView &str) noexcept
 Obtains a string that is generally handled as a variable name. Its own object ( str) moves to the position immediately after the obtained string. More...
 

Detailed Description

Implements stream-related classes usually commonly used, various containers, and other gadget classes. nlib_ns is an alias.

Description
The following classes and functions are implemented in the nn::nlib namespace.
See also
nlib Platform APIs (global namespace)

Function Documentation

◆ GetNintendoTime()

nn::nlib::GetNintendoTime ( int64_t *  t)
inlinenoexcept

Returns the amount of time that has elapsed, in units of milliseconds, starting from 2000-01-01.

Parameters
[out]tPointer to where the elapsed time is stored.
Returns
Any value other than 0 indicates an error. If the pointer is invalid, the function returns EINVAL.

Definition at line 31 of file DateTime.h.

◆ GetTickTime()

nn::nlib::GetTickTime ( )
inlinenoexcept

Returns the time in units of milliseconds that has elapsed since the system started.

Returns
The elapsed time since the system started.
Examples:
heap/cachedheap/cachedheap.cpp, heap/nmalloc_simple/nmalloc_simple.cpp, and msgpack/msgpack2/msgpack2.cpp.

Definition at line 42 of file DateTime.h.

◆ LockFreeInit()

template<class T >
nn::nlib::LockFreeInit ( T **  ptr)
inlinenoexcept

Constructs an object in a thread safe manner.

Template Parameters
TThe type of the object to be initialized.
Parameters
[out]ptrThe pointer to the initialized object.
Return values
0Success.
EAGAINThe constructor function (ConstructorForLockFree<T>()()) has returned NULL.
Description
This function assigns a pointer to the object created by executing ConstructorForLockFree<T>()() to *ptr. In this case, mutex performs no exclusive processing and CAS(Compare-and-Swap) sets a pointer to the object only once in a thread safe manner. This operation may cause ConstructorForLockFree<T>()() to be simultaneously run in multiple threads, which in turn any objects that are not used are deleted by executing DestructorForLockFree<T>()(). Note that *ptr must have been statically initialized to NULL.
Sample code is provided below. In this sample code, multiple thread build MyObject as it takes time to build MyObject. However, only one of the objects is used and the remaining objects are not used and are deleted. Because the execution efficiency is deteriorated in those cases, this function is suited for cases where it will not take time to build objects.
struct MyObject {
MyObject() {
nlib_printf("MyObject(%p) is constructed by thread %d\n",
this, GetMyThreadId());
nlib_sleep(10000);
}
~MyObject() {
nlib_printf("MyObject(%p) is destroyed by thread %d\n",
this, GetMyThreadId());
}
void UseObject() {
nlib_printf("Object(%p) used from thread %d\n",
this, GetMyThreadId());
}
};
static MyObject* myobj = NULL;
const int kNumThread = 8;
std::thread th_list[kNumThread];
for (auto& th : th_list) {
th = std::thread([&]() {
if (e == 0) { myobj->UseObject(); }
});
}
for (auto& th : th_list) { th.join(); }
MyObject* p = myobj;
myobj = nullptr; // use nlib_atomic_compare_exchangeptr if used in other places.
delete p;
/*
Output:
MyObject(0000017EF4EF16F0) is constructed by thread 16972
MyObject(0000017EF4EF1670) is constructed by thread 5744
MyObject(0000017EF4EF1430) is constructed by thread 9036
MyObject(0000017EF4EF0FF0) is constructed by thread 232
MyObject(0000017EF4EF1470) is constructed by thread 12732
MyObject(0000017EF4EF14B0) is constructed by thread 15228
MyObject(0000017EF4F2DB80) is constructed by thread 5792
MyObject(0000017EF4F2D640) is constructed by thread 7100
Object(0000017EF4EF1670) used from thread 5744
MyObject(0000017EF4EF1430) is destroyed by thread 9036
MyObject(0000017EF4F2DB80) is destroyed by thread 5792
MyObject(0000017EF4EF0FF0) is destroyed by thread 232
MyObject(0000017EF4EF14B0) is destroyed by thread 15228
Object(0000017EF4EF1670) used from thread 232
MyObject(0000017EF4EF1470) is destroyed by thread 12732
Object(0000017EF4EF1670) used from thread 9036
Object(0000017EF4EF1670) used from thread 15228
Object(0000017EF4EF1670) used from thread 12732
Object(0000017EF4EF1670) used from thread 5792
MyObject(0000017EF4F2D640) is destroyed by thread 7100
MyObject(0000017EF4EF16F0) is destroyed by thread 16972
Object(0000017EF4EF1670) used from thread 7100
Object(0000017EF4EF1670) used from thread 16972
MyObject(0000017EF4EF1670) is destroyed by thread 15912
*/

Definition at line 602 of file LockFree.h.

◆ StrCat()

template<class T , size_t N>
nn::nlib::StrCat ( T(&)  dest[N],
const T *  src 
)
inlinenoexcept

A template overload of the above function.

Template Parameters
TEither char or wchar_t.
NThe size of the string buffer where the string is appended.
Parameters
[in,out]destThe null-terminated string buffer where the string is appended.
[in]srcThe null-terminated string to append.
Returns
The return value of StrCat(&dest[0], N, src).

Definition at line 148 of file Cstring.h.

◆ StrCpy()

template<class T , size_t N>
nn::nlib::StrCpy ( T(&)  dest[N],
const T *  src 
)
inlinenoexcept

A template overload of the above function.

Template Parameters
TEither char, wchar_t, nlib_utf16_t, or nlib_utf32_t.
NThe size of the buffer to copy to.
Parameters
[out]destThe buffer where the string is copied.
[in]srcThe string to copy.
Returns
The return value of StrCpy(&dest[0], N, src).

Definition at line 122 of file Cstring.h.

◆ StrNcat()

template<class T , size_t N>
nn::nlib::StrNcat ( T(&)  dest[N],
const T *  src,
size_t  n 
)
inlinenoexcept

A template overload of the above function.

Template Parameters
TEither char or wchar_t.
NThe size of the string buffer where the string is appended.
Parameters
[in,out]destThe null-terminated string buffer where the string is appended.
[in]srcThe null-terminated string to append.
[in]nThe maximum number of characters to add (excluding the null character).
Returns
The return value of StrNcat(&dest[0], N, src, n).

Definition at line 153 of file Cstring.h.

◆ StrNcpy()

template<class T , size_t N>
nn::nlib::StrNcpy ( T(&)  dest[N],
const T *  src,
size_t  n 
)
inlinenoexcept

A template overload of the above function.

Template Parameters
TEither char, wchar_t, nlib_utf16_t, or nlib_utf32_t.
NThe size of the buffer to copy to.
Parameters
[out]destThe buffer where the string is copied.
[in]srcThe string to copy.
[in]nThe maximum number of characters to copy (excluding the null character).
Returns
The return value of StrNcpy(&dest[0], N, src, n).

Definition at line 143 of file Cstring.h.

◆ VsnPrintf() [1/2]

nn::nlib::VsnPrintf ( char *  buf,
size_t  size,
const char *  fmt,
va_list  args 
)
inlinenoexcept

Executes vsnprintf.

Parameters
[out]bufThe buffer storing the string.
[in]sizeThe size of the buffer (a number of characters).
[in]fmtThe format.
[in]argsPointer to an argument list.
Returns
If successful, returns the length of the string that was (supposed to be) written, not including the null terminator. The function returns a negative value if it fails.
Description
The null character is written to the end of buf. The user must call va_end after this function has been called.
The function makes an internal call to vsnprintf, but the error values and other behavior can differ, depending on the platform.
This is illustrated by the following coding example.
void MyFunc(char* buf, size_t size, const char* fmt, ...) {
va_start(args, fmt);
int n = VsnPrintf(buf, size, fmt, args);
va_end(args);
if (n < 0) {
// Note that if the buffer is too small, the function might return a negative value rather than a positive number and set an error such as EAGAIN, ERANGE, or EOVERFLOW in \a errno.
// The error values differ depending on the platform.
// The negative number values themselves differ, so compare them unsigned.
....
} else if (static_cast<size_t>(n) >= size) {
// The string is not written in its entirety, but rounded.
....
} else {
// Successfully written.
....
}
}

Definition at line 277 of file Cstring.h.

◆ VsnPrintf() [2/2]

nn::nlib::VsnPrintf ( wchar_t *  buf,
size_t  size,
const wchar_t *  fmt,
va_list  args 
)
inlinenoexcept

Executes vsnprintf.

Parameters
[out]bufThe buffer storing the string.
[in]sizeThe size of the buffer (a number of characters).
[in]fmtThe format.
[in]argsPointer to an argument list.
Returns
If successful, returns the number of characters that were written, not including the null terminator. The function returns a negative value if it fails.
Description
The null character is written to the end of buf. The user must call va_end after this function has been called.
The function makes an internal call to vsnwprintf, but the error values and other behavior can differ, depending on the platform.

Definition at line 285 of file Cstring.h.

◆ VsnPrintfFallback()

nn::nlib::VsnPrintfFallback ( char *  buf,
size_t  size,
const char *  fmt,
va_list  args 
)
noexcept

The fallback for VsnPrintf.

Parameters
[out]bufThe buffer storing the string.
[in]sizeThe size of the buffer (a number of characters).
[in]fmtThe format.
[in]argsPointer to an argument list.
Returns
If successful, returns the number of characters that were written, not including the null terminator. The function returns a negative value if it fails.
Description
This function is called from VsnPrintf in environments where vsnprintf does not exist or can be classified as such. This function can also be called directly. As of now, the floating-point type does not use exponential notation.
If the function fails, an error value is set in errno (in environments where errno exists).
The following flag characters are supported.
  • #: For x and X conversion, the string 0x (or 0X) is added in front if the numerical value is not 0. For o conversion, the character 0 is added in front if the numerical value is not 0.
  • 0: Padded with zeros instead of white spaces to the right of the converted value. This is ignored if - is specified. This is ignored if a precision is specified.
  • -: Left-justified.
  • A space (' '): Adds one blank space in front of a positive number created from a signed conversion.
  • +: Always place the sign in front of a signed converted number.
For the field width, you can specify a decimal string or "*". "*" must be an int type value because the next argument specifies the field width.
For the precision, you can specify a decimal string or "*".
The following length modifiers are supported.
  • hh: The argument is char or unsigned char.
  • h: The argument is short or unsigned short.
  • l: The argument is long or unsigned long.
  • ll: The argument is long long or unsigned long long.
  • z: The argument is size_t.
The following conversion specifiers are supported.
  • d, c: Signed integer.
  • o, u, x, X: Unsigned integer.
  • c: A character (type char).
  • s: A string (const char* type). If ls, it is a const wchar_t*-type string, but the character corresponding to the lower 8 bits is output.
  • p: Outputs the pointer address in hexadecimal.