LiteralId Class Reference

#include <apibaseid.h>

Inheritance diagram for LiteralId:

Detailed Description

LiteralId is used as base class of Id. It may only be used for strings such as string literals which have a longer lifetime than the LiteralId object itself. The benefit is that LiteralId is a literal type and has a trivial destructor.

Public Member Functions

constexpr LiteralId ()
 
constexpr LiteralId (const LiteralId &)=default
 
MAXON_IMPLICIT LiteralId (const Id &)=delete
 
constexpr LiteralIdoperator= (const LiteralId &)=default
 
LiteralIdoperator= (const Id &)=delete
 
template<UInt N>
constexpr LiteralId (const Char(&str)[N])
 
Bool operator== (const LiteralId &other) const
 
Bool operator< (const LiteralId &other) const
 
 MAXON_OPERATOR_COMPARISON (LiteralId)
 
COMPARERESULT Compare (const LiteralId &other) const
 
constexpr HashInt GetHashCode () const
 
UniqueHash GetUniqueHashCode () const
 
constexpr Bool IsEmpty () const
 
constexpr Bool IsPopulated () const
 
constexpr const CharGetCString () const
 
constexpr Int GetCStringLength () const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
CString ToCString () const
 
Block< const CharToBlock () const
 
const IdGet () const
 
 operator const Id & () const
 
Bool UsesStrongReference () const
 
template<UInt N>
constexpr LiteralId (bool dummy, const Char(&str)[N])
 
constexpr LiteralId (bool dummy, const LiteralId &src)
 
template<typename T , typename = typename T::DeclarationHelper>
constexpr LiteralId (bool dummy, const T &decl)
 
template<typename T , typename = typename T::DeclarationHelper>
constexpr LiteralId (int dummy, const T &decl)
 
template<typename T , typename = typename std::enable_if<std::is_base_of<InternedIdFidBase, T>::value>::type>
Bool operator== (const T &other) const
 
template<typename T , typename = typename std::enable_if<std::is_base_of<InternedIdFidBase, T>::value>::type>
Bool operator!= (const T &other) const
 

Static Public Member Functions

static constexpr HashInt GetHashCode (const Char *str)
 

Static Public Attributes

static const Int MAX_LENGTH_EXPONENT
 
static const UInt LOW_HASH_MASK
 
static const Int MAX_LENGTH
 

Protected Member Functions

constexpr LiteralId (const Char *value, UInt hash)
 
 LiteralId (ENUM_DONT_INITIALIZE)
 

Protected Attributes

const Char_value
 
UInt _hash
 

Static Protected Attributes

static const Int RC_STRING_BIT
 
static const UInt RC_STRING_MASK
 
static const UInt HASH_MASK
 

Friends

class EntityBase
 

Constructor & Destructor Documentation

◆ LiteralId() [1/10]

constexpr LiteralId ( )
constexpr

◆ LiteralId() [2/10]

constexpr LiteralId ( const LiteralId )
constexprdefault

◆ LiteralId() [3/10]

MAXON_IMPLICIT LiteralId ( const Id )
delete

◆ LiteralId() [4/10]

constexpr LiteralId ( const Char(&)  str[N])
explicitconstexpr

◆ LiteralId() [5/10]

constexpr LiteralId ( bool  dummy,
const Char(&)  str[N] 
)
constexpr

◆ LiteralId() [6/10]

constexpr LiteralId ( bool  dummy,
const LiteralId src 
)
constexpr

◆ LiteralId() [7/10]

constexpr LiteralId ( bool  dummy,
const T &  decl 
)
constexpr

◆ LiteralId() [8/10]

constexpr LiteralId ( int  dummy,
const T &  decl 
)
constexpr

◆ LiteralId() [9/10]

constexpr LiteralId ( const Char value,
UInt  hash 
)
constexprprotected

◆ LiteralId() [10/10]

LiteralId ( ENUM_DONT_INITIALIZE  )
explicitprotected

Member Function Documentation

◆ operator=() [1/2]

constexpr LiteralId& operator= ( const LiteralId )
constexprdefault

◆ operator=() [2/2]

LiteralId& operator= ( const Id )
delete

◆ operator==() [1/2]

Bool operator== ( const LiteralId other) const

◆ operator<()

Bool operator< ( const LiteralId other) const

◆ MAXON_OPERATOR_COMPARISON()

MAXON_OPERATOR_COMPARISON ( LiteralId  )

◆ Compare()

COMPARERESULT Compare ( const LiteralId other) const

Compares two Id objects using the lexicographic order.

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

◆ GetHashCode() [1/2]

constexpr HashInt GetHashCode ( ) const
constexpr

◆ GetUniqueHashCode()

UniqueHash GetUniqueHashCode ( ) const

◆ IsEmpty()

constexpr Bool IsEmpty ( ) const
constexpr

Checks if the Id is empty.

Returns
True if the Id contains a nullptr as c-string.

◆ IsPopulated()

constexpr Bool IsPopulated ( ) const
constexpr

Checks if this Id contains anything.

Returns
True if the ID contains a c-string.

◆ GetCString()

constexpr const Char* GetCString ( ) const
constexpr

Returns the internal c-string. No copy is made.

Returns
Internal string.

◆ GetCStringLength()

constexpr Int GetCStringLength ( ) const
constexpr

Returns the length of the internal c-string. This function doesn't have to scan the string, because the length is directly available in the Id.

Returns
Length of internal string.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.
Returns
The converted result.

◆ ToCString()

CString ToCString ( ) const

◆ Get()

const Id& Get ( ) const

◆ operator const Id &()

operator const Id & ( ) const

◆ UsesStrongReference()

Bool UsesStrongReference ( ) const

Returns true if this Id uses a strong reference for the internal string. Otherwise, the Id uses a global c-string which is assumed to persist at least as long as the Id.

Returns
True if the Id uses a strong reference.

◆ GetHashCode() [2/2]

static constexpr HashInt GetHashCode ( const Char str)
staticconstexpr
Parameters
[in]strMust not be nullptr.
Returns
Hash valiue.

◆ operator==() [2/2]

Bool operator== ( const T &  other) const

◆ operator!=()

Bool operator!= ( const T &  other) const

Friends And Related Function Documentation

◆ EntityBase

friend class EntityBase
friend

Member Data Documentation

◆ MAX_LENGTH_EXPONENT

const Int MAX_LENGTH_EXPONENT
static

◆ LOW_HASH_MASK

const UInt LOW_HASH_MASK
static

Mask for the lower bits of the hash (the part which corresponds to the hash code of the string).

◆ RC_STRING_BIT

const Int RC_STRING_BIT
staticprotected

Bit position in _hash of the bit which is set when the Id uses a strong reference on the string.

◆ RC_STRING_MASK

const UInt RC_STRING_MASK
staticprotected

Mask to get the RC_STRING_BIT from _hash.

◆ HASH_MASK

const UInt HASH_MASK
staticprotected

Mask to get the hash code from _hash.

◆ MAX_LENGTH

const Int MAX_LENGTH
static

◆ _value

const Char* _value
protected

C-string identifier. If the RC_STRING_BIT is set in _hash, the pointee is held by a strong reference.

◆ _hash

UInt _hash
protected

Combination of hash code (lower bits), then a bit at RC_STRING_BIT and finally the string length (MAX_LENGTH_EXPONENT bits). Use HASH_MASK to mask out the RC_STRING_BIT.