12 #ifndef OPENVDB_AX_CODEGEN_STRING_HAS_BEEN_INCLUDED 13 #define OPENVDB_AX_CODEGEN_STRING_HAS_BEEN_INCLUDED 15 #include <openvdb/version.h> 35 static constexpr int64_t SSO_LENGTH = 16;
36 static_assert(SSO_LENGTH >= 2,
"SSO should be greater than or equal to 2");
41 String(
const std::string& str) :
String(str.c_str(), str.size()) {}
42 String(
const char* str,
const int64_t size)
44 assert(str !=
nullptr);
45 this->ptr = this->SSO;
46 this->reset(str, size);
48 ~String() {
if (!this->isLocal()) std::free(ptr); }
54 const std::string
str()
const {
return std::string(this->ptr, this->len); }
55 const char*
c_str()
const {
return this->ptr; }
56 int64_t
size()
const {
return this->len; }
57 bool isLocal()
const {
return this->ptr == this->SSO; }
58 void clear() { this->reset(
"", 0); }
62 inline operator const char*()
const {
return this->ptr; }
66 this->reset(str.c_str(), str.size());
72 this->reset(other.
ptr, other.
len);
78 return std::strcmp(this->ptr, other.
ptr) == 0;
90 std::memcpy(s.
ptr, this->c_str(), this->size());
91 std::memcpy(s.
ptr + this->size(), other.
c_str(), other.
size());
102 inline void reset(
const char* str,
const int64_t size)
105 std::memcpy(this->ptr, str, size);
108 inline void alloc(
const size_t size)
110 if (!this->isLocal()) std::free(this->ptr);
111 if (size > SSO_LENGTH-1) this->ptr =
static_cast<char*
>(std::malloc(size + 1));
112 else this->ptr = this->SSO;
113 this->ptr[size] =
'\0';
118 char SSO[SSO_LENGTH];
130 #endif // OPENVDB_AX_CODEGEN_STRING_HAS_BEEN_INCLUDED String(const char *str, const int64_t size)
Definition: String.h:42
~String()
Definition: String.h:48
const char * c_str() const
Definition: String.h:55
const String & operator=(const std::string &str)
Definition: String.h:64
void reset(const char *str, const int64_t size)
Definition: String.h:102
char * ptr
Definition: String.h:117
const std::string str() const
Definition: String.h:54
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition: String.h:33
int64_t len
Definition: String.h:119
String(const char *str)
Construct from null terminated character string.
Definition: String.h:40
void alloc(const size_t size)
Definition: String.h:108
bool isLocal() const
Definition: String.h:57
void clear()
Definition: String.h:58
Definition: Exceptions.h:13
bool operator!=(const String &other) const
Definition: String.h:81
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:473
const String & operator=(const String &other)
Definition: String.h:70
String operator+(const String &other) const
Definition: String.h:86
int64_t size() const
Definition: String.h:56
String(const String &other)
Definition: String.h:50
bool operator==(const String &other) const
Definition: String.h:76
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
String(const std::string &str)
Definition: String.h:41
String()
Definition: String.h:38
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212