Nebula
Loading...
Searching...
No Matches
attribute.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "attrid.h"
13#include "boolattrid.h"
14#include "blobattrid.h"
15#include "guidattrid.h"
16#include "floatattrid.h"
17#include "intattrid.h"
18#include "uintattrid.h"
19#include "mat4attrid.h"
20#include "vec4attrid.h"
21#include "stringattrid.h"
22#include "util/variant.h"
23#include "math/vec4.h"
24#include "math/mat4.h"
25#include "util/keyvaluepair.h"
26#include "util/guid.h"
27#include "util/blob.h"
28
29//------------------------------------------------------------------------------
30namespace Attr
31{
32class Attribute : public Util::KeyValuePair<AttrId,Util::Variant>
33{
34public:
36 Attribute();
38 Attribute(const Attribute& rhs);
40 Attribute(const AttrId& id);
44 Attribute(const BoolAttrId& id, bool val);
46 Attribute(const FloatAttrId& id, float val);
48 Attribute(const IntAttrId& id, int val);
50 Attribute(const UIntAttrId& id, uint val);
52 Attribute(const Int64AttrId& id, int64_t val);
54 Attribute(const Mat4AttrId& id, const Math::mat4& val);
56 Attribute(const StringAttrId& id, const Util::String& val);
58 Attribute(const Vec4AttrId& id, const Math::vec4& val);
60 Attribute(const GuidAttrId& id, const Util::Guid& val);
62 Attribute(const BlobAttrId& id, const Util::Blob& val);
63
64
66 void SetAttrId(const AttrId& id);
68 const AttrId& GetAttrId() const;
70 const Util::String& GetName() const;
72 const Util::FourCC& GetFourCC() const;
74 ValueType GetValueType() const;
78 void Clear();
79
81 void operator=(const Attribute& rhs);
83 void operator=(bool rhs);
85 void operator=(float rhs);
87 void operator=(int rhs);
89 void operator=(const Math::mat4& rhs);
91 void operator=(const Util::String& rhs);
93 void operator=(const Math::vec4& rhs);
95 void operator=(const Util::Guid& rhs);
97 void operator=(const Util::Blob& rhs);
98
100 bool operator==(const Attribute& rhs) const;
102 bool operator==(const Util::String& rhs) const;
104 bool operator==(int rhs) const;
106 bool operator==(float rhs) const;
108 bool operator==(bool rhs) const;
110 bool operator==(const Math::vec4& rhs) const;
112 bool operator==(const Util::Guid& rhs) const;
113
115 bool operator!=(const Attribute& rhs) const;
117 bool operator!=(const Util::String& rhs) const;
119 bool operator!=(int rhs) const;
121 bool operator!=(float rhs) const;
123 bool operator!=(bool rhs) const;
125 bool operator!=(const Math::vec4& rhs) const;
127 bool operator!=(const Util::Guid& rhs) const;
128
130 void SetBool(bool val);
132 bool GetBool() const;
134 void SetInt(int val);
136 int GetInt() const;
138 void SetUInt(uint val);
140 uint GetUInt() const;
142 void SetInt64(int64_t val);
144 int64_t GetInt64() const;
146 void SetFloat(float val);
148 float GetFloat() const;
150 void SetString(const Util::String& val);
152 const Util::String& GetString() const;
154 void SetMat4(const Math::mat4& val);
156 const Math::mat4& GetMat4() const;
158 void SetVec4(const Math::vec4& val);
160 Math::vec4 GetVec4() const;
162 void SetGuid(const Util::Guid& val);
164 const Util::Guid& GetGuid() const;
166 void SetBlob(const Util::Blob& val);
168 const Util::Blob& GetBlob() const;
170 void SetValue(const Util::Variant& val);
172 const Util::Variant& GetValue() const;
173
175 void SetValueFromString(const Util::String& str);
182};
183
184//------------------------------------------------------------------------------
187inline
189{
190 // empty
191}
192
193//------------------------------------------------------------------------------
196inline
199{
200 // empty
201}
202
203//------------------------------------------------------------------------------
206inline
209{
210 // empty
211}
212
213//------------------------------------------------------------------------------
216inline
222
223//------------------------------------------------------------------------------
226inline
227Attribute::Attribute(const BoolAttrId& id, bool val) :
229{
230 // empty
231}
232
233//------------------------------------------------------------------------------
236inline
237Attribute::Attribute(const FloatAttrId& id, float val) :
239{
240 // empty
241}
242
243//------------------------------------------------------------------------------
246inline
247Attribute::Attribute(const IntAttrId& id, int val) :
249{
250 // empty
251}
252
253//------------------------------------------------------------------------------
256inline
257Attribute::Attribute(const Int64AttrId& id, int64_t val) :
259{
260 // empty
261}
262
263//------------------------------------------------------------------------------
266inline
269{
270 // empty
271}
272
273//------------------------------------------------------------------------------
276inline
279{
280 // empty
281}
282
283//------------------------------------------------------------------------------
286inline
289{
290 // empty
291}
292
293//------------------------------------------------------------------------------
296inline
297Attribute::Attribute(const GuidAttrId& id, const Util::Guid& val) :
299{
300 // empty
301}
302
303//------------------------------------------------------------------------------
306inline
309{
310 // empty
311}
312
313//------------------------------------------------------------------------------
316inline
319{
320 // empty
321}
322
323//------------------------------------------------------------------------------
326inline void
328{
329 this->keyData = id;
330}
331
332//------------------------------------------------------------------------------
335inline const AttrId&
337{
338 return this->keyData;
339}
340
341//------------------------------------------------------------------------------
344inline const Util::String&
346{
347 return this->keyData.GetName();
348}
349
350//------------------------------------------------------------------------------
353inline const Util::FourCC&
355{
356 return this->keyData.GetFourCC();
357}
358
359//------------------------------------------------------------------------------
362inline ValueType
364{
365 return this->keyData.GetValueType();
366}
367
368//------------------------------------------------------------------------------
371inline AccessMode
373{
374 return this->keyData.GetAccessMode();
375}
376
377//------------------------------------------------------------------------------
380inline void
382{
383 this->valueData.Clear();
384}
385
386//------------------------------------------------------------------------------
389inline void
391{
392 this->keyData = rhs.keyData;
393 this->valueData = rhs.valueData;
394}
395
396//------------------------------------------------------------------------------
399inline void
401{
402 n_assert(this->GetValueType() == BoolType);
403 n_assert(this->GetAccessMode() == ReadWrite);
404 this->valueData = rhs;
405}
406
407//------------------------------------------------------------------------------
410inline void
412{
413 n_assert(this->GetValueType() == FloatType);
414 n_assert(this->GetAccessMode() == ReadWrite);
415 this->valueData = rhs;
416}
417
418//------------------------------------------------------------------------------
421inline void
423{
424 n_assert(this->GetValueType() == IntType);
425 n_assert(this->GetAccessMode() == ReadWrite);
426 this->valueData = rhs;
427}
428
429//------------------------------------------------------------------------------
432inline void
434{
435 n_assert(this->GetValueType() == Mat4Type);
436 n_assert(this->GetAccessMode() == ReadWrite);
437 this->valueData = rhs;
438}
439
440//------------------------------------------------------------------------------
443inline void
445{
446 n_assert(this->GetValueType() == StringType);
447 n_assert(this->GetAccessMode() == ReadWrite);
448 this->valueData = rhs;
449}
450
451//------------------------------------------------------------------------------
454inline void
456{
457 n_assert(this->GetValueType() == Vec4Type);
458 n_assert(this->GetAccessMode() == ReadWrite);
459 this->valueData = rhs;
460}
461
462//------------------------------------------------------------------------------
465inline void
466Attribute::operator=(const Util::Guid& rhs)
467{
468 n_assert(this->GetValueType() == GuidType);
469 n_assert(this->GetAccessMode() == ReadWrite);
470 this->valueData = rhs;
471}
472
473//------------------------------------------------------------------------------
476inline void
478{
479 n_assert(this->GetValueType() == BlobType);
480 n_assert(this->GetAccessMode() == ReadWrite);
481 this->valueData = rhs;
482}
483
484//------------------------------------------------------------------------------
487inline bool
489{
490 return ((this->keyData == rhs.keyData) && (this->valueData == rhs.valueData));
491}
492
493//------------------------------------------------------------------------------
496inline bool
498{
499 n_assert(this->GetValueType() == StringType);
500 return this->valueData == rhs;
501}
502
503//------------------------------------------------------------------------------
506inline bool
508{
509 n_assert(this->GetValueType() == IntType);
510 return this->valueData == rhs;
511}
512
513//------------------------------------------------------------------------------
516inline bool
517Attribute::operator==(float rhs) const
518{
519 n_assert(this->GetValueType() == FloatType);
520 return this->valueData == rhs;
521}
522
523//------------------------------------------------------------------------------
526inline bool
528{
529 n_assert(this->GetValueType() == BoolType);
530 return this->valueData == rhs;
531}
532
533//------------------------------------------------------------------------------
536inline bool
538{
539 n_assert(this->GetValueType() == Vec4Type);
540 return this->valueData == rhs;
541}
542
543//------------------------------------------------------------------------------
546inline bool
547Attribute::operator==(const Util::Guid& rhs) const
548{
549 n_assert(this->GetValueType() == GuidType);
550 return this->valueData == rhs;
551}
552
553//------------------------------------------------------------------------------
556inline bool
558{
559 return (this->keyData != rhs.keyData) || (this->valueData != rhs.valueData);
560}
561
562//------------------------------------------------------------------------------
565inline bool
567{
568 n_assert(this->GetValueType() == StringType);
569 return this->valueData != rhs;
570}
571
572//------------------------------------------------------------------------------
575inline bool
577{
578 n_assert(this->GetValueType() == IntType);
579 return this->valueData != rhs;
580}
581
582//------------------------------------------------------------------------------
585inline bool
586Attribute::operator!=(float rhs) const
587{
588 n_assert(this->GetValueType() == FloatType);
589 return this->valueData != rhs;
590}
591
592//------------------------------------------------------------------------------
595inline bool
597{
598 n_assert(this->GetValueType() == Vec4Type);
599 return this->valueData != rhs;
600}
601
602//------------------------------------------------------------------------------
605inline bool
606Attribute::operator!=(const Util::Guid& rhs) const
607{
608 n_assert(this->GetValueType() == GuidType);
609 return this->valueData != rhs;
610}
611
612//------------------------------------------------------------------------------
615inline void
617{
618 n_assert(this->GetValueType() == BoolType);
619 n_assert(this->GetAccessMode() == ReadWrite);
620 this->valueData = val;
621}
622
623//------------------------------------------------------------------------------
626inline bool
628{
629 n_assert(this->GetValueType() == BoolType);
630 return this->valueData.GetBool();
631}
632
633//------------------------------------------------------------------------------
636inline void
638{
639 n_assert(this->GetValueType() == IntType);
640 n_assert(this->GetAccessMode() == ReadWrite);
641 this->valueData = val;
642}
643
644//------------------------------------------------------------------------------
647inline int
649{
650 n_assert(this->GetValueType() == IntType);
651 return this->valueData.GetInt();
652}
653
654//------------------------------------------------------------------------------
657inline void
659{
660 n_assert(this->GetValueType() == UIntType);
661 n_assert(this->GetAccessMode() == ReadWrite);
662 this->valueData = val;
663}
664
665//------------------------------------------------------------------------------
668inline uint
670{
671 n_assert(this->GetValueType() == UIntType);
672 return this->valueData.GetUInt();
673}
674
675//------------------------------------------------------------------------------
678inline void
680{
681 n_assert(this->GetValueType() == Int64Type);
682 n_assert(this->GetAccessMode() == ReadWrite);
683 this->valueData = val;
684}
685
686//------------------------------------------------------------------------------
689inline int64_t
691{
692 n_assert(this->GetValueType() == Int64Type);
693 return this->valueData.GetInt64();
694}
695
696//------------------------------------------------------------------------------
699inline void
701{
702 n_assert(this->GetValueType() == FloatType);
703 n_assert(this->GetAccessMode() == ReadWrite);
704 this->valueData = val;
705}
706
707//------------------------------------------------------------------------------
710inline float
712{
713 n_assert(this->GetValueType() == FloatType);
714 return this->valueData.GetFloat();
715}
716
717//------------------------------------------------------------------------------
720inline void
722{
723 n_assert(this->GetValueType() == StringType);
724 n_assert(this->GetAccessMode() == ReadWrite);
725 this->valueData = val;
726}
727
728//------------------------------------------------------------------------------
731inline const Util::String&
733{
734 n_assert(this->GetValueType() == StringType);
735 return this->valueData.GetString();
736}
737
738//------------------------------------------------------------------------------
741inline void
743{
744 n_assert(this->GetValueType() == Mat4Type);
745 n_assert(this->GetAccessMode() == ReadWrite);
746 this->valueData = val;
747}
748
749//------------------------------------------------------------------------------
752inline const Math::mat4&
754{
755 n_assert(this->GetValueType() == Mat4Type);
756 return this->valueData.GetMat4();
757}
758
759//------------------------------------------------------------------------------
762inline void
764{
765 n_assert(this->GetValueType() == Vec4Type);
766 n_assert(this->GetAccessMode() == ReadWrite);
767 this->valueData = val;
768}
769
770//------------------------------------------------------------------------------
773inline Math::vec4
775{
776 n_assert(this->GetValueType() == Vec4Type);
777 return this->valueData.GetVec4();
778}
779
780//------------------------------------------------------------------------------
783inline void
784Attribute::SetGuid(const Util::Guid& val)
785{
786 n_assert(this->GetValueType() == GuidType);
787 n_assert(this->GetAccessMode() == ReadWrite);
788 this->valueData = val;
789}
790
791//------------------------------------------------------------------------------
794inline const Util::Guid&
796{
797 n_assert(this->GetValueType() == GuidType);
798 return this->valueData.GetGuid();
799}
800
801//------------------------------------------------------------------------------
804inline void
806{
807 n_assert(this->GetValueType() == BlobType);
808 n_assert(this->GetAccessMode() == ReadWrite);
809 this->valueData = val;
810}
811
812//------------------------------------------------------------------------------
815inline const Util::Blob&
817{
818 n_assert(this->GetValueType() == BlobType);
819 return this->valueData.GetBlob();
820}
821
822//------------------------------------------------------------------------------
825inline void
827{
828 n_assert(this->GetValueType() != VoidType);
829 switch (this->GetValueType())
830 {
831 case IntType:
832 this->valueData = str.AsInt();
833 break;
834
835 case FloatType:
836 this->valueData = str.AsFloat();
837 break;
838
839 case BoolType:
840 this->valueData = str.AsBool();
841 break;
842
843 case Vec4Type:
844 this->valueData = str.AsVec4();
845 break;
846
847 case StringType:
848 this->valueData = str;
849 break;
850
851 case Mat4Type:
852 this->valueData = str.AsMat4();
853 break;
854
855 case GuidType:
856 this->valueData = Util::Guid::FromString(str);
857 break;
858
859 default:
860 n_error("Attribute::SetValueFromString(): cannot convert string to attribute type!");
861 break;
862 }
863}
864
865//------------------------------------------------------------------------------
868inline Util::String
870{
871 n_assert(this->GetValueType() != VoidType);
872 Util::String str;
873 switch (this->GetValueType())
874 {
875 case IntType:
876 str.SetInt(this->GetInt());
877 break;
878
879 case FloatType:
880 str.SetFloat(this->GetFloat());
881 break;
882
883 case BoolType:
884 str.SetBool(this->GetBool());
885 break;
886
887 case Vec4Type:
888 str.SetVec4(this->GetVec4());
889 break;
890
891 case StringType:
892 str = this->GetString();
893 break;
894
895 case Mat4Type:
896 str.SetMat4(this->GetMat4());
897 break;
898
899 case GuidType:
900 str = this->GetGuid().AsString();
901 break;
902
903 case BlobType:
904 n_error("Attribute: Cannot convert blob to string (attrid='%s')!", this->GetName().AsCharPtr());
905 break;
906
907 case VoidType:
908 n_error("Attribute: Cannot convert void attribute to string (attrid='%s')!", this->GetName().AsCharPtr());
909 break;
910 default: n_error("Attribute: unhandled enum"); break;
911 }
912 return str;
913}
914
915//------------------------------------------------------------------------------
918inline ValueType
923
924//------------------------------------------------------------------------------
927inline Util::String
932
933//------------------------------------------------------------------------------
936inline void
938{
939 this->valueData = val;
940}
941
942//------------------------------------------------------------------------------
945inline const Util::Variant&
947{
948 return this->valueData;
949}
950
951} // namespace Attr
952//------------------------------------------------------------------------------
An attribute ID is used to carry attribute types (no values) around.
Definition attrid.h:20
bool GetBool() const
get bool content
Definition attribute.h:627
void SetVec4(const Math::vec4 &val)
set float4 value
Definition attribute.h:763
void operator=(const Attribute &rhs)
assignment operator
Definition attribute.h:390
const AttrId & GetAttrId() const
get attribute id
Definition attribute.h:336
AccessMode GetAccessMode() const
get access mode of attribute
Definition attribute.h:372
int64_t GetInt64() const
get int64 content
Definition attribute.h:690
void SetBool(bool val)
set bool content
Definition attribute.h:616
const Util::String & GetName() const
get name of attribute
Definition attribute.h:345
bool operator==(const Attribute &rhs) const
equality operator
Definition attribute.h:488
const Util::Blob & GetBlob() const
get blob value
Definition attribute.h:816
uint GetUInt() const
get int content
Definition attribute.h:669
void Clear()
clear the attribute's value
Definition attribute.h:381
Math::vec4 GetVec4() const
get float4 value
Definition attribute.h:774
Attribute()
default constructor
Definition attribute.h:188
static ValueType StringToValueType(const Util::String &s)
convert string to type
Definition attribute.h:919
const Util::String & GetString() const
get string content
Definition attribute.h:732
void SetValue(const Util::Variant &val)
set generic value
Definition attribute.h:937
void SetUInt(uint val)
set int content
Definition attribute.h:658
void SetAttrId(const AttrId &id)
set attribute id
Definition attribute.h:327
void SetString(const Util::String &val)
set string content
Definition attribute.h:721
Util::String ValueAsString() const
convert the content to a string
Definition attribute.h:869
void SetGuid(const Util::Guid &val)
set guid value
Definition attribute.h:784
void SetFloat(float val)
set float content
Definition attribute.h:700
void SetMat4(const Math::mat4 &val)
set matrix44 value
Definition attribute.h:742
void SetValueFromString(const Util::String &str)
set value from string (convert as necessary)
Definition attribute.h:826
float GetFloat() const
get float content
Definition attribute.h:711
ValueType GetValueType() const
get value type of attribute
Definition attribute.h:363
const Util::Variant & GetValue() const
get generic value
Definition attribute.h:946
const Util::FourCC & GetFourCC() const
get fourcc of attribute
Definition attribute.h:354
bool operator!=(const Attribute &rhs) const
equality operator
Definition attribute.h:557
void SetInt(int val)
set int content
Definition attribute.h:637
const Math::mat4 & GetMat4() const
get matrix44 value
Definition attribute.h:753
bool operator!=(bool rhs) const
bool equality operator
static Util::String ValueTypeToString(ValueType t)
convert type to string
Definition attribute.h:928
int GetInt() const
get int content
Definition attribute.h:648
void SetBlob(const Util::Blob &val)
set blob value
Definition attribute.h:805
const Util::Guid & GetGuid() const
get guid value
Definition attribute.h:795
void SetInt64(int64_t val)
set int64 content
Definition attribute.h:679
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
Definition intattrid.h:97
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
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
KeyValuePair()
Definition keyvaluepair.h:74
An "any type" variable.
Definition variant.h:32
Type
variant types
Definition variant.h:36
static Type StringToType(const Util::String &str)
convert string to type
Definition variant.h:3599
static Util::String TypeToString(Type t)
convert type to string
Definition variant.h:3555
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:32
@ IntType
Definition valuetype.h:25
@ FloatType
Definition valuetype.h:28
@ Mat4Type
Definition valuetype.h:35
@ BoolType
Definition valuetype.h:30
@ Int64Type
Definition valuetype.h:27
@ StringType
Definition valuetype.h:34
@ BlobType
Definition valuetype.h:37
@ UIntType
Definition valuetype.h:26
@ VoidType
Definition valuetype.h:21
@ GuidType
Definition valuetype.h:38
AccessMode
Definition accessmode.h:15
@ ReadWrite
Definition accessmode.h:17
A quad tree designed to return regions of free 2D space.
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.cs:8
void SetBool(bool val)
set as bool value
Definition string.cc:1500
bool AsBool() const
return contents as bool
Definition string.cc:1086
void SetInt(int val)
set as int value
Definition string.cc:1419
Math::mat4 AsMat4() const
return contents as mat4
Definition string.cc:695
int AsInt() const
return contents as integer
Definition string.cc:1029
void SetVec4(const Math::vec4 &v)
set as vec4 value
Definition string.cc:1548
void SetFloat(float val)
set as float value
Definition string.cc:1482
float AsFloat() const
return contents as float
Definition string.cc:1077
void SetMat4(const Math::mat4 &v)
set as mat4 value
Definition string.cc:1593
Math::vec4 AsVec4() const
return contents as vec4
Definition string.cc:1704
unsigned int uint
Definition types.h:33