ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
acav::InternedString Class Reference

Immutable string with automatic deduplication via global pool. More...

#include <InternedString.h>

Public Types

using value_type = std::string::value_type
using const_iterator = std::string::const_iterator

Public Member Functions

 InternedString (const std::string &v)
 Construct from std::string.
 InternedString (std::string &&v)
 Construct from std::string (move).
 InternedString (const char *v)
 Construct from C-string literal.
 InternedString (std::string_view v)
 Construct from string_view.
 InternedString (std::size_t n, char c)
 Construct string of n copies of character c.
 InternedString (const InternedString &other)
InternedString & operator= (const InternedString &other)
 InternedString (InternedString &&other) noexcept
InternedString & operator= (InternedString &&other) noexcept
const std::string & str () const
 Get the underlying string value.
bool empty () const noexcept
 Check if the string is empty.
std::size_t size () const noexcept
 Get string length.
const_iterator begin () const noexcept
const_iterator end () const noexcept
const char & operator[] (std::size_t pos) const
char & operator[] (std::size_t pos)
const char & back () const
const char * c_str () const
const char * data () const
void clear ()
 Clear the string (sets to empty interned string).
void push_back (char c)
InternedString & append (const char *s, std::size_t n)
InternedString & operator+= (const InternedString &other)
void resize (std::size_t n, char c='\0')
bool operator== (const InternedString &other) const noexcept
bool operator!= (const InternedString &other) const noexcept
std::size_t refCount () const noexcept
 Get reference count for this string.

Static Public Member Functions

static std::size_t poolSize ()
 Get current pool size (for debugging).
static void displayPool ()
 Display all strings in pool (for debugging).

Friends

bool operator< (const InternedString &lhs, const InternedString &rhs)

Detailed Description

Immutable string with automatic deduplication via global pool.

Provides memory-efficient string storage by sharing identical string values. Multiple instances with the same content point to the same underlying memory. Thread-safe, reference counted, and compatible with nlohmann::json.

Definition at line 55 of file InternedString.h.

Member Typedef Documentation

◆ const_iterator

using acav::InternedString::const_iterator = std::string::const_iterator

Definition at line 84 of file InternedString.h.

◆ value_type

using acav::InternedString::value_type = std::string::value_type

Definition at line 57 of file InternedString.h.

Constructor & Destructor Documentation

◆ InternedString() [1/7]

acav::InternedString::InternedString ( const std::string & v)
explicit

Construct from std::string.

Definition at line 85 of file InternedString.cpp.

◆ InternedString() [2/7]

acav::InternedString::InternedString ( std::string && v)
explicit

Construct from std::string (move).

Definition at line 89 of file InternedString.cpp.

◆ InternedString() [3/7]

acav::InternedString::InternedString ( const char * v)

Construct from C-string literal.

Definition at line 93 of file InternedString.cpp.

◆ InternedString() [4/7]

acav::InternedString::InternedString ( std::string_view v)
explicit

Construct from string_view.

Definition at line 96 of file InternedString.cpp.

◆ InternedString() [5/7]

acav::InternedString::InternedString ( std::size_t n,
char c )

Construct string of n copies of character c.

Definition at line 98 of file InternedString.cpp.

◆ InternedString() [6/7]

acav::InternedString::InternedString ( const InternedString & other)

Definition at line 101 of file InternedString.cpp.

◆ InternedString() [7/7]

acav::InternedString::InternedString ( InternedString && other)
noexcept

Definition at line 121 of file InternedString.cpp.

◆ ~InternedString()

acav::InternedString::~InternedString ( )

Definition at line 135 of file InternedString.cpp.

Member Function Documentation

◆ append()

InternedString & acav::InternedString::append ( const char * s,
std::size_t n )

Definition at line 188 of file InternedString.cpp.

◆ back()

const char & acav::InternedString::back ( ) const

Definition at line 173 of file InternedString.cpp.

◆ begin()

InternedString::const_iterator acav::InternedString::begin ( ) const
noexcept

Definition at line 149 of file InternedString.cpp.

◆ c_str()

const char * acav::InternedString::c_str ( ) const

Definition at line 175 of file InternedString.cpp.

◆ clear()

void acav::InternedString::clear ( )

Clear the string (sets to empty interned string).

Definition at line 179 of file InternedString.cpp.

◆ data()

const char * acav::InternedString::data ( ) const

Definition at line 177 of file InternedString.cpp.

◆ displayPool()

void acav::InternedString::displayPool ( )
static

Display all strings in pool (for debugging).

Definition at line 244 of file InternedString.cpp.

◆ empty()

bool acav::InternedString::empty ( ) const
noexcept

Check if the string is empty.

Definition at line 143 of file InternedString.cpp.

Referenced by str().

◆ end()

InternedString::const_iterator acav::InternedString::end ( ) const
noexcept

Definition at line 153 of file InternedString.cpp.

◆ operator!=()

bool acav::InternedString::operator!= ( const InternedString & other) const
noexcept

Definition at line 220 of file InternedString.cpp.

◆ operator+=()

InternedString & acav::InternedString::operator+= ( const InternedString & other)

Definition at line 195 of file InternedString.cpp.

◆ operator=() [1/2]

InternedString & acav::InternedString::operator= ( const InternedString & other)

Definition at line 109 of file InternedString.cpp.

◆ operator=() [2/2]

InternedString & acav::InternedString::operator= ( InternedString && other)
noexcept

Definition at line 126 of file InternedString.cpp.

◆ operator==()

bool acav::InternedString::operator== ( const InternedString & other) const
noexcept

Definition at line 215 of file InternedString.cpp.

◆ operator[]() [1/2]

char & acav::InternedString::operator[] ( std::size_t pos)

Definition at line 161 of file InternedString.cpp.

◆ operator[]() [2/2]

const char & acav::InternedString::operator[] ( std::size_t pos) const

Definition at line 157 of file InternedString.cpp.

◆ poolSize()

std::size_t acav::InternedString::poolSize ( )
static

Get current pool size (for debugging).

Definition at line 235 of file InternedString.cpp.

◆ push_back()

void acav::InternedString::push_back ( char c)

Definition at line 182 of file InternedString.cpp.

◆ refCount()

std::size_t acav::InternedString::refCount ( ) const
noexcept

Get reference count for this string.

Definition at line 240 of file InternedString.cpp.

◆ resize()

void acav::InternedString::resize ( std::size_t n,
char c = '\0' )

Definition at line 208 of file InternedString.cpp.

◆ size()

std::size_t acav::InternedString::size ( ) const
noexcept

Get string length.

Definition at line 145 of file InternedString.cpp.

◆ str()

const std::string & acav::InternedString::str ( ) const

Get the underlying string value.

Definition at line 138 of file InternedString.cpp.

References empty().

◆ operator<

bool operator< ( const InternedString & lhs,
const InternedString & rhs )
friend

Definition at line 224 of file InternedString.cpp.


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