InternedId Class Reference

#include <datatypelib.h>

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.

Classes

struct  FastCompare
 

Public Types

using PrivateInfo = Tuple< UniqueHash >
 

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 (CString &&str)
 
Result< void > Init (const String &str)
 
Result< void > Init (const Char *str, Bool copyString=true)
 
Result< void > Init (const Block< const Char > &str)
 
 operator const Id & () const
 
const IdGet () const
 
const IdGetPointer () const
 
 operator InternedIdPtr () 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
 
HashInt GetHashCode () const
 
const UniqueHashGetUniqueHashCode () const
 
const CharGetCString () const
 
Int GetCStringLength () const
 
Block< const CharToBlock () const
 
String ToString (const FormatStatement *fmt=nullptr) const
 
CString ToCString () const
 
Bool IsPopulated () const
 
Bool IsEmpty () const
 
void Reset ()
 

Static Public Member Functions

template<typename INPUTTYPE >
static Result< InternedIdCreate (INPUTTYPE &&inputId)
 
template<UInt NUMBER>
static Result< InternedIdCreate ()
 
static MAXON_ATTRIBUTE_FORCE_INLINE const InternedIdDefaultValue ()
 
static void PrivateAddReference (const Id *ptr)
 

Static Public Attributes

static const InternedId DEFAULT_VALUE
 

Private Member Functions

void Release ()
 

Static Private Member Functions

static Bool IsReferenced (const Id *ptr)
 
static void Free (const Id *ptr)
 

Private Attributes

const Id_id
 

Static Private Attributes

static constexpr Int INFO_OFFSET
 

Friends

class SystemImpl
 
class ObjectModel
 

Member Typedef Documentation

◆ PrivateInfo

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() [1/2]

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.

◆ Create() [2/2]

static Result<InternedId> Create ( )
static

Creates a new InternedId for the given numerical value.

Template Parameters
NUMBERThe decimal number to intern as id.
Returns
The value converted to InternedId.

◆ Init() [1/6]

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/6]

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/6]

Result<void> Init ( CString &&  str)

Initializes an InternedId with a given CString.

Parameters
[in]strThe string to intern. The string is empty afterwards!
Returns
OK on success.

◆ Init() [4/6]

Result<void> Init ( const String str)

Initializes an InternedId with a given String.

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

◆ Init() [5/6]

Result<void> Init ( const Char str,
Bool  copyString = true 
)

Initializes an InternedId with a given C-style string.

Parameters
[in]strThe string to intern.
[in]copyStringIf true (the default value), a copy of str is made at first (which is then held via a strong reference).
Returns
OK on success.

◆ Init() [6/6]

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()

HashInt GetHashCode ( ) const

◆ GetUniqueHashCode()

const UniqueHash& GetUniqueHashCode ( ) const

Returns the 128-bit hash value of this @CLASS. The implementation ensures uniform distribution, so for practical purposes you can safely assume that two objects are equal if their hash values are equal.

Returns
Hash value of this @CLASS.

◆ GetCString()

const Char* GetCString ( ) const

◆ GetCStringLength()

Int GetCStringLength ( ) const

◆ ToBlock()

Block<const Char> ToBlock ( ) const

◆ DefaultValue()

static MAXON_ATTRIBUTE_FORCE_INLINE const InternedId& DefaultValue ( )
static

◆ ToString()

String ToString ( const FormatStatement fmt = nullptr) const

◆ ToCString()

CString ToCString ( ) const

◆ IsPopulated()

Bool IsPopulated ( ) const

◆ IsEmpty()

Bool IsEmpty ( ) const

◆ Reset()

void Reset ( )

◆ PrivateAddReference()

static void PrivateAddReference ( const Id ptr)
static

◆ IsReferenced()

static Bool IsReferenced ( const Id ptr)
staticprivate

◆ Release()

void Release ( )
private

◆ Free()

static void Free ( const Id ptr)
staticprivate

Friends And Related Function Documentation

◆ SystemImpl

friend class SystemImpl
friend

◆ ObjectModel

friend class ObjectModel
friend

Member Data Documentation

◆ DEFAULT_VALUE

const InternedId DEFAULT_VALUE
static

◆ _id

const Id* _id
private

Pointer to the interned id.

◆ INFO_OFFSET

constexpr Int INFO_OFFSET
staticconstexprprivate