20 #ifndef FASTRTPS_UTILS_FIXED_SIZE_STRING_HPP_
21 #define FASTRTPS_UTILS_FIXED_SIZE_STRING_HPP_
27 #define MEMCCPY _memccpy
29 #define MEMCCPY memccpy
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
42 template <
size_t MAX_CHARS>
52 memset(string_data, 0,
sizeof(string_data) );
61 set(c_string !=
nullptr ? c_string :
"");
66 set(c_string !=
nullptr ? c_string :
"");
78 const char*
c_str() const noexcept {
return string_data; }
79 std::string
to_string()
const {
return std::string(string_data); }
82 bool operator == (
const char* rhs)
const noexcept {
return strncmp(string_data, rhs, MAX_CHARS) == 0; }
83 bool operator == (
const std::string& rhs)
const noexcept {
return strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; }
84 template<
size_t N>
bool operator == (
const fixed_string<N> & rhs)
const noexcept {
return strncmp(string_data, rhs.c_str(), MAX_CHARS) == 0; }
87 bool operator != (
const char* rhs)
const noexcept {
return strncmp(string_data, rhs, MAX_CHARS) != 0; }
88 bool operator != (
const std::string& rhs)
const noexcept {
return strncmp(string_data, rhs.c_str(), MAX_CHARS) != 0; }
89 template<
size_t N>
bool operator != (
const fixed_string<N> & rhs)
const noexcept {
return strncmp(string_data, rhs.c_str(), MAX_CHARS) != 0; }
91 operator const char* ()
const noexcept {
return c_str(); }
93 size_t size() const noexcept {
return string_len; }
96 void set(
const char* c_string) noexcept
98 char* result = (
char*) MEMCCPY(string_data, c_string,
'\0', MAX_CHARS);
99 string_len = (result ==
nullptr) ? MAX_CHARS : (
size_t)(result - string_data) - 1u;
102 char string_data[MAX_CHARS + 1];
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23
Template class for non-alloc strings.
Definition: fixed_size_string.hpp:44
fixed_string() noexcept
Default constructor.
Definition: fixed_size_string.hpp:50
fixed_string & operator=(const char *c_string) noexcept
Definition: fixed_size_string.hpp:64
size_t size() const noexcept
Definition: fixed_size_string.hpp:93
fixed_string(const std::string &str) noexcept
Definition: fixed_size_string.hpp:71
bool operator==(const char *rhs) const noexcept
Definition: fixed_size_string.hpp:82
static constexpr size_t max_size
Definition: fixed_size_string.hpp:47
std::string to_string() const
Definition: fixed_size_string.hpp:79
const char * c_str() const noexcept
Definition: fixed_size_string.hpp:78
fixed_string(const char *c_string) noexcept
Definition: fixed_size_string.hpp:59
bool operator!=(const char *rhs) const noexcept
Definition: fixed_size_string.hpp:87