Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
string_t Struct Reference

Classes

struct  StringComparisonOperators

Public Member Functions

 string_t (uint32_t len)
 string_t (const char *data, uint32_t len)
 string_t (const char *data)
 string_t (const string &value)
bool IsInlined () const
const char * GetData () const
const char * GetDataUnsafe () const
char * GetDataWriteable () const
const char * GetPrefix () const
char * GetPrefixWriteable ()
idx_t GetSize () const
void SetSizeAndFinalize (uint32_t size, idx_t allocated_size)
bool Empty () const
string GetString () const
 operator string () const
char * GetPointer () const
void SetPointer (char *new_ptr)
void Finalize ()
void Verify () const
void VerifyUTF8 () const
void VerifyCharacters () const
void VerifyNull () const
bool operator== (const string_t &r) const
bool operator!= (const string_t &r) const
bool operator> (const string_t &r) const
bool operator< (const string_t &r) const

Static Public Attributes

static constexpr idx_t PREFIX_BYTES = 4 * sizeof(char)
static constexpr idx_t INLINE_BYTES = 12 * sizeof(char)
static constexpr idx_t HEADER_SIZE = sizeof(uint32_t) + PREFIX_BYTES
static constexpr idx_t MAX_STRING_SIZE = NumericLimits<uint32_t>::Maximum()
static constexpr idx_t PREFIX_LENGTH = PREFIX_BYTES
static constexpr idx_t INLINE_LENGTH = INLINE_BYTES

Private Attributes

union { 
   struct { 
      uint32_t   length 
      char   prefix [4] 
      char *   ptr 
   }   pointer
   struct { 
      uint32_t   length 
      char   inlined [12] 
   }   inlined
} value

Friends

struct StringComparisonOperators

Constructor & Destructor Documentation

◆ string_t() [1/4]

duckdb::string_t::string_t ( uint32_t len)
inlineexplicit
4723 {
4724 value.inlined.length = len;
4725 }

◆ string_t() [2/4]

duckdb::string_t::string_t ( const char * data,
uint32_t len )
inline
4726 {
4727 value.inlined.length = len;
4728 D_ASSERT(data || GetSize() == 0);
4729 if (IsInlined()) {
4730 // zero initialize the prefix first
4731 // this makes sure that strings with length smaller than 4 still have an equal prefix
4732 memset(value.inlined.inlined, 0, INLINE_BYTES);
4733 if (GetSize() == 0) {
4734 return;
4735 }
4736 // small string: inlined
4737 memcpy(value.inlined.inlined, data, GetSize());
4738 } else {
4739 // large string: store pointer
4740#ifndef DUCKDB_DEBUG_NO_INLINE
4741 memcpy(value.pointer.prefix, data, PREFIX_LENGTH);
4742#else
4743 memset(value.pointer.prefix, 0, PREFIX_BYTES);
4744#endif
4745 value.pointer.ptr = (char *)data; // NOLINT
4746 }
4747 }

◆ string_t() [3/4]

duckdb::string_t::string_t ( const char * data)
inline
4750 : string_t(data, UnsafeNumericCast<uint32_t>(strlen(data))) {
4751 }

◆ string_t() [4/4]

duckdb::string_t::string_t ( const string & value)
inline
4753 : string_t(value.c_str(), UnsafeNumericCast<uint32_t>(value.size())) {
4754 }

Member Function Documentation

◆ IsInlined()

bool duckdb::string_t::IsInlined ( ) const
inline
4756 {
4757 return GetSize() <= INLINE_LENGTH;
4758 }

◆ GetData()

const char * duckdb::string_t::GetData ( ) const
inline
4760 {
4761 return IsInlined() ? const_char_ptr_cast(value.inlined.inlined) : value.pointer.ptr;
4762 }

◆ GetDataUnsafe()

const char * duckdb::string_t::GetDataUnsafe ( ) const
inline
4763 {
4764 return GetData();
4765 }

◆ GetDataWriteable()

char * duckdb::string_t::GetDataWriteable ( ) const
inline
4767 {
4768 return IsInlined() ? (char *)value.inlined.inlined : value.pointer.ptr; // NOLINT
4769 }

◆ GetPrefix()

const char * duckdb::string_t::GetPrefix ( ) const
inline
4771 {
4772 return value.inlined.inlined;
4773 }

◆ GetPrefixWriteable()

char * duckdb::string_t::GetPrefixWriteable ( )
inline
4775 {
4776 return value.inlined.inlined;
4777 }

◆ GetSize()

idx_t duckdb::string_t::GetSize ( ) const
inline
4779 {
4780 return value.inlined.length;
4781 }

◆ SetSizeAndFinalize()

void duckdb::string_t::SetSizeAndFinalize ( uint32_t size,
idx_t allocated_size )
inline

Data was written to the 'value.pointer.ptr', has to be copied to the inlined bytes

4783 {
4784 value.inlined.length = size;
4785 if (allocated_size > INLINE_LENGTH && IsInlined()) {
4787 D_ASSERT(value.pointer.ptr);
4788 auto ptr = value.pointer.ptr;
4789 memcpy(GetDataWriteable(), ptr, size);
4790 }
4791 Finalize();
4792 VerifyCharacters();
4793 }
GOpaque< Size > size(const GMat &src)

◆ Empty()

bool duckdb::string_t::Empty ( ) const
inline
4795 {
4796 return value.inlined.length == 0;
4797 }

◆ GetString()

string duckdb::string_t::GetString ( ) const
inline
4799 {
4800 return string(GetData(), GetSize());
4801 }

◆ operator string()

duckdb::string_t::operator string ( ) const
inlineexplicit
4803 {
4804 return GetString();
4805 }

◆ GetPointer()

char * duckdb::string_t::GetPointer ( ) const
inline
4807 {
4808 D_ASSERT(!IsInlined());
4809 return value.pointer.ptr;
4810 }

◆ SetPointer()

void duckdb::string_t::SetPointer ( char * new_ptr)
inline
4812 {
4813 D_ASSERT(!IsInlined());
4814 value.pointer.ptr = new_ptr;
4815 }

◆ Finalize()

void duckdb::string_t::Finalize ( )
inline
4817 {
4818 // set trailing NULL byte
4819 if (GetSize() <= INLINE_LENGTH) {
4820 // fill prefix with zeros if the length is smaller than the prefix length
4821 memset(value.inlined.inlined + GetSize(), 0, INLINE_BYTES - GetSize());
4822 } else {
4823 // copy the data into the prefix
4824#ifndef DUCKDB_DEBUG_NO_INLINE
4825 auto dataptr = GetData();
4826 memcpy(value.pointer.prefix, dataptr, PREFIX_LENGTH);
4827#else
4828 memset(value.pointer.prefix, 0, PREFIX_BYTES);
4829#endif
4830 }
4831 }

◆ Verify()

void duckdb::string_t::Verify ( ) const
129037 {
129038#ifdef DEBUG
129039 VerifyUTF8();
129040#endif
129041
129042 VerifyCharacters();
129043}

◆ VerifyUTF8()

void duckdb::string_t::VerifyUTF8 ( ) const
129045 {
129046 auto dataptr = GetData();
129047 (void)dataptr;
129048 D_ASSERT(dataptr);
129049
129050 auto utf_type = Utf8Proc::Analyze(dataptr, GetSize());
129051 (void)utf_type;
129052 D_ASSERT(utf_type != UnicodeType::INVALID);
129053}
static UnicodeType Analyze(const char *s, size_t len, UnicodeInvalidReason *invalid_reason=nullptr, size_t *invalid_pos=nullptr)
Distinguishes ASCII, Valid UTF8 and Invalid UTF8 strings.
Definition duckdb.cpp:507297

◆ VerifyCharacters()

void duckdb::string_t::VerifyCharacters ( ) const
129055 {
129056 auto dataptr = GetData();
129057 (void)dataptr;
129058 D_ASSERT(dataptr);
129059
129060 // verify that the prefix contains the first four characters of the string
129061 for (idx_t i = 0; i < MinValue<idx_t>(PREFIX_LENGTH, GetSize()); i++) {
129062 D_ASSERT(GetPrefix()[i] == dataptr[i]);
129063 }
129064 // verify that for strings with length <= INLINE_LENGTH, the rest of the string is zero
129065 for (idx_t i = GetSize(); i < INLINE_LENGTH; i++) {
129066 D_ASSERT(GetData()[i] == '\0');
129067 }
129068}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ operator==()

bool duckdb::string_t::operator== ( const string_t & r) const
inline
4895 {
4896 return StringComparisonOperators::Equals(*this, r);
4897 }

◆ operator!=()

bool duckdb::string_t::operator!= ( const string_t & r) const
inline
4899 {
4900 return !(*this == r);
4901 }

◆ operator>()

bool duckdb::string_t::operator> ( const string_t & r) const
inline
4903 {
4904 return StringComparisonOperators::GreaterThan(*this, r);
4905 }

◆ operator<()

bool duckdb::string_t::operator< ( const string_t & r) const
inline
4906 {
4907 return r > *this;
4908 }

The documentation for this struct was generated from the following files: