(ObjectLibrary) Added Query static method
Former-commit-id: 802dcc589dd2c552a332490153b6761341c0a698
This commit is contained in:
parent
53162c1722
commit
22e5230c32
|
|
@ -25,6 +25,7 @@ class NzObjectLibrary
|
|||
static bool Has(const NzString& name);
|
||||
|
||||
static void Register(const NzString& name, NzObjectRef<Type> object);
|
||||
static NzObjectRef<Type> Query(const NzString& name);
|
||||
static void Unregister(const NzString& name);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -8,14 +8,11 @@
|
|||
template<typename Type>
|
||||
NzObjectRef<Type> NzObjectLibrary<Type>::Get(const NzString& name)
|
||||
{
|
||||
auto it = Type::s_library.find(name);
|
||||
if (it != Type::s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
NzObjectRef<Type> ref = Query(name);
|
||||
if (!ref)
|
||||
NazaraError("Object \"" + name + "\" is not present");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
|
@ -30,6 +27,16 @@ void NzObjectLibrary<Type>::Register(const NzString& name, NzObjectRef<Type> obj
|
|||
Type::s_library.emplace(name, object);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
NzObjectRef<Type> NzObjectLibrary<Type>::Query(const NzString& name)
|
||||
{
|
||||
auto it = Type::s_library.find(name);
|
||||
if (it != Type::s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void NzObjectLibrary<Type>::Unregister(const NzString& name)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue