20 template<
typename TYPE>
23 template <
typename TYPE>
27 template <
typename TYPE>
65template <
typename ATTRIBUTE>
69 static_assert(!std::is_polymorphic<ATTRIBUTE>(),
"ATTRIBUTE must not be polymorpic.");
70 static_assert(!std::is_abstract<ATTRIBUTE>(),
"ATTRIBUTE must not be abstract.");
78template<
typename TYPE>
86 return reg->componentDescriptions[
id.id] !=
nullptr;
98template<
typename TYPE>
109 static_assert(!std::is_polymorphic<TYPE>(),
"TYPE must not be polymorpic.");
110 static_assert(!std::is_abstract<TYPE>(),
"TYPE must not be abstract.");
113 if (!reg->registry.Contains(name))
119 if (descriptor.id >= reg->componentDescriptions.Size())
121 SizeT prevSize = reg->componentDescriptions.Size();
122 reg->componentDescriptions.Resize(descriptor.id + 1);
123 SizeT num = reg->componentDescriptions.Size() - prevSize;
124 reg->componentDescriptions.Fill(prevSize, num,
nullptr);
127 reg->componentDescriptions[descriptor.id] = desc;
128 reg->registry.Add(name, descriptor);
134 n_error(
"Tried to register component named %s: Cannot register two components with same name!", name.
Value());
137 return AttributeId::Invalid();
144template <
typename TYPE>
148 static_assert(!std::is_polymorphic<TYPE>(),
"TYPE must not be polymorpic.");
149 static_assert(!std::is_abstract<TYPE>(),
"TYPE must not be abstract.");
152 if (!reg->registry.Contains(desc->
name))
155 if (attrId.id >= reg->componentDescriptions.Size())
157 SizeT prevSize = reg->componentDescriptions.Size();
158 reg->componentDescriptions.Resize(attrId.id + 1);
159 SizeT num = reg->componentDescriptions.Size() - prevSize;
160 reg->componentDescriptions.Fill(
161 prevSize, num,
nullptr
165 reg->componentDescriptions[attrId.id] = desc;
166 reg->registry.Add(desc->
name, attrId);
172 n_error(
"Tried to register component named %s: Cannot register two components with same name!", desc->
name.
Value());
175 return AttributeId::Invalid();
185 if (!reg->registry.Contains(name))
191 if (descriptor.id >= reg->componentDescriptions.Size())
193 reg->componentDescriptions.Resize(descriptor.id + 1);
197 reg->componentDescriptions[descriptor.id] = desc;
198 reg->registry.Add(name, descriptor);
203 n_error(
"Tried to register component named %s: Cannot register two components with same name!", name.
Value());
206 return AttributeId::Invalid();
216 IndexT index = reg->registry.FindIndex(name);
219 return reg->registry.ValueAtIndex(index);
222 return AttributeId::Invalid();
232 if (descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size())
235 reg->componentDescriptions[descriptor.id] !=
nullptr,
"Trying to get description of attribute that is not registered!"
237 return reg->componentDescriptions[descriptor.id];
250 n_assert(descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size());
251 return reg->componentDescriptions[descriptor.id]->typeSize;
261 n_assert(descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size());
262 return reg->componentDescriptions[descriptor.id]->externalFlags;
268inline void const*
const
272 n_assert(descriptor.id >= 0 && descriptor.id < reg->componentDescriptions.Size());
273 return reg->componentDescriptions[descriptor.id]->defVal;
283 return reg->componentDescriptions;
Definition attribute.h:29
Util::StringAtom name
name of attribute
Definition attribute.h:49
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:100
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:258
~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:269
AttributeRegistry()
Definition attributeregistry.cc:47
static AttributeId GetAttributeId(Util::StringAtom name)
get attribute id from name
Definition attributeregistry.h:213
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:247
static Util::FixedArray< Attribute * > const & GetAllAttributes()
get an array of all attributes
Definition attributeregistry.h:280
static Attribute * GetAttribute(AttributeId descriptor)
get attribute description by id
Definition attributeregistry.h:229
static AttributeRegistry * Singleton
Definition attributeregistry.h:53
static bool IsRegistered()
Check if a type is registered.
Definition attributeregistry.h:80
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:47
int SizeT
Definition types.h:42
int IndexT
Definition types.h:41