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
duckdb::String Class Reference

Public Member Functions

 String (const std::string &str)
 
 String (const char *str, const uint32_t size)
 
 String (const char *str)
 
 String (const String &other)=delete
 
Stringoperator= (const String &other)=delete
 
 String (String &&other) noexcept
 
Stringoperator= (String &&other) noexcept
 
bool operator== (const String &other) const
 
bool operator== (const std::string &other) const
 
bool operator== (const char *other) const
 
bool operator> (const String &other) const
 
bool operator!= (const String &other) const
 
bool operator< (const String &other) const
 
bool operator>= (const String &other) const
 
bool operator<= (const String &other) const
 
char operator[] (const idx_t pos) const
 
uint32_t size () const
 
bool empty () const
 
const chardata () const
 
const charbegin () const
 
const charend () const
 
const charc_str () const
 
bool IsOwning () const
 
bool IsInlined () const
 
String Copy () const
 
String Reference () const
 
std::string ToStdString () const
 
String Lower () const
 

Static Public Member Functions

static bool CanBeInlined (uint32_t size)
 
static String Copy (const char *data, uint32_t size)
 
static String Copy (const String &other)
 
static String Copy (const char *data)
 
static String Copy (const std::string &str)
 
static String Reference (const char *data, uint32_t size)
 
static String Reference (const String &other)
 
static String Reference (const char *data)
 
static String Reference (const std::string &str)
 
static uint32_t SafeStrLen (const char *data)
 
static uint32_t SafeStrLen (const std::string &data)
 
static char CharacterToLower (char c)
 

Private Member Functions

void AssignOwning (const char *new_data, uint32_t new_size)
 
void Destroy ()
 
void ReleaseOwning ()
 
void TransferOwnership (String &other)
 

Private Attributes

uint32_t len
 
union { 
 
   const char *   ptr 
 
   char   buf [INLINE_CAP] 
 
};  
 

Static Private Attributes

static constexpr auto INLINE_CAP = sizeof(char *)
 
static constexpr auto INLINE_MAX = INLINE_CAP - 1
 
static constexpr auto NON_OWNING_BIT = 1UL << (sizeof(uint32_t) * 8 - 1)
 
static constexpr auto LENGTH_MAX = (1UL << (sizeof(uint32_t) * 8 - 1)) - 1
 

Constructor & Destructor Documentation

◆ String() [1/5]

duckdb::String::String ( )
inline
6712 : len(0), buf {0} {
6713 }

◆ String() [2/5]

duckdb::String::String ( const std::string &  str)
inline
6715 { // NOLINT allowimplicit conversion
6716 AssignOwning(str.data(), SafeStrLen(str));
6717 }

◆ String() [3/5]

duckdb::String::String ( const char str,
const uint32_t  size 
)
inline
6719 {
6720 AssignOwning(str, size);
6721 }

◆ String() [4/5]

duckdb::String::String ( const char str)
inline
6724 : String(str, str ? SafeStrLen(str) : 0) {
6725 }
std::string String

◆ String() [5/5]

duckdb::String::String ( String &&  other)
inlinenoexcept
6733 {
6734 TransferOwnership(other);
6735 }

◆ ~String()

duckdb::String::~String ( )
inline
6747 {
6748 Destroy();
6749 }

Member Function Documentation

◆ operator=()

String & duckdb::String::operator= ( String &&  other)
inlinenoexcept
6738 {
6739 if (this != &other) {
6740 Destroy();
6741 TransferOwnership(other);
6742 }
6743 return *this;
6744 }

◆ operator==() [1/3]

bool duckdb::String::operator== ( const String other) const
inline
6753 {
6754 if (this == &other) {
6755 return true; // points to the same instance
6756 }
6757
6758 if (size() != other.size()) {
6759 return false;
6760 }
6761
6762 return memcmp(data(), other.data(), size()) == 0;
6763 }

◆ operator==() [2/3]

bool duckdb::String::operator== ( const std::string &  other) const
inline
6765 {
6766 if (SafeStrLen(other) != size()) {
6767 return false;
6768 }
6769 return memcmp(data(), other.data(), size()) == 0;
6770 }

◆ operator==() [3/3]

bool duckdb::String::operator== ( const char other) const
inline
6772 {
6773 if (!other || SafeStrLen(other) != size()) {
6774 return false;
6775 }
6776
6777 if (this->data() == other) {
6778 return true; // points to the same instance
6779 }
6780
6781 return memcmp(data(), other, size()) == 0;
6782 }

◆ operator>()

bool duckdb::String::operator> ( const String other) const
inline
6784 {
6785 const auto this_size = size();
6786 const auto other_size = other.size();
6787 const auto min_size = MinValue<idx_t>(this_size, other_size);
6788
6789 auto memcmp_res = memcmp(data(), other.data(), min_size);
6790 return memcmp_res > 0 || (memcmp_res == 0 && this_size > other_size);
6791 }

◆ operator!=()

bool duckdb::String::operator!= ( const String other) const
inline
6793 {
6794 return !(*this == other);
6795 }

◆ operator<()

bool duckdb::String::operator< ( const String other) const
inline
6796 {
6797 return other > *this;
6798 }

◆ operator>=()

bool duckdb::String::operator>= ( const String other) const
inline
6799 {
6800 return !(*this < other);
6801 }

◆ operator<=()

bool duckdb::String::operator<= ( const String other) const
inline
6802 {
6803 return !(*this > other);
6804 }

◆ operator[]()

char duckdb::String::operator[] ( const idx_t  pos) const
inline
6806 {
6807 D_ASSERT(pos < size());
6808
6809 if (IsInlined()) {
6810 return buf[pos];
6811 }
6812 return ptr[pos];
6813 }

◆ size()

uint32_t duckdb::String::size ( ) const
inline
6818 {
6819 return len & ~NON_OWNING_BIT;
6820 }

◆ empty()

bool duckdb::String::empty ( ) const
inline
6821 {
6822 return len == 0;
6823 }

◆ data()

const char * duckdb::String::data ( ) const
inline
6824 {
6825 return IsInlined() ? buf : ptr;
6826 }

◆ begin()

const char * duckdb::String::begin ( ) const
inline
6827 {
6828 return data();
6829 }

◆ end()

const char * duckdb::String::end ( ) const
inline
6830 {
6831 return data() + size();
6832 }

◆ c_str()

const char * duckdb::String::c_str ( ) const
inline
6833 {
6834 return data();
6835 }

◆ IsOwning()

bool duckdb::String::IsOwning ( ) const
inline
6839 {
6840 return (len & NON_OWNING_BIT) == 0;
6841 }

◆ IsInlined()

bool duckdb::String::IsInlined ( ) const
inline
6843 {
6844 return len <= INLINE_MAX;
6845 }

◆ CanBeInlined()

static bool duckdb::String::CanBeInlined ( uint32_t  size)
inlinestatic
6847 {
6848 return size <= INLINE_MAX;
6849 }

◆ Copy() [1/5]

static String duckdb::String::Copy ( const char data,
uint32_t  size 
)
inlinestatic
6852 {
6853 if (data == nullptr) {
6854 return String(); // Return an empty String
6855 }
6856
6857 String result;
6858 result.AssignOwning(data, size);
6859 return result;
6860 }

◆ Copy() [2/5]

static String duckdb::String::Copy ( const String other)
inlinestatic
6862 {
6863 return Copy(other.data(), other.size());
6864 }

◆ Copy() [3/5]

static String duckdb::String::Copy ( const char data)
inlinestatic
6865 {
6866 return Copy(data, data ? SafeStrLen(data) : 0);
6867 }

◆ Copy() [4/5]

static String duckdb::String::Copy ( const std::string &  str)
inlinestatic
6868 {
6869 return Copy(str.data(), SafeStrLen(str));
6870 }

◆ Copy() [5/5]

String duckdb::String::Copy ( ) const
inline
6871 {
6872 return String::Copy(data(), size());
6873 }

◆ Reference() [1/5]

static String duckdb::String::Reference ( const char data,
uint32_t  size 
)
inlinestatic
6877 {
6878 if (data == nullptr) {
6879 return String(); // Return an empty String
6880 }
6881
6882 String result;
6883 // If we reference, and we can inline it, we make owning anyway
6884 if (size <= INLINE_MAX) {
6885 result.AssignOwning(data, size);
6886 } else {
6887 result.ptr = const_cast<char *>(data); // NOLINT allow const cast
6888 result.len = size | NON_OWNING_BIT; // Set the non-owning bit
6889 }
6890 return result;
6891 }

◆ Reference() [2/5]

static String duckdb::String::Reference ( const String other)
inlinestatic
6893 {
6894 return Reference(other.data(), other.size());
6895 }

◆ Reference() [3/5]

static String duckdb::String::Reference ( const char data)
inlinestatic
6896 {
6897 return Reference(data, data ? SafeStrLen(data) : 0);
6898 }

◆ Reference() [4/5]

static String duckdb::String::Reference ( const std::string &  str)
inlinestatic
6899 {
6900 return Reference(str.data(), SafeStrLen(str));
6901 }

◆ Reference() [5/5]

String duckdb::String::Reference ( ) const
inline
6902 {
6903 return String::Reference(data(), size());
6904 }

◆ ToStdString()

std::string duckdb::String::ToStdString ( ) const
inline
6906 {
6907 if (IsInlined()) {
6908 return std::string(buf, size());
6909 }
6910 return std::string(ptr, size());
6911 }

◆ SafeStrLen() [1/2]

static uint32_t duckdb::String::SafeStrLen ( const char data)
inlinestatic
6913 {
6914 if (!data) {
6915 return 0;
6916 }
6917
6918 const auto len = strlen(data);
6919 D_ASSERT(len < NumericLimits<uint32_t>::Maximum());
6920 return static_cast<uint32_t>(len);
6921 }
::uint32_t uint32_t

◆ SafeStrLen() [2/2]

static uint32_t duckdb::String::SafeStrLen ( const std::string &  data)
inlinestatic
6923 {
6924 const auto len = data.size();
6925 D_ASSERT(len < NumericLimits<uint32_t>::Maximum());
6926 return static_cast<uint32_t>(len);
6927 }

◆ CharacterToLower()

static char duckdb::String::CharacterToLower ( char  c)
inlinestatic
6930 {
6931 if (c >= 'A' && c <= 'Z') {
6932 return UnsafeNumericCast<char>(c + ('a' - 'A'));
6933 }
6934 return c;
6935 }

◆ Lower()

String duckdb::String::Lower ( ) const
inline
6937 {
6938 const auto str_data = data();
6939 const auto str_size = size();
6940
6941 std::string lowercase_str;
6942 lowercase_str.reserve(str_size);
6943 for (idx_t i = 0; i < str_size; ++i) {
6944 lowercase_str.push_back(CharacterToLower(str_data[i]));
6945 }
6946 return String(lowercase_str);
6947 }

◆ AssignOwning()

void duckdb::String::AssignOwning ( const char new_data,
uint32_t  new_size 
)
inlineprivate
6955 {
6956 len = new_data ? new_size : 0;
6957
6958 if (len == 0) {
6959 buf[len] = '\0'; // Null-terminate the inline buffer
6960 return;
6961 }
6962
6963 if (len <= INLINE_MAX) {
6964 memcpy(buf, new_data, len);
6965 buf[len] = '\0'; // Null-terminate the inline buffer
6966 return;
6967 }
6968
6969 auto new_ptr = new char[len + 1]; // +1 for null-termination
6970 memcpy(new_ptr, new_data, len);
6971 new_ptr[len] = '\0';
6972
6973 ptr = new_ptr;
6974 }

◆ Destroy()

void duckdb::String::Destroy ( )
inlineprivate
6976 {
6977 if (IsOwning() && !IsInlined()) {
6978 delete[] ptr;
6979 }
6980 }

◆ ReleaseOwning()

void duckdb::String::ReleaseOwning ( )
inlineprivate
6983 {
6984 // Set the non-owning bit
6985 if (IsOwning() && !IsInlined()) {
6986 len |= NON_OWNING_BIT;
6987 }
6988 }

◆ TransferOwnership()

void duckdb::String::TransferOwnership ( String other)
inlineprivate
6990 {
6991 len = other.len;
6992 if (IsInlined()) {
6993 AssignOwning(other.data(), other.size());
6994 } else {
6995 ptr = other.ptr;
6996 len = other.len;
6997 }
6998 other.ReleaseOwning();
6999 }

The documentation for this class was generated from the following file: