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)
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);
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 operator+(const String &other) const
Definition: String.h:86
int64_t size() const
Definition: String.h:56
const char * c_str() const
Definition: String.h:55
String(const String &other)
Definition: String.h:50
bool operator==(const String &other) const
Definition: String.h:76
String(const char *str)
Construct from null terminated character string.
Definition: String.h:40
const std::string str() const
Definition: String.h:54
__hostdev__ constexpr uint32_t strlen()
return the number of characters (including null termination) required to convert enum type to a strin...
Definition: NanoVDB.h:209
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:474
int64_t len
Definition: String.h:119
String(const char *str, const int64_t size)
Definition: String.h:42
void clear()
Definition: String.h:58
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
int strcmp(const char *lhs, const char *rhs)
Compares two null-terminated byte strings lexicographically.
Definition: Util.h:255
const String & operator=(const std::string &str)
Definition: String.h:64
Definition: Exceptions.h:13
const String & operator=(const String &other)
Definition: String.h:70
void reset(const char *str, const int64_t size)
Definition: String.h:102
~String()
Definition: String.h:48
bool operator!=(const String &other) const
Definition: String.h:81
char * ptr
Definition: String.h:117
String()
Definition: String.h:38
String(const std::string &str)
Definition: String.h:41
bool isLocal() const
Definition: String.h:57
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition: String.h:33
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218
void alloc(const size_t size)
Definition: String.h:108