Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Name Class Referencefinal

#include <Name.h>

Public Types

using Hash = Internal::NameData::Hash
 

Public Member Functions

 AZ_TYPE_INFO (Name, "{3D2B920C-9EFD-40D5-AAE0-DF131C3D4931}")
 
 AZ_CLASS_ALLOCATOR (Name, AZ::SystemAllocator)
 
 Name (const Name &name)
 
 Name (Name &&name)
 
Nameoperator= (const Name &)
 
Nameoperator= (Name &&)
 
 Name (AZStd::string_view name)
 
 Name (AZStd::string_view name, NameDictionary &nameDictionary)
 
 Name (Hash hash)
 
 Name (Hash hash, NameDictionary &nameDictionary)
 
 Name (NameRef name)
 Creates a name from a NameRef, an already existent name within the name dictionary.
 
Nameoperator= (AZStd::string_view name)
 
AZStd::string_view GetStringView () const
 
const char * GetCStr () const
 
bool IsEmpty () const
 
bool operator== (const Name &other) const
 
bool operator!= (const Name &other) const
 
bool operator== (const NameRef &other) const
 
bool operator!= (const NameRef &other) const
 
Hash GetHash () const
 Returns the string's hash that is used as the key in the NameDictionary.
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 
static Name FromStringLiteral (AZStd::string_view name, NameDictionary *nameDictionary)
 
static Name *& GetDeferredHead ()
 

Friends

bool operator< (const Name &lhs, const Name &rhs)=delete
 
bool operator<= (const Name &lhs, const Name &rhs)=delete
 
bool operator> (const Name &lhs, const Name &rhs)=delete
 
bool operator>= (const Name &lhs, const Name &rhs)=delete
 

Detailed Description

The Name class provides very fast string equality comparison, so that names can be used as IDs without sacrificing performance. It is a smart pointer to a NameData held in a NameDictionary, where names are tracked, de-duplicated, and ref-counted.

Creating a Name object with a value that doesn't exist in the dictionary is very slow. Creating a Name object with a value that already exists in the dictionary is similar to creating AZStd::string. Copy-constructing a Name object is very fast. Equality-comparison of two Name objects is very fast.

Names require the dictionary to be initialized before they are created, unless they are created from a string literal via Name::FromStringLiteral, in which they'll store their string for deferred initialization. A Name instance may only be statically declared using Name::FromStringLiteral (or the AZ_NAME_LITERAL helper macro).

Constructor & Destructor Documentation

◆ Name() [1/3]

AZ::Name::Name ( AZStd::string_view  name)
explicit

Creates an instance of a name from a string. The name string is used as a key to lookup an entry in the dictionary, and is not internally held after the call.

◆ Name() [2/3]

AZ::Name::Name ( Hash  hash)
explicit

Creates an instance of a name from a hash. The hash will be used to find an existing name in the dictionary. If there is no name with this hash, the resulting name will be empty.

◆ Name() [3/3]

AZ::Name::Name ( Hash  hash,
NameDictionary nameDictionary 
)

Lookup an instance of a name from a hash. This overload uses the supplied nameDictionary

Member Function Documentation

◆ FromStringLiteral()

static Name AZ::Name::FromStringLiteral ( AZStd::string_view  name,
NameDictionary nameDictionary 
)
static

Creates a Name from a string literal. FromStringLiteral is suitable for creating Names that live at a global or static scope.

Names created from string literals may exist without a NameDictionary, and may continue to persist after the NameDictionary is destroyed (even if it is destroyed multiple times, as in some text fixtures).

Warning
FromStringLiteral is not thread-safe and should only be called from the main thread.

◆ GetDeferredHead()

static Name *& AZ::Name::GetDeferredHead ( )
inlinestatic

For internal use: Gets a reference to the current head of the deferred Name linked list. The list is used to initialize Names created before the NameDictionary when their modules are loaded.

◆ GetStringView()

AZStd::string_view AZ::Name::GetStringView ( ) const

Returns the name's string value. This is always null-terminated. This will always point to a string in memory (i.e. it will return "" instead of null).

◆ operator=()

Name & AZ::Name::operator= ( AZStd::string_view  name)

Assigns a new name. The name string is used as a key to lookup an entry in the dictionary, and is not internally held after the call.


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