HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
hoover_chess_utils::pgn_reader::MiniString< t_maxLen > Class Template Reference

A Pascal-style length-prefixed string with the specified maximum length. More...

#include <pgnreader-string-utils.h>

Public Member Functions

constexpr MiniString () noexcept
 Initializing constructor. Sets the length of the contained string to 0.
 
constexpr MiniString (MiniString_Uninitialized) noexcept
 Non-initializing constructor. The state of the object is undefined.
 
 MiniString (const MiniString &)=default
 Copy constructor (default)
 
 MiniString (MiniString &&)=default
 Move constructor (default)
 
MiniStringoperator= (const MiniString &) &=default
 Copy assignment (default)
 
MiniStringoperator= (MiniString &&) &=default
 Move assignment (default)
 
 ~MiniString ()=default
 Destructor (default)
 
constexpr void setLength (std::uint8_t length) noexcept
 Sets the length of the contained string without resetting the contents.
 
constexpr void assign (const char *str) noexcept
 Assigns a C-string.
 
constexpr void assign (const char *str, std::size_t strLen) noexcept
 Assigns a string with length. In case the string is longer than the maximum capacity, the contained string is truncated.
 
constexpr char operator[] (std::size_t index) const noexcept
 Returns a character at a specified offset. This function does not perform an index bounds check.
 
constexpr char & operator[] (std::size_t index) noexcept
 Returns a reference to the character at a specified offset. This function does not perform an index bounds check.
 
constexpr char * data () noexcept
 Returns a pointer to the string data. The string may be non-terminated by ('\0').
 
constexpr const char * data () const noexcept
 Returns a const pointer to the string data. The string may be non-terminated by ('\0').
 
constexpr std::size_t size () const noexcept
 Returns the size of the string.
 
constexpr std::string_view getStringView () const
 Returns a string view to the string.
 

Static Public Member Functions

static constexpr std::size_t capacity () noexcept
 Returns the capacity (maximum size) of a string to hold.
 

Private Attributes

std::uint8_t m_length
 
std::array< char, t_maxLen > m_storage
 

Detailed Description

template<std::size_t t_maxLen>
class hoover_chess_utils::pgn_reader::MiniString< t_maxLen >

A Pascal-style length-prefixed string with the specified maximum length.

Template Parameters
t_maxLenMaximum length of the contained string. Range: [1, 255]

This object is intended as a fast, low-level container for small strings. The implementation foregoes many common API usage correctness checks to improve runtime performance.

Remarks
MiniString is not a '\0'-terminated string. A MiniString can contain the character '\0'.

Constructor & Destructor Documentation

◆ MiniString() [1/4]

template<std::size_t t_maxLen>
constexpr hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::MiniString ( )
inlineconstexprnoexcept

Initializing constructor. Sets the length of the contained string to 0.

◆ MiniString() [2/4]

template<std::size_t t_maxLen>
constexpr hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::MiniString ( MiniString_Uninitialized  )
inlineconstexprnoexcept

Non-initializing constructor. The state of the object is undefined.

◆ MiniString() [3/4]

template<std::size_t t_maxLen>
hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::MiniString ( const MiniString< t_maxLen > &  )
default

Copy constructor (default)

◆ MiniString() [4/4]

template<std::size_t t_maxLen>
hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::MiniString ( MiniString< t_maxLen > &&  )
default

Move constructor (default)

◆ ~MiniString()

template<std::size_t t_maxLen>
hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::~MiniString ( )
default

Destructor (default)

Member Function Documentation

◆ assign() [1/2]

template<std::size_t t_maxLen>
constexpr void hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::assign ( const char *  str)
inlineconstexprnoexcept

Assigns a C-string.

Parameters
[in]strC-string

Assigns a C-string by copying up to t_maxLen characters and setting the length. The terminator ('\0') is not included.

◆ assign() [2/2]

template<std::size_t t_maxLen>
constexpr void hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::assign ( const char *  str,
std::size_t  strLen 
)
inlineconstexprnoexcept

Assigns a string with length. In case the string is longer than the maximum capacity, the contained string is truncated.

Parameters
[in]strPointer to string
[in]strLenInput string length

◆ capacity()

template<std::size_t t_maxLen>
static constexpr std::size_t hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::capacity ( )
inlinestaticconstexprnoexcept

Returns the capacity (maximum size) of a string to hold.

Returns
Maximum size of the held string. Same as t_maxLen template parameter.

◆ data() [1/2]

template<std::size_t t_maxLen>
constexpr const char * hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::data ( ) const
inlineconstexprnoexcept

Returns a const pointer to the string data. The string may be non-terminated by ('\0').

Returns
Pointer to string data

◆ data() [2/2]

template<std::size_t t_maxLen>
constexpr char * hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::data ( )
inlineconstexprnoexcept

Returns a pointer to the string data. The string may be non-terminated by ('\0').

Returns
Pointer to string data

◆ getStringView()

template<std::size_t t_maxLen>
constexpr std::string_view hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::getStringView ( ) const
inlineconstexpr

Returns a string view to the string.

Returns
String view
str.assign("12345");
std::cout << "MiniString contents: " << str.getStringView() << std::endl;
A Pascal-style length-prefixed string with the specified maximum length.
Definition pgnreader-string-utils.h:57
constexpr void assign(const char *str) noexcept
Assigns a C-string.
Definition pgnreader-string-utils.h:114
constexpr std::string_view getStringView() const
Returns a string view to the string.
Definition pgnreader-string-utils.h:215

◆ operator=() [1/2]

template<std::size_t t_maxLen>
MiniString & hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::operator= ( const MiniString< t_maxLen > &  ) &
default

Copy assignment (default)

◆ operator=() [2/2]

template<std::size_t t_maxLen>
MiniString & hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::operator= ( MiniString< t_maxLen > &&  ) &
default

Move assignment (default)

◆ operator[]() [1/2]

template<std::size_t t_maxLen>
constexpr char hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::operator[] ( std::size_t  index) const
inlineconstexprnoexcept

Returns a character at a specified offset. This function does not perform an index bounds check.

Parameters
[in]indexString offset
Returns
Character at the specified offset

◆ operator[]() [2/2]

template<std::size_t t_maxLen>
constexpr char & hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::operator[] ( std::size_t  index)
inlineconstexprnoexcept

Returns a reference to the character at a specified offset. This function does not perform an index bounds check.

Parameters
[in]indexString offset
Returns
Reference to the character at the specified offset

Example

str.setLength(2U);
str[0] = '4';
str[1] = '2';
constexpr void setLength(std::uint8_t length) noexcept
Sets the length of the contained string without resetting the contents.
Definition pgnreader-string-utils.h:101

◆ setLength()

template<std::size_t t_maxLen>
constexpr void hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::setLength ( std::uint8_t  length)
inlineconstexprnoexcept

Sets the length of the contained string without resetting the contents.

Parameters
[in]lengthNew string length. Range: [0, t_maxLen]
Note
It is the caller's responsibility to ensure that the string data for offsets [0, length-1] is fully initialized.

◆ size()

template<std::size_t t_maxLen>
constexpr std::size_t hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::size ( ) const
inlineconstexprnoexcept

Returns the size of the string.

Returns
Size of the string

Member Data Documentation

◆ m_length

template<std::size_t t_maxLen>
std::uint8_t hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::m_length
private

◆ m_storage

template<std::size_t t_maxLen>
std::array<char, t_maxLen> hoover_chess_utils::pgn_reader::MiniString< t_maxLen >::m_storage
private

The documentation for this class was generated from the following file: