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");
44 template<std::
size_t S>
46 String(
const std::string& str) :
String(str.c_str(), str.size()) {}
48 ~String() {
if (!this->isLocal()) std::free(ptr); }
52 const std::string
str()
const {
return std::string(this->ptr, this->len); }
53 const char*
c_str()
const {
return this->ptr; }
54 int64_t
size()
const {
return this->len; }
55 bool isLocal()
const {
return this->ptr == this->SSO; }
56 void clear() { this->reset(
"", 0); }
60 inline operator const char*()
const {
return this->ptr; }
64 this->reset(str.c_str(), str.size());
70 this->reset(other.
ptr, other.
len);
76 return std::strcmp(this->ptr, other.
ptr) == 0;
88 std::memcpy(s.
ptr, this->c_str(), this->size());
89 std::memcpy(s.
ptr + this->size(), other.
c_str(), other.
size());
100 String(
const char* str,
const int64_t size)
102 assert(str !=
nullptr);
103 this->ptr = this->SSO;
104 this->reset(str, size);
107 inline void reset(
const char* str,
const int64_t size)
110 std::memcpy(this->ptr, str, size);
113 inline void alloc(
const size_t size)
115 if (!this->isLocal()) std::free(this->ptr);
116 if (size > SSO_LENGTH-1) this->ptr =
static_cast<char*
>(std::malloc(size + 1));
117 else this->ptr = this->SSO;
118 this->ptr[size] =
'\0';
123 char SSO[SSO_LENGTH];
135 #endif // OPENVDB_AX_CODEGEN_STRING_HAS_BEEN_INCLUDED String operator+(const String &other) const
Definition: String.h:84
String(const std::string &str)
Definition: String.h:46
String(const char *str)
Definition: String.h:39
void reset(const char *str, const int64_t size)
Definition: String.h:107
String(const String &other)
Definition: String.h:47
~String()
Definition: String.h:48
char * ptr
Definition: String.h:122
An extremely basic but native representation of a string class with SSO support. This exists to provi...
Definition: String.h:33
const String & operator=(const std::string &str)
Definition: String.h:62
String()
Definition: String.h:38
int64_t len
Definition: String.h:124
void alloc(const size_t size)
Definition: String.h:113
String(char(&str)[S])
Definition: String.h:45
bool operator!=(const String &other) const
Definition: String.h:79
void clear()
Definition: String.h:56
Definition: Exceptions.h:13
int64_t size() const
Definition: String.h:54
String(const char *str, const int64_t size)
Definition: String.h:100
const std::string str() const
Definition: String.h:52
const char * c_str() const
Definition: String.h:53
bool isLocal() const
Definition: String.h:55
const String & operator=(const String &other)
Definition: String.h:68
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
bool operator==(const String &other) const
Definition: String.h:74
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202