Id Class Reference

#include <apibaseid.h>

Inheritance diagram for Id:

Detailed Description

Id represents an identifier consisting of a c-string. Such identifiers are used mainly to identify entities such as interfaces, components, classes, registries, entries, modules or published objects.

Public Member Functions

constexpr Id ()
 
 Id (const volatile Char *str)
 
template<UInt N>
constexpr Id (const Char(&str)[N])
 
 Id (Id &&other)
 
 Id (const Id &other)
 
 ~Id ()
 
void Reset ()
 
 MAXON_OPERATOR_MOVE_ASSIGNMENT (Id)
 
Idoperator= (const Id &other)
 
ResultMem Init (const Char *str, Bool copyString)
 
ResultMem Init (const Block< const Char > &str)
 
ResultMem Init (const CString &str)
 
ResultMem Init (CString &&str)
 
ResultMem Init (const String &str)
 
void Init (const InternedId &id)
 
void InitReference (const Char *str)
 
- Public Member Functions inherited from LiteralId
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 MAXON_ATTRIBUTE_FORCE_INLINE const IdDefaultValue ()
 
template<typename... INPUTTYPE>
static Result< IdCreate (INPUTTYPE &&... inputId)
 
- Static Public Member Functions inherited from LiteralId
static constexpr HashInt GetHashCode (const Char *str)
 

Private Member Functions

 Id (const CString &)=delete
 
void AddStrReference ()
 
void RemoveStrReference ()
 

Additional Inherited Members

- Static Public Attributes inherited from LiteralId
static const Int MAX_LENGTH_EXPONENT
 
static const UInt LOW_HASH_MASK
 
static const Int MAX_LENGTH
 
- Protected Member Functions inherited from LiteralId
constexpr LiteralId (const Char *value, UInt hash)
 
 LiteralId (ENUM_DONT_INITIALIZE)
 
- Protected Attributes inherited from LiteralId
const Char_value
 
UInt _hash
 
- Static Protected Attributes inherited from LiteralId
static const Int RC_STRING_BIT
 
static const UInt RC_STRING_MASK
 
static const UInt HASH_MASK
 

Constructor & Destructor Documentation

◆ Id() [1/6]

constexpr Id ( )
constexpr

Constructs a null Id. The internal c-string will be nullptr.

◆ Id() [2/6]

Id ( const volatile Char str)
explicit

Constructs an Id for a given c-string. str is used directly for the internal c-string pointer.

Warning
The c-string has to exist at least as long as the constructed Id. If you can't guarantee that, you have to use the Init function.
Parameters
[in]strIdentifier as c-string, may be nullptr. This will always be used directly, i.e., no copy is made.

◆ Id() [3/6]

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

◆ Id() [4/6]

Id ( Id &&  other)

Constructs an Id by moving the values from another Id.

Parameters
[in]otherAnother Id to move from.

◆ Id() [5/6]

Id ( const Id other)

Copy constructs an Id from another Id.

Parameters
[in]otherAnother Id to copy from.

◆ ~Id()

~Id ( )

Destructs the Id. If the Id uses a strong reference, the reference will be removed.

◆ Id() [6/6]

Id ( const CString )
explicitprivatedelete

Member Function Documentation

◆ DefaultValue()

static MAXON_ATTRIBUTE_FORCE_INLINE const Id& DefaultValue ( )
static

◆ Reset()

void Reset ( )

Resets the Id. Afterwards, its internal c-string will be nullptr.

◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( Id  )

◆ operator=()

Id& operator= ( const Id other)

◆ Init() [1/6]

ResultMem Init ( const Char str,
Bool  copyString 
)

Sets this Id to a new value. If copyString is false, str is used directly for the internal c-string pointer, and it is assumed that the c-string exists at least as long as this Id. Otherwise, if copyString is true, a copy of str is created and held by a strong reference.

Parameters
[in]strIdentifier as c-string, may be nullptr.
[in]copyStringIf true, a copy of str is made at first (and then held by a strong reference).
Returns
False if a copy had to be made, but the allocation failed. True otherwise.

◆ Init() [2/6]

ResultMem Init ( const Block< const Char > &  str)

Sets this Id to str. A copy of str is created and used for the internal c-string (as a strong reference).

Parameters
[in]strIdentifier as a block of characters (no null termination required).
Returns
False if a copy had to be made, but the allocation failed. True otherwise.

◆ Init() [3/6]

ResultMem Init ( const CString str)

Sets this Id to str. A copy of str is created and used for the internal c-string (as a strong reference).

Parameters
[in]strIdentifier as CString.
Returns
False if a copy had to be made, but the allocation failed. True otherwise.

◆ Init() [4/6]

ResultMem Init ( CString &&  str)

Sets this Id to str. A copy of str is created and used for the internal c-string (as a strong reference).

Parameters
[in]strIdentifier as CString, The string is empty afterwards!
Returns
False if a copy had to be made, but the allocation failed. True otherwise.

◆ Init() [5/6]

ResultMem Init ( const String str)

Sets this Id to str.

Parameters
[in]strIdentifier as String.
Returns
False if the allocation failed. True otherwise.

◆ Init() [6/6]

void Init ( const InternedId id)

Sets this Id to id.

Parameters
[in]idInterned Id.

◆ InitReference()

void InitReference ( const Char str)

Sets this Id to str, where str has to be a dynamically allocated string which can be shared using strong references. This Id must be in empty state when calling this function.

Parameters
[in]strIdentifier as a dynamically allocated c-string, must not be nullptr.

◆ Create()

Result< Id > Create ( INPUTTYPE &&...  inputId)
static

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

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

◆ AddStrReference()

void AddStrReference ( )
private

◆ RemoveStrReference()

void RemoveStrReference ( )
private