20 template<
typename TYPE>
23 template <
typename TYPE>
27 template <
typename TYPE>
65template <
typename ATTRIBUTE>
69 static_assert(std::is_trivially_destructible<ATTRIBUTE>());
77template<
typename TYPE>
85 return reg->componentDescriptions[
id.id] !=
nullptr;
97template<
typename TYPE>
108 static_assert(!std::is_polymorphic<TYPE>(),
"TYPE must not be polymorpic.");
109 static_assert(!std::is_abstract<TYPE>(),
"TYPE must not be abstract.");
112 if (!reg->registry.Contains(name))
118 if (descriptor.id >= reg->componentDescriptions.Size())
120 SizeT prevSize = reg->componentDescriptions.Size();
121 reg->componentDescriptions.Resize(descriptor.id + 1);
122 SizeT num = reg->componentDescriptions.Size() - prevSize;
123 reg->componentDescriptions.Fill(prevSize, num,
nullptr);
126 reg->componentDescriptions[descriptor.id] = desc;
127 reg->registry.Add(name, descriptor);
133 n_error(
"Tried to register component named %s: Cannot register two components with same name!", name.
Value());
136 return AttributeId::Invalid();
143template <
typename TYPE>
147 static_assert(!std::is_polymorphic<TYPE>(),
"TYPE must not be polymorpic.");
148 static_assert(!std::is_abstract<TYPE>(),
"TYPE must not be abstract.");
151 if (!reg->registry.Contains(desc->
name))
154 if (attrId.id >= reg->componentDescriptions.Size())
156 SizeT prevSize = reg->componentDescriptions.Size();
157 reg->componentDescriptions.Resize(attrId.id + 1);
158 SizeT num = reg->componentDescriptions.Size() - prevSize;
159 reg->componentDescriptions.Fill(
160 prevSize, num,
nullptr
164 reg->componentDescriptions[attrId.id] = desc;
165 reg->registry.Add(desc->
name, attrId);
171 n_error(
"Tried to register component named %s: Cannot register two components with same name!", desc->
name.
Value());
174 return AttributeId::Invalid();
184 if (!reg->registry.Contains(name))
190 if (descriptor.id >= reg->componentDescriptions.Size())
192 reg->componentDescriptions.Resize(descriptor.id + 1);
196 reg->componentDescriptions[descriptor.id] = desc;
197 reg->registry.Add(name, descriptor);
202 n_error(
"Tried to register component named %s: Cannot register two components with same name!", name.
Value());
205 return AttributeId::Invalid();
215 IndexT index = reg->registry.FindIndex(name);
218 return reg->registry.ValueAtIndex(index);
221 return AttributeId::Invalid();
231 if (descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size())
234 reg->componentDescriptions[descriptor.id] !=
nullptr,
"Trying to get description of attribute that is not registered!"
236 return reg->componentDescriptions[descriptor.id];
249 n_assert(descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size());
250 return reg->componentDescriptions[descriptor.id]->typeSize;
260 n_assert(descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size());
261 return reg->componentDescriptions[descriptor.id]->externalFlags;
267inline void const*
const
271 n_assert(descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size());
272 return reg->componentDescriptions[descriptor.id]->defVal;
282 return reg->componentDescriptions;
Definition attribute.h:29
Util::StringAtom name
name of attribute
Definition attribute.h:49
Definition attributeregistry.h:17
Util::FixedArray< Attribute * > componentDescriptions
Definition attributeregistry.h:55
static AttributeId Register(Util::StringAtom name, TYPE defaultValue, uint32_t flags=0)
register a type (templated)
Definition attributeregistry.h:99
static AttributeRegistry * Instance()
The registry's constructor is called by the Instance() method, and nobody else.
Definition attributeregistry.cc:18
static uint32_t Flags(AttributeId descriptor)
get flags by attribute id
Definition attributeregistry.h:257
~AttributeRegistry()
Definition attributeregistry.cc:55
Util::Dictionary< Util::StringAtom, AttributeId > registry
Definition attributeregistry.h:56
static void const *const DefaultValue(AttributeId descriptor)
get attribute default value pointer
Definition attributeregistry.h:268
AttributeRegistry()
Definition attributeregistry.cc:47
static AttributeId GetAttributeId(Util::StringAtom name)
get attribute id from name
Definition attributeregistry.h:212
static void Destroy()
This static method is used to destroy the registry object and should be called right before the main ...
Definition attributeregistry.cc:35
static SizeT TypeSize(AttributeId descriptor)
get type size by attribute id
Definition attributeregistry.h:246
static Util::FixedArray< Attribute * > const & GetAllAttributes()
get an array of all attributes
Definition attributeregistry.h:279
static Attribute * GetAttribute(AttributeId descriptor)
get attribute description by id
Definition attributeregistry.h:228
static AttributeRegistry * Singleton
Definition attributeregistry.h:53
static bool IsRegistered()
Check if a type is registered.
Definition attributeregistry.h:79
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
A StringAtom.
Definition stringatom.h:22
const char * Value() const
get contained string as char ptr (fast)
Definition stringatom.h:362
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define n_assert2(exp, msg)
Definition debug.h:51
#define n_assert(exp)
Definition debug.h:50
Attribute.
Definition attribute.h:26
uint16_t GenerateNewAttributeId()
Do not use.
Definition attributeregistry.cc:65
AttributeId GetAttributeId()
Definition attributeregistry.h:67
Definition attributeid.h:19
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48