20#ifndef FASTCDR_UTILS_FIXED_SIZE_STRING_HPP_
21#define FASTCDR_UTILS_FIXED_SIZE_STRING_HPP_
27#define MEMCCPY _memccpy
29#define MEMCCPY memccpy
43template <
size_t MAX_CHARS>
67 size_t n_chars)
noexcept
80 size_t n_chars)
noexcept
83 (MAX_CHARS < n_chars) ? MAX_CHARS : n_chars;
96 const char* c_string) noexcept
99 set(c_string !=
nullptr ? c_string :
"");
108 const char* c_string)
noexcept
110 set(c_string !=
nullptr ? c_string :
"");
173 const char* rhs)
const noexcept
186 return strncmp(
string_data, rhs.c_str(), MAX_CHARS) == 0;
197 return strncmp(
string_data, rhs.c_str(), MAX_CHARS) == 0;
206 const char* rhs)
const noexcept
208 return !(*
this == rhs);
219 return !(*
this == rhs);
230 return !(*
this == rhs);
280 operator const char* ()
const noexcept {
299 const char* str)
const noexcept
312 return strncmp(
string_data, str.c_str(), MAX_CHARS);
323 return strncmp(
string_data, str.c_str(), MAX_CHARS);
329 const char* c_string)
noexcept
Template class for non-alloc strings.
std::string to_string() const
Converts to std::string.
fixed_string & assign(const char *c_array, size_t n_chars) noexcept
Assigns from a char array.
void set(const char *c_string) noexcept
size_t string_len
Holds current string length.
int compare(const std::string &str) const noexcept
Compares with a std::string.
bool operator<(const fixed_string< N > &rhs) const noexcept
Compares relational less than with a fixed_string of any size.
fixed_string() noexcept
Default constructor.
bool operator>(const fixed_string< N > &rhs) const noexcept
Compares relational greater than with a fixed_string of any size.
fixed_string & operator=(const char *c_string) noexcept
Assigns from a C string.
bool operator==(const char *rhs) const noexcept
Compares equality with a C string.
char string_data[MAX_CHARS+1]
Holds string data, including ending null character.
fixed_string(const char *c_string) noexcept
Constructs from a C string.
bool operator!=(const char *rhs) const noexcept
Compares inequality with a C string.
fixed_string(const std::string &str) noexcept
Constructs from a std::string.
static constexpr size_t max_size
Maximum number of characters.
int compare(const fixed_string< N > &str) const noexcept
Compares with a fixed_string.
int compare(const char *str) const noexcept
Compares with a C string.
fixed_string(const char *c_array, size_t n_chars) noexcept
Constructs from a char array.
size_t size() const noexcept
Returns the size of the string.
const char * c_str() const noexcept
Converts to C string.