InternedId Class Reference

#include <datatypelib.h>

Inheritance diagram for InternedId:

Detailed Description

InternedId represents an Id which has been interned into a pool of unique Id objects. I.e., there are no two different Id objects with an equal id string, so for equality comparison you can compare pointers instead of whole strings.

You can use MAXON_INTERNED_ID and MAXON_INTERNED_ID_LOCAL to define interned ids which will be initialized automatically at module initialization.

InternedId uses reference counting, so where possible use {const InternedId&} instead of InternedId to avoid unnecesssary reference counting.

Public Member Functions

 InternedId ()
 
 InternedId (InternedId &&src)
 
InternedIdoperator= (InternedId &&src)
 
 InternedId (const InternedId &src)
 
InternedIdoperator= (const InternedId &src)
 
 ~InternedId ()
 
Result< void > Init (const Id &i)
 
Result< void > Init (const CString &str)
 
Result< void > Init (const String &str)
 
Result< void > Init (const Char *str)
 
Result< void > Init (const Block< const Char > &str)
 
 operator const Id & () const
 
const IdGet () const
 
const IdGetPointer () const
 
Bool operator== (const InternedId &other) const
 
Bool operator!= (const InternedId &other) const
 
Bool operator< (const InternedId &other) const
 
 MAXON_OPERATOR_INEQUALITY (InternedId)
 
Bool operator== (const Id &other) const
 
Bool operator!= (const Id &other) const
 
COMPARERESULT Compare (const InternedId &other) const
 
UInt GetHashCode () const
 
const CharGetCString () const
 
Int GetCStringLength () const
 
Block< const CharToBlock () const
 
String ToString (const FormatStatement *fmt) const
 
Bool IsPopulated () const
 
Bool IsEmpty () const
 
void Reset ()
 

Static Public Member Functions

template<typename INPUTTYPE >
static Result< InternedIdCreate (INPUTTYPE &&inputId)
 
static const InternedIdNullValue ()
 

Static Public Attributes

static const InternedId NULL_VALUE
 

Static Private Member Functions

static void Free (const Id *ptr)
 

Private Attributes

const Id_id
 

Constructor & Destructor Documentation

◆ InternedId() [1/3]

Constructs an empty InternedId. You have to initialize it afterwards using Init().

◆ InternedId() [2/3]

InternedId ( InternedId &&  src)

◆ InternedId() [3/3]

InternedId ( const InternedId src)

◆ ~InternedId()

~InternedId ( )

Member Function Documentation

◆ operator=() [1/2]

InternedId& operator= ( InternedId &&  src)

◆ operator=() [2/2]

InternedId& operator= ( const InternedId src)

◆ Create()

static Result<InternedId> Create ( INPUTTYPE &&  inputId)
static

Creates a new InternedId for the given inputId. All types for which there is an InternedId::Init function are supported.

Parameters
[in]inputIdThe id to intern.
Template Parameters
INPUTTYPEThe type of inputId. All types for which there is an InternedId::Init function are supported.
Returns
The inputId converted to InternedId.

◆ Init() [1/5]

Result<void> Init ( const Id i)

Initializes an InternedId with a given Id.

Parameters
[in]iThe id to intern.
Returns
OK on success.

◆ Init() [2/5]

Result<void> Init ( const CString str)

Initializes an InternedId with a given CString.

Parameters
[in]strThe string to intern.
Returns
OK on success.

◆ Init() [3/5]

Result<void> Init ( const String str)

Initializes an InternedId with a given String.

Parameters
[in]strThe string to intern.
Returns
OK on success.

◆ Init() [4/5]

Result<void> Init ( const Char str)

Initializes an InternedId with a given C-style string.

Parameters
[in]strThe string to intern.
Returns
OK on success.

◆ Init() [5/5]

Result<void> Init ( const Block< const Char > &  str)

Initializes an InternedId with a given block of characters.

Parameters
[in]strThe string to intern, no null termination required.
Returns
OK on success.

◆ operator const Id &()

operator const Id & ( ) const

Returns the interned Id. The returned object is unique, i.e., there is no other interned Id with an equal string.

Returns
Interned Id.

◆ Get()

const Id& Get ( ) const

Returns the interned Id. The returned object is unique, i.e., there is no other interned Id with an equal string.

Returns
Interned Id.

◆ GetPointer()

const Id* GetPointer ( ) const

Returns a pointer to the interned Id. The pointer is unique, i.e., there is no other pointer to an interned Id with an equal string. The Id uses a special reference-counting, so you must only use the returned pointer as long as the owning InternedId is valid.

Returns
Unique pointer to the interned Id.

◆ operator==() [1/2]

Bool operator== ( const InternedId other) const

◆ operator!=() [1/2]

Bool operator!= ( const InternedId other) const

◆ operator<()

Bool operator< ( const InternedId other) const

◆ MAXON_OPERATOR_INEQUALITY()

MAXON_OPERATOR_INEQUALITY ( InternedId  )

◆ operator==() [2/2]

Bool operator== ( const Id other) const

◆ operator!=() [2/2]

Bool operator!= ( const Id other) const

◆ Compare()

COMPARERESULT Compare ( const InternedId other) const

Compares two InternedId objects using the lexicographic order.

Parameters
[in]otherOther InternedId object.
Returns
See COMPARERESULT.

◆ GetHashCode()

UInt GetHashCode ( ) const

◆ GetCString()

const Char* GetCString ( ) const

◆ GetCStringLength()

Int GetCStringLength ( ) const

◆ ToBlock()

Block<const Char> ToBlock ( ) const

◆ NullValue()

static const InternedId& NullValue ( )
static

◆ ToString()

String ToString ( const FormatStatement fmt) const

◆ IsPopulated()

Bool IsPopulated ( ) const

◆ IsEmpty()

Bool IsEmpty ( ) const

◆ Reset()

void Reset ( )

◆ Free()

static void Free ( const Id ptr)
staticprivate

Member Data Documentation

◆ NULL_VALUE

const InternedId NULL_VALUE
static

◆ _id

const Id* _id
private

Pointer to the interned id.