Nebula
Loading...
Searching...
No Matches
attributedefinitionbase.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13#include "core/types.h"
14#include "util/fourcc.h"
15#include "util/string.h"
16#include "util/hashtable.h"
17#include "util/dictionary.h"
18#include "valuetype.h"
19#include "accessmode.h"
20#include "attrexithandler.h"
21#include "util/string.h"
22#include "util/blob.h"
23#include "math/quat.h"
24#include "math/transform44.h"
25
26//------------------------------------------------------------------------------
27namespace Attr
28{
30{
31public:
34 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const byte& defVal, bool isDynamic);
36 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const short& defVal, bool isDynamic);
40 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const int& defVal, bool isDynamic);
44 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const int64_t& defVal, bool isDynamic);
46 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const uint64_t& defVal, bool isDynamic);
48 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const float& defVal, bool isDynamic);
50 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const double& defVal, bool isDynamic);
52 explicit AttributeDefinitionBase(const Util::String& name, const Util::String& typeName, const Util::FourCC& fourCC, AccessMode accessMode, const bool& defVal, bool isDynamic);
91
95 static void Destroy();
96
98 bool IsDynamic() const;
100 const Util::String& GetName() const;
102 const Util::FourCC& GetFourCC() const;
104 const Util::String& GetTypeName() const;
106 const Util::Variant& GetDefaultValue() const;
108 const uint GetSizeOfType() const;
112 ValueType GetValueType() const;
114 static const AttributeDefinitionBase* FindByName(const Util::String& n);
116 static const AttributeDefinitionBase* FindByFourCC(const Util::FourCC& fcc);
120 static void ClearDynamicAttributes();
121
123 static void InitializeRegistry();
124
125protected:
127 void Register();
128
129private:
133 static void CheckCreateNameRegistry();
135 static void CheckCreateFourCCRegistry();
138
146
147 friend class AttrId;
152
159};
160
161//------------------------------------------------------------------------------
164inline
167{
169 if (!NameRegistry->Contains(n))
170 {
171 return nullptr;
172 }
173 else
174 {
175 return (*NameRegistry)[n];
176 }
177}
178
179//------------------------------------------------------------------------------
182inline
185{
187 if (!FourCCRegistry->Contains(fcc))
188 {
189 return nullptr;
190 }
191 else
192 {
193 return (*FourCCRegistry)[fcc];
194 }
195}
196
197//------------------------------------------------------------------------------
200inline
201const Util::String&
203{
204 return this->name;
205}
206
207//------------------------------------------------------------------------------
210inline
211const Util::FourCC&
213{
214 return this->fourCC;
215}
216
217//------------------------------------------------------------------------------
220inline
221const Util::String&
223{
224 return this->typeName;
225}
226
227//------------------------------------------------------------------------------
230inline
231const Util::Variant&
233{
234 return this->defaultValue;
235}
236
237//------------------------------------------------------------------------------
240inline
241const uint
243{
244 switch (this->valueType)
245 {
246 case VoidType: return 0;
247 case ByteType: return sizeof(uint8);
248 case ShortType: return sizeof(uint16);
249 case UShortType: return sizeof(uint16);
250 case IntType: return sizeof(uint32);
251 case UIntType: return sizeof(uint32);
252 case Int64Type: return sizeof(uint64);
253 case UInt64Type: return sizeof(uint64);
254 case FloatType: return sizeof(float);
255 case DoubleType: return sizeof(double);
256 case BoolType: return sizeof(bool);
257 case Vec2Type: return sizeof(float) * 2;
258 case Vec4Type: return sizeof(float) * 4;
259 case QuaternionType: return sizeof(float) * 4;
260 case StringType: return sizeof(Util::String);
261 case Mat4Type: return sizeof(Math::mat4);
262 case Transform44Type: return sizeof(Math::transform44);
263 case BlobType: return sizeof(Util::Blob);
264 case GuidType: return sizeof(Util::Guid);
265 case VoidPtrType: return sizeof(void*);
266 case IntArrayType: return sizeof(Util::Array<int>);
267 case FloatArrayType: return sizeof(Util::Array<float>);
268 case BoolArrayType: return sizeof(Util::Array<bool>);
269 case Vec2ArrayType: return sizeof(Util::Array<Math::vec2>);
270 case Vec4ArrayType: return sizeof(Util::Array<Math::vec4>);
271 case Mat4ArrayType: return sizeof(Util::Array<Math::mat4>);
272 case StringArrayType: return sizeof(Util::Array<Util::String>);
273 case GuidArrayType: return sizeof(Util::Array<Util::Guid>);
274 case BlobArrayType: return sizeof(Util::Array<Util::Blob>);
275 default:
276 n_error("AttributeDefinitionBase::GetSizeOfType(): invalid type enum '%d'!", this->valueType);
277 return 0;
278 }
279}
280
281//------------------------------------------------------------------------------
284inline
290
291//------------------------------------------------------------------------------
294inline
297{
298 return this->accessMode;
299}
300
301//------------------------------------------------------------------------------
304inline
305bool
307{
308 return this->isDynamic;
309}
310
311} // namespace Attr
312//------------------------------------------------------------------------------
Exit handler for the Attr subsystem, cleans up dynamic attribute definitions before shutdown.
Definition attrexithandler.h:19
An attribute ID is used to carry attribute types (no values) around.
Definition attrid.h:20
Implements a universal attribute definition, consisting of an attribute name, attribute fourcc code,...
Definition attributedefinitionbase.h:30
static const AttributeDefinitionBase * FindByName(const Util::String &n)
find by name
Definition attributedefinitionbase.h:166
const uint GetSizeOfType() const
get size of type in bytes
Definition attributedefinitionbase.h:242
const Util::String & GetTypeName() const
get type name
Definition attributedefinitionbase.h:222
Util::Variant defaultValue
Definition attributedefinitionbase.h:143
static void InitializeRegistry()
setup registry if it doesn't exist
Definition attributedefinitionbase.cc:515
Util::FourCC fourCC
Definition attributedefinitionbase.h:141
static Util::Dictionary< Util::FourCC, const AttributeDefinitionBase * > * FourCCRegistry
Definition attributedefinitionbase.h:150
static void ClearDynamicAttributes()
clear all dynamic attributes
Definition attributedefinitionbase.cc:687
AccessMode GetAccessMode() const
get access type
Definition attributedefinitionbase.h:296
bool isDynamic
Definition attributedefinitionbase.h:145
bool IsDynamic() const
return true if this is a dynamic attribute
Definition attributedefinitionbase.h:306
Util::String name
Definition attributedefinitionbase.h:139
const Util::Variant & GetDefaultValue() const
get default value
Definition attributedefinitionbase.h:232
AccessMode accessMode
Definition attributedefinitionbase.h:142
static const AttributeDefinitionBase * FindByFourCC(const Util::FourCC &fcc)
find by FourCC
Definition attributedefinitionbase.h:184
static void RegisterDynamicAttribute(const Util::String &name, const Util::String &typeName, const Util::FourCC &fourCC, ValueType valueType, AccessMode accessMode)
register a dynamic attribute
Definition attributedefinitionbase.cc:612
static void CheckCreateDynamicAttributesArray()
check if dynamic attribute array exists and create on demand
Definition attributedefinitionbase.cc:527
static void CheckCreateNameRegistry()
check if name registry exists and create on demand
Definition attributedefinitionbase.cc:491
static void Destroy()
static destruction method - call to cleanup the registry hashtable
Definition attributedefinitionbase.cc:585
Util::String typeName
Definition attributedefinitionbase.h:140
const Util::String & GetName() const
get attribute name
Definition attributedefinitionbase.h:202
~AttributeDefinitionBase()
destructor
Definition attributedefinitionbase.cc:481
ValueType GetValueType() const
get value type
Definition attributedefinitionbase.h:286
static Util::Array< const AttributeDefinitionBase * > * DynamicAttributes
Definition attributedefinitionbase.h:151
static AttrExitHandler attrExitHandler
Definition attributedefinitionbase.h:148
static void CheckCreateFourCCRegistry()
check if fourcc registry exists and create on demand
Definition attributedefinitionbase.cc:503
static Util::HashTable< Util::String, const AttributeDefinitionBase * > * NameRegistry
Definition attributedefinitionbase.h:149
void Register()
register an attribute definition
Definition attributedefinitionbase.cc:543
const Util::FourCC & GetFourCC() const
get fourcc code
Definition attributedefinitionbase.h:212
const Attr::ValueType valueType
Definition attributedefinitionbase.h:144
AttributeDefinitionBase()
default constructor is private
Definition attributedefinitionbase.cc:20
A 4x4 matrix which is described by translation, rotation and scale.
Definition transform44.h:20
Nebula's dynamic array class.
Definition array.h:60
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A four-character-code is a quasi-human-readable 32-bit-id.
Definition fourcc.h:19
Implements a GUID.
Organizes key/value pairs by a hash code.
Definition hashtable.h:42
An "any type" variable.
Definition variant.h:31
Type GetType() const
get type
Definition variant.h:1172
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_assert(exp)
Definition debug.h:50
Definition accessmode.h:13
ValueType
Definition valuetype.h:20
@ UInt64Type
Definition valuetype.h:28
@ Vec4Type
Definition valuetype.h:33
@ Vec2Type
Definition valuetype.h:32
@ IntType
Definition valuetype.h:25
@ GuidArrayType
Definition valuetype.h:49
@ QuaternionType
Definition valuetype.h:34
@ FloatType
Definition valuetype.h:29
@ BoolArrayType
Definition valuetype.h:43
@ Transform44Type
Definition valuetype.h:37
@ ByteType
Definition valuetype.h:22
@ Mat4Type
Definition valuetype.h:36
@ UShortType
Definition valuetype.h:24
@ BoolType
Definition valuetype.h:31
@ Vec4ArrayType
Definition valuetype.h:45
@ DoubleType
Definition valuetype.h:30
@ StringArrayType
Definition valuetype.h:46
@ Int64Type
Definition valuetype.h:27
@ IntArrayType
Definition valuetype.h:41
@ StringType
Definition valuetype.h:35
@ ShortType
Definition valuetype.h:23
@ FloatArrayType
Definition valuetype.h:42
@ Vec2ArrayType
Definition valuetype.h:44
@ Mat4ArrayType
Definition valuetype.h:47
@ BlobArrayType
Definition valuetype.h:48
@ BlobType
Definition valuetype.h:38
@ VoidPtrType
Definition valuetype.h:40
@ UIntType
Definition valuetype.h:26
@ VoidType
Definition valuetype.h:21
@ GuidType
Definition valuetype.h:39
AccessMode
Definition accessmode.h:15
A 4x4 single point precision float matrix.
Definition mat4.h:49
A quaternion is usually used to represent an orientation in 3D space.
Definition quat.h:30
A 2-component float vector class.
Definition vec2.h:21
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
uint8_t uint8
Definition types.h:42
unsigned int uint
Definition types.h:31
unsigned short ushort
Definition types.h:32
uint64_t uint64
Definition types.h:36
uint16_t uint16
Definition types.h:40
uint32_t uint32
Definition types.h:38
Defines the valid attribute value types as enum.