27 #include <string_view>
29 #ifdef EMLABCPP_USE_NLOHMANN_JSON
30 #include <nlohmann/json.hpp>
36 template < std::
size_t N >
45 std::fill_n( this->
data(),
N,
'\0' );
51 std::copy_n( sv.begin(),
std::min( sv.size(),
N - 1 ), this->begin() );
54 template < std::
size_t M >
58 static_assert( M <
N );
59 std::copy_n( msg, M, this->begin() );
62 template < std::
size_t M >
66 static_assert( M <
N );
67 std::copy_n( msg.data(), M, this->begin() );
70 operator std::string_view()
const
72 return std::string_view( this->
data() );
75 [[nodiscard]] constexpr std::size_t
size()
const
77 return strlen( this->
data() );
80 template < std::
size_t M >
83 return std::string_view{ *
this } == std::string_view{ other };
86 constexpr
bool operator==( std::string_view other )
const noexcept
88 return std::string_view{ *
this } == other;
94 template <
typename T >
97 static constexpr
bool value =
false;
100 template < std::
size_t N >
108 template <
typename T >
111 template < std::
size_t N >
114 return os << std::string_view( sb );
117 #ifdef EMLABCPP_USE_NLOHMANN_JSON
119 template < std::
size_t N >
120 void to_json( nlohmann::json& j, string_buffer< N >
const& buffer )
122 j = std::string_view{ buffer };
125 template < std::
size_t N >
126 void from_json( nlohmann::json
const& j, string_buffer< N >& buffer )
128 std::string
const s = j;
129 buffer = string_buffer< N >( std::string_view{ s } );
MIT License.
Definition: impl.h:31
constexpr pointer data() noexcept
Returns pointer to first item of the storage.
Definition: static_storage.h:108
concept is_string_buffer_v
Definition: string_buffer.h:109
constexpr Derived const & min(vec_point_base< Derived, N > const &a, vec_point_base< Derived, N > const &b)
Definition: vec_point_base.h:236
std::ostream & operator<<(std::ostream &os, string_buffer< N > const &sb)
Definition: string_buffer.h:112
N
Definition: static_storage.h:97
Definition: string_buffer.h:96
static constexpr bool value
Definition: string_buffer.h:97
Definition: string_buffer.h:38
constexpr string_buffer(std::string_view sv)
Definition: string_buffer.h:48
constexpr bool operator==(string_buffer< M > const &other) const noexcept
Definition: string_buffer.h:81
std::array< char, N > base_type
Definition: string_buffer.h:40
constexpr bool operator==(std::string_view other) const noexcept
Definition: string_buffer.h:86
constexpr string_buffer(char const (&msg)[M])
Definition: string_buffer.h:55
constexpr std::size_t size() const
Definition: string_buffer.h:75
constexpr string_buffer()
Definition: string_buffer.h:42
constexpr string_buffer(string_buffer< M > const &msg)
Definition: string_buffer.h:63
static constexpr std::size_t capacity
Definition: string_buffer.h:39