15 #ifndef TurtleBrains_FixedString_hpp
16 #define TurtleBrains_FixedString_hpp
18 #include <turtle_brains/core/tb_configuration.hpp>
19 #include <turtle_brains/core/tb_string.hpp>
20 #include <turtle_brains/core/tb_error.hpp>
36 #if (defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER))
37 #pragma GCC diagnostic ignored "-Wstringop-truncation"
47 tb_static_error_if(Size < 1,
"Expected FixedString size to contain at least 1 character.");
58 strncpy(mData, value, Size);
64 strncpy(mData, value.c_str(), Size);
70 strncpy(mData, value.mData, Size);
75 strncpy(mData, other.mData, Size);
81 strncpy(mData, other.c_str(), Size);
87 strncpy(mData, other, Size);
91 bool operator==(
const FixedString& other)
const {
return 0 == std::strncmp(mData, other.String().c_str(), Size); }
92 bool operator==(
const char* other)
const {
return 0 == std::strncmp(mData, other, Size); }
93 bool operator==(
const String& other)
const {
return 0 == std::strncmp(mData, other.c_str(), Size); }
94 bool operator!=(
const FixedString& other)
const {
return 0 != std::strncmp(mData, other.mData, Size); }
95 bool operator!=(
const char* other)
const {
return 0 != std::strncmp(mData, other, Size); }
96 bool operator!=(
const String& other)
const {
return 0 != std::strncmp(mData, other.c_str(), Size); }
103 bool empty(
void)
const {
return mData[0] ==
'\0'; }
104 size_t size(
void)
const
109 const char* nullTerm =
static_cast<const char*
>(memchr(mData,
'\0', Size));
110 const char* start = &mData[0];
111 return (
nullptr == nullTerm) ? Size : (nullTerm - start);
114 size_t FixedSize(
void)
const {
return Size; }
118 const char*
data(
void)
const {
return mData; }
119 char*
data(
void) {
return mData; }
130 template <
size_t Size> std::ostream& operator<<(std::ostream& outputStream,
const FixedString<Size>& fixed)
132 outputStream << fixed.data();
136 template <
size_t Size> std::istream& operator<<(std::istream& inputStream, FixedString<Size>& fixed)
139 inputStream >> buffer;
144 template <
size_t Size>
bool operator==(
const char* left,
const FixedString<Size>& right) {
return 0 == std::strncmp(right.data(), left, Size); }
145 template <
size_t Size>
bool operator==(
const String& left,
const FixedString<Size>& right) {
return 0 == std::strncmp(right.data(), left.c_str(), Size); }
146 template <
size_t Size>
bool operator!=(
const char* left,
const FixedString<Size>& right) {
return 0 != std::strncmp(right.data(), left, Size); }
147 template <
size_t Size>
bool operator!=(
const String& left,
const FixedString<Size>& right) {
return 0 != std::strncmp(right.data(), left.c_str(), Size); }
154 #if (defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER))
155 #pragma GCC diagnostic warning "-Wstringop-truncation"
Definition: tb_fixed_string.hpp:46
const char * data(void) const
Definition: tb_fixed_string.hpp:118
Definition: tb_types.hpp:32
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:125
std::string String
Definition: tb_string.hpp:302
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:22