#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) | |
Name & | operator= (const Name &) |
Name & | operator= (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. | |
Name & | operator= (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 |
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).
|
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.
|
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.
AZ::Name::Name | ( | Hash | hash, |
NameDictionary & | nameDictionary | ||
) |
Lookup an instance of a name from a hash. This overload uses the supplied 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).
|
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.
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).
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.