Nebula
Loading...
Searching...
No Matches
attribute.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "boolattrid.h"
13#include "blobattrid.h"
14#include "guidattrid.h"
15#include "floatattrid.h"
16#include "intattrid.h"
17#include "uintattrid.h"
18#include "mat4attrid.h"
19#include "vec4attrid.h"
20#include "stringattrid.h"
21#include "util/variant.h"
22#include "math/vec4.h"
23#include "math/mat4.h"
24#include "util/keyvaluepair.h"
25#include "util/guid.h"
26#include "util/blob.h"
27
28//------------------------------------------------------------------------------
29namespace Attr
30{
31class Attribute : public Util::KeyValuePair<AttrId,Util::Variant>
32{
33public:
35 Attribute();
37 Attribute(const Attribute& rhs);
39 Attribute(const AttrId& id);
43 Attribute(const BoolAttrId& id, bool val);
45 Attribute(const FloatAttrId& id, float val);
47 Attribute(const IntAttrId& id, int val);
49 Attribute(const UIntAttrId& id, uint val);
51 Attribute(const Mat4AttrId& id, const Math::mat4& val);
53 Attribute(const StringAttrId& id, const Util::String& val);
55 Attribute(const Vec4AttrId& id, const Math::vec4& val);
57 Attribute(const GuidAttrId& id, const Util::Guid& val);
59 Attribute(const BlobAttrId& id, const Util::Blob& val);
60
61
63 void SetAttrId(const AttrId& id);
65 const AttrId& GetAttrId() const;
67 const Util::String& GetName() const;
69 const Util::FourCC& GetFourCC() const;
71 ValueType GetValueType() const;
75 void Clear();
76
78 void operator=(const Attribute& rhs);
80 void operator=(bool rhs);
82 void operator=(float rhs);
84 void operator=(int rhs);
86 void operator=(const Math::mat4& rhs);
88 void operator=(const Util::String& rhs);
90 void operator=(const Math::vec4& rhs);
92 void operator=(const Util::Guid& rhs);
94 void operator=(const Util::Blob& rhs);
95
97 bool operator==(const Attribute& rhs) const;
99 bool operator==(const Util::String& rhs) const;
101 bool operator==(int rhs) const;
103 bool operator==(float rhs) const;
105 bool operator==(bool rhs) const;
107 bool operator==(const Math::vec4& rhs) const;
109 bool operator==(const Util::Guid& rhs) const;
110
112 bool operator!=(const Attribute& rhs) const;
114 bool operator!=(const Util::String& rhs) const;
116 bool operator!=(int rhs) const;
118 bool operator!=(float rhs) const;
120 bool operator!=(bool rhs) const;
122 bool operator!=(const Math::vec4& rhs) const;
124 bool operator!=(const Util::Guid& rhs) const;
125
127 void SetBool(bool val);
129 bool GetBool() const;
131 void SetInt(int val);
133 int GetInt() const;
135 void SetUInt(uint val);
137 uint GetUInt() const;
139 void SetFloat(float val);
141 float GetFloat() const;
143 void SetString(const Util::String& val);
145 const Util::String& GetString() const;
147 void SetMat4(const Math::mat4& val);
149 const Math::mat4& GetMat4() const;
151 void SetVec4(const Math::vec4& val);
153 Math::vec4 GetVec4() const;
155 void SetGuid(const Util::Guid& val);
157 const Util::Guid& GetGuid() const;
159 void SetBlob(const Util::Blob& val);
161 const Util::Blob& GetBlob() const;
163 void SetValue(const Util::Variant& val);
165 const Util::Variant& GetValue() const;
166
168 void SetValueFromString(const Util::String& str);
175};
176
177//------------------------------------------------------------------------------
180inline
182{
183 // empty
184}
185
186//------------------------------------------------------------------------------
189inline
191 Util::KeyValuePair<AttrId,Util::Variant>(rhs.keyData, rhs.valueData)
192{
193 // empty
194}
195
196//------------------------------------------------------------------------------
199inline
202{
203 // empty
204}
205
206//------------------------------------------------------------------------------
209inline
215
216//------------------------------------------------------------------------------
219inline
220Attribute::Attribute(const BoolAttrId& id, bool val) :
222{
223 // empty
224}
225
226//------------------------------------------------------------------------------
229inline
230Attribute::Attribute(const FloatAttrId& id, float val) :
232{
233 // empty
234}
235
236//------------------------------------------------------------------------------
239inline
240Attribute::Attribute(const IntAttrId& id, int val) :
242{
243 // empty
244}
245
246//------------------------------------------------------------------------------
249inline
252{
253 // empty
254}
255
256//------------------------------------------------------------------------------
259inline
262{
263 // empty
264}
265
266//------------------------------------------------------------------------------
269inline
272{
273 // empty
274}
275
276//------------------------------------------------------------------------------
279inline
282{
283 // empty
284}
285
286//------------------------------------------------------------------------------
289inline
292{
293 // empty
294}
295
296//------------------------------------------------------------------------------
299inline
302{
303 // empty
304}
305
306//------------------------------------------------------------------------------
309inline void
311{
312 this->keyData = id;
313}
314
315//------------------------------------------------------------------------------
318inline const AttrId&
320{
321 return this->keyData;
322}
323
324//------------------------------------------------------------------------------
327inline const Util::String&
329{
330 return this->keyData.GetName();
331}
332
333//------------------------------------------------------------------------------
336inline const Util::FourCC&
338{
339 return this->keyData.GetFourCC();
340}
341
342//------------------------------------------------------------------------------
345inline ValueType
347{
348 return this->keyData.GetValueType();
349}
350
351//------------------------------------------------------------------------------
354inline AccessMode
356{
357 return this->keyData.GetAccessMode();
358}
359
360//------------------------------------------------------------------------------
363inline void
365{
366 this->valueData.Clear();
367}
368
369//------------------------------------------------------------------------------
372inline void
374{
375 this->keyData = rhs.keyData;
376 this->valueData = rhs.valueData;
377}
378
379//------------------------------------------------------------------------------
382inline void
384{
385 n_assert(this->GetValueType() == BoolType);
386 n_assert(this->GetAccessMode() == ReadWrite);
387 this->valueData = rhs;
388}
389
390//------------------------------------------------------------------------------
393inline void
395{
396 n_assert(this->GetValueType() == FloatType);
397 n_assert(this->GetAccessMode() == ReadWrite);
398 this->valueData = rhs;
399}
400
401//------------------------------------------------------------------------------
404inline void
406{
407 n_assert(this->GetValueType() == IntType);
408 n_assert(this->GetAccessMode() == ReadWrite);
409 this->valueData = rhs;
410}
411
412//------------------------------------------------------------------------------
415inline void
417{
418 n_assert(this->GetValueType() == Mat4Type);
419 n_assert(this->GetAccessMode() == ReadWrite);
420 this->valueData = rhs;
421}
422
423//------------------------------------------------------------------------------
426inline void
428{
429 n_assert(this->GetValueType() == StringType);
430 n_assert(this->GetAccessMode() == ReadWrite);
431 this->valueData = rhs;
432}
433
434//------------------------------------------------------------------------------
437inline void
439{
440 n_assert(this->GetValueType() == Vec4Type);
441 n_assert(this->GetAccessMode() == ReadWrite);
442 this->valueData = rhs;
443}
444
445//------------------------------------------------------------------------------
448inline void
450{
451 n_assert(this->GetValueType() == GuidType);
452 n_assert(this->GetAccessMode() == ReadWrite);
453 this->valueData = rhs;
454}
455
456//------------------------------------------------------------------------------
459inline void
461{
462 n_assert(this->GetValueType() == BlobType);
463 n_assert(this->GetAccessMode() == ReadWrite);
464 this->valueData = rhs;
465}
466
467//------------------------------------------------------------------------------
470inline bool
472{
473 return ((this->keyData == rhs.keyData) && (this->valueData == rhs.valueData));
474}
475
476//------------------------------------------------------------------------------
479inline bool
481{
482 n_assert(this->GetValueType() == StringType);
483 return this->valueData == rhs;
484}
485
486//------------------------------------------------------------------------------
489inline bool
491{
492 n_assert(this->GetValueType() == IntType);
493 return this->valueData == rhs;
494}
495
496//------------------------------------------------------------------------------
499inline bool
500Attribute::operator==(float rhs) const
501{
502 n_assert(this->GetValueType() == FloatType);
503 return this->valueData == rhs;
504}
505
506//------------------------------------------------------------------------------
509inline bool
511{
512 n_assert(this->GetValueType() == BoolType);
513 return this->valueData == rhs;
514}
515
516//------------------------------------------------------------------------------
519inline bool
521{
522 n_assert(this->GetValueType() == Vec4Type);
523 return this->valueData == rhs;
524}
525
526//------------------------------------------------------------------------------
529inline bool
531{
532 n_assert(this->GetValueType() == GuidType);
533 return this->valueData == rhs;
534}
535
536//------------------------------------------------------------------------------
539inline bool
541{
542 return (this->keyData != rhs.keyData) || (this->valueData != rhs.valueData);
543}
544
545//------------------------------------------------------------------------------
548inline bool
550{
551 n_assert(this->GetValueType() == StringType);
552 return this->valueData != rhs;
553}
554
555//------------------------------------------------------------------------------
558inline bool
560{
561 n_assert(this->GetValueType() == IntType);
562 return this->valueData != rhs;
563}
564
565//------------------------------------------------------------------------------
568inline bool
569Attribute::operator!=(float rhs) const
570{
571 n_assert(this->GetValueType() == FloatType);
572 return this->valueData != rhs;
573}
574
575//------------------------------------------------------------------------------
578inline bool
580{
581 n_assert(this->GetValueType() == Vec4Type);
582 return this->valueData != rhs;
583}
584
585//------------------------------------------------------------------------------
588inline bool
590{
591 n_assert(this->GetValueType() == GuidType);
592 return this->valueData != rhs;
593}
594
595//------------------------------------------------------------------------------
598inline void
600{
601 n_assert(this->GetValueType() == BoolType);
602 n_assert(this->GetAccessMode() == ReadWrite);
603 this->valueData = val;
604}
605
606//------------------------------------------------------------------------------
609inline bool
611{
612 n_assert(this->GetValueType() == BoolType);
613 return this->valueData.GetBool();
614}
615
616//------------------------------------------------------------------------------
619inline void
621{
622 n_assert(this->GetValueType() == IntType);
623 n_assert(this->GetAccessMode() == ReadWrite);
624 this->valueData = val;
625}
626
627//------------------------------------------------------------------------------
630inline int
632{
633 n_assert(this->GetValueType() == IntType);
634 return this->valueData.GetInt();
635}
636
637//------------------------------------------------------------------------------
640inline void
642{
643 n_assert(this->GetValueType() == UIntType);
644 n_assert(this->GetAccessMode() == ReadWrite);
645 this->valueData = val;
646}
647
648//------------------------------------------------------------------------------
651inline uint
653{
654 n_assert(this->GetValueType() == UIntType);
655 return this->valueData.GetUInt();
656}
657
658//------------------------------------------------------------------------------
661inline void
663{
664 n_assert(this->GetValueType() == FloatType);
665 n_assert(this->GetAccessMode() == ReadWrite);
666 this->valueData = val;
667}
668
669//------------------------------------------------------------------------------
672inline float
674{
675 n_assert(this->GetValueType() == FloatType);
676 return this->valueData.GetFloat();
677}
678
679//------------------------------------------------------------------------------
682inline void
684{
685 n_assert(this->GetValueType() == StringType);
686 n_assert(this->GetAccessMode() == ReadWrite);
687 this->valueData = val;
688}
689
690//------------------------------------------------------------------------------
693inline const Util::String&
695{
696 n_assert(this->GetValueType() == StringType);
697 return this->valueData.GetString();
698}
699
700//------------------------------------------------------------------------------
703inline void
705{
706 n_assert(this->GetValueType() == Mat4Type);
707 n_assert(this->GetAccessMode() == ReadWrite);
708 this->valueData = val;
709}
710
711//------------------------------------------------------------------------------
714inline const Math::mat4&
716{
717 n_assert(this->GetValueType() == Mat4Type);
718 return this->valueData.GetMat4();
719}
720
721//------------------------------------------------------------------------------
724inline void
726{
727 n_assert(this->GetValueType() == Vec4Type);
728 n_assert(this->GetAccessMode() == ReadWrite);
729 this->valueData = val;
730}
731
732//------------------------------------------------------------------------------
735inline Math::vec4
737{
738 n_assert(this->GetValueType() == Vec4Type);
739 return this->valueData.GetVec4();
740}
741
742//------------------------------------------------------------------------------
745inline void
747{
748 n_assert(this->GetValueType() == GuidType);
749 n_assert(this->GetAccessMode() == ReadWrite);
750 this->valueData = val;
751}
752
753//------------------------------------------------------------------------------
756inline const Util::Guid&
758{
759 n_assert(this->GetValueType() == GuidType);
760 return this->valueData.GetGuid();
761}
762
763//------------------------------------------------------------------------------
766inline void
768{
769 n_assert(this->GetValueType() == BlobType);
770 n_assert(this->GetAccessMode() == ReadWrite);
771 this->valueData = val;
772}
773
774//------------------------------------------------------------------------------
777inline const Util::Blob&
779{
780 n_assert(this->GetValueType() == BlobType);
781 return this->valueData.GetBlob();
782}
783
784//------------------------------------------------------------------------------
787inline void
789{
790 n_assert(this->GetValueType() != VoidType);
791 switch (this->GetValueType())
792 {
793 case IntType:
794 this->valueData = str.AsInt();
795 break;
796
797 case FloatType:
798 this->valueData = str.AsFloat();
799 break;
800
801 case BoolType:
802 this->valueData = str.AsBool();
803 break;
804
805 case Vec4Type:
806 this->valueData = str.AsVec4();
807 break;
808
809 case StringType:
810 this->valueData = str;
811 break;
812
813 case Mat4Type:
814 this->valueData = str.AsMat4();
815 break;
816
817 case GuidType:
818 this->valueData = Util::Guid::FromString(str);
819 break;
820
821 default:
822 n_error("Attribute::SetValueFromString(): cannot convert string to attribute type!");
823 break;
824 }
825}
826
827//------------------------------------------------------------------------------
830inline Util::String
832{
833 n_assert(this->GetValueType() != VoidType);
834 Util::String str;
835 switch (this->GetValueType())
836 {
837 case IntType:
838 str.SetInt(this->GetInt());
839 break;
840
841 case FloatType:
842 str.SetFloat(this->GetFloat());
843 break;
844
845 case BoolType:
846 str.SetBool(this->GetBool());
847 break;
848
849 case Vec4Type:
850 str.SetVec4(this->GetVec4());
851 break;
852
853 case StringType:
854 str = this->GetString();
855 break;
856
857 case Mat4Type:
858 str.SetMat4(this->GetMat4());
859 break;
860
861 case GuidType:
862 str = this->GetGuid().AsString();
863 break;
864
865 case BlobType:
866 n_error("Attribute: Cannot convert blob to string (attrid='%s')!", this->GetName().AsCharPtr());
867 break;
868
869 case VoidType:
870 n_error("Attribute: Cannot convert void attribute to string (attrid='%s')!", this->GetName().AsCharPtr());
871 break;
872 default: n_error("Attribute: unhandled enum"); break;
873 }
874 return str;
875}
876
877//------------------------------------------------------------------------------
880inline ValueType
885
886//------------------------------------------------------------------------------
889inline Util::String
894
895//------------------------------------------------------------------------------
898inline void
900{
901 this->valueData = val;
902}
903
904//------------------------------------------------------------------------------
907inline const Util::Variant&
909{
910 return this->valueData;
911}
912
913} // namespace Attr
914//------------------------------------------------------------------------------
An attribute ID is used to carry attribute types (no values) around.
Definition attrid.h:20
A compiletime-typesafe key/value pair.
Definition attribute.h:32
bool GetBool() const
get bool content
Definition attribute.h:610
void SetVec4(const Math::vec4 &val)
set float4 value
Definition attribute.h:725
void operator=(const Attribute &rhs)
assignment operator
Definition attribute.h:373
const AttrId & GetAttrId() const
get attribute id
Definition attribute.h:319
AccessMode GetAccessMode() const
get access mode of attribute
Definition attribute.h:355
void SetBool(bool val)
set bool content
Definition attribute.h:599
const Util::String & GetName() const
get name of attribute
Definition attribute.h:328
bool operator==(const Attribute &rhs) const
equality operator
Definition attribute.h:471
const Util::Blob & GetBlob() const
get blob value
Definition attribute.h:778
uint GetUInt() const
get int content
Definition attribute.h:652
void Clear()
clear the attribute's value
Definition attribute.h:364
Math::vec4 GetVec4() const
get float4 value
Definition attribute.h:736
Attribute()
default constructor
Definition attribute.h:181
static ValueType StringToValueType(const Util::String &s)
convert string to type
Definition attribute.h:881
const Util::String & GetString() const
get string content
Definition attribute.h:694
void SetValue(const Util::Variant &val)
set generic value
Definition attribute.h:899
void SetUInt(uint val)
set int content
Definition attribute.h:641
void SetAttrId(const AttrId &id)
set attribute id
Definition attribute.h:310
void SetString(const Util::String &val)
set string content
Definition attribute.h:683
Util::String ValueAsString() const
convert the content to a string
Definition attribute.h:831
void SetGuid(const Util::Guid &val)
set guid value
Definition attribute.h:746
void SetFloat(float val)
set float content
Definition attribute.h:662
void SetMat4(const Math::mat4 &val)
set matrix44 value
Definition attribute.h:704
void SetValueFromString(const Util::String &str)
set value from string (convert as necessary)
Definition attribute.h:788
float GetFloat() const
get float content
Definition attribute.h:673
ValueType GetValueType() const
get value type of attribute
Definition attribute.h:346
const Util::Variant & GetValue() const
get generic value
Definition attribute.h:908
const Util::FourCC & GetFourCC() const
get fourcc of attribute
Definition attribute.h:337
bool operator!=(const Attribute &rhs) const
equality operator
Definition attribute.h:540
void SetInt(int val)
set int content
Definition attribute.h:620
const Math::mat4 & GetMat4() const
get matrix44 value
Definition attribute.h:715
bool operator!=(bool rhs) const
bool equality operator
static Util::String ValueTypeToString(ValueType t)
convert type to string
Definition attribute.h:890
int GetInt() const
get int content
Definition attribute.h:631
void SetBlob(const Util::Blob &val)
set blob value
Definition attribute.h:767
const Util::Guid & GetGuid() const
get guid value
Definition attribute.h:757
Typed attribute id for blob type.
Definition blobattrid.h:18
Typed attribute id for bool type.
Definition boolattrid.h:18
Typed attribute id for float type.
Definition floatattrid.h:18
Typed attribute id for guid type.
Definition guidattrid.h:18
Typed attribute id for integer type.
Definition intattrid.h:18
Typed attribute id for mat4 type.
Definition mat4attrid.h:18
Typed attribute id for string type.
Definition stringattrid.h:18
Typed attribute id for unsigned integer type.
Definition uintattrid.h:18
Typed attribute id for vec4 type.
Definition vec4attrid.h:18
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
A four-character-code is a quasi-human-readable 32-bit-id.
Definition fourcc.h:19
Implements a GUID.
Key/Value pair objects are used by most assiociative container classes, like Dictionary or HashTable.
Definition keyvaluepair.h:19
AttrId keyData
Definition keyvaluepair.h:66
Util::Variant valueData
Definition keyvaluepair.h:67
An "any type" variable.
Definition variant.h:31
const Math::mat4 & GetMat4() const
get mat4 content
Definition variant.h:2642
Type
variant types
Definition variant.h:35
Math::vec4 GetVec4() const
get vec4 content
Definition variant.h:2604
int GetInt() const
get integer content
Definition variant.h:2422
const Util::String & GetString() const
get string content
Definition variant.h:2548
uint GetUInt() const
get unsigned integer content
Definition variant.h:2432
bool GetBool() const
get bool content
Definition variant.h:2529
void Clear()
clear content, resets type to void
Definition variant.h:610
const Util::Guid & GetGuid() const
get guid content
Definition variant.h:2680
float GetFloat() const
get float content
Definition variant.h:2491
static Type StringToType(const Util::String &str)
convert string to type
Definition variant.h:3504
const Util::Blob & GetBlob() const
get blob
Definition variant.h:2699
static Util::String TypeToString(Type t)
convert type to string
Definition variant.h:3460
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
@ Vec4Type
Definition valuetype.h:33
@ IntType
Definition valuetype.h:25
@ FloatType
Definition valuetype.h:29
@ Mat4Type
Definition valuetype.h:36
@ BoolType
Definition valuetype.h:31
@ StringType
Definition valuetype.h:35
@ BlobType
Definition valuetype.h:38
@ UIntType
Definition valuetype.h:26
@ VoidType
Definition valuetype.h:21
@ GuidType
Definition valuetype.h:39
AccessMode
Definition accessmode.h:15
@ ReadWrite
Definition accessmode.h:17
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
void SetInt(int val)
set as int value
Definition string.cc:1405
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:705
void SetBool(bool val)
set as bool value
Definition string.cc:1468
bool AsBool() const
return contents as bool
Definition string.cc:1072
float AsFloat() const
return contents as float
Definition string.cc:1063
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1672
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1561
int AsInt() const
return contents as integer
Definition string.cc:1039
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1516
void SetFloat(float val)
set as float value
Definition string.cc:1450
unsigned int uint
Definition types.h:31