9 #ifndef Navigation_BlobField32_H
10 #define Navigation_BlobField32_H
28 static const
KyUInt32 Type_Unset = 0;
29 static const
KyUInt32 Type_KyUInt32 = 1;
30 static const
KyUInt32 Type_KyInt32 = 2;
31 static const
KyUInt32 Type_KyFloat32 = 3;
35 BlobField32() : m_type(Type_Unset), m_value(0) {}
37 KyUInt32& ValueAsUInt32() {
return m_value; }
39 KyFloat32& ValueAsFloat32() {
char* value = (
char*)&m_value;
return *(
KyFloat32*)value; }
42 BlobArray<char> m_name;
48 SwapEndianness(e,
self.m_name);
49 SwapEndianness(e,
self.m_type);
50 SwapEndianness(e,
self.m_value);
54 class BlobField32Mapping
58 BlobField32Mapping() : m_type(BlobField32::Type_Unset), m_name(
KY_NULL), m_value(KY_NULL) {}
60 BlobField32Mapping(
KyUInt32 type,
const char* name,
bool* value) : m_type(type), m_name(name), m_value((char*)value) {}
61 BlobField32Mapping(
KyUInt32 type,
const char* name,
KyUInt32* value) : m_type(type), m_name(name), m_value((char*)value) {}
62 BlobField32Mapping(
KyUInt32 type,
const char* name,
KyInt32* value) : m_type(type), m_name(name), m_value((char*)value) {}
63 BlobField32Mapping(
KyUInt32 type,
const char* name,
KyFloat32* value) : m_type(type), m_name(name), m_value((char*)value) {}
65 bool& ValueAsBool() {
return *((
bool*)m_value); }
70 bool GetValueAsBool() {
return *((
bool*)m_value); }
75 void SetValueAsBool(
bool value) { *((
bool*)m_value) = value; }
77 void SetValueAsInt32(
KyInt32 value) { *((
KyInt32*)m_value) = value; }
80 void SetValueFromBlobValue32(
KyUInt32 blobValue32)
82 if (m_type == BlobField32::Type_Bool)
83 *((
bool*)m_value) = (blobValue32 != 1);
95 template <
class OSTREAM>
96 inline OSTREAM& operator<<(OSTREAM& os, BlobField32Mapping& mapping)
98 os << mapping.m_name <<
" : ";
100 switch(mapping.m_type)
102 case BlobField32::Type_KyUInt32 : os <<(*(
KyUInt32*) (mapping.m_value));
break;
103 case BlobField32::Type_KyInt32 : os <<(*(
KyInt32*) (mapping.m_value));
break;
104 case BlobField32::Type_KyFloat32 : os <<(*(
KyFloat32*)(mapping.m_value));
break;
105 case BlobField32::Type_Bool : os <<(*(
bool*) (mapping.m_value));
break;
112 class BlobField32Builder :
public BaseBlobBuilder<BlobField32>
115 BlobField32Builder(BlobField32Mapping& mapping) : m_mapping(&mapping) {}
118 virtual void DoBuild()
125 BlobField32Mapping* m_mapping;
131 class BlobMultiField32
135 BlobMultiField32() : m_valueType(BlobField32::Type_Unset) {}
137 KyUInt32 GetCount()
const {
return m_values.GetCount(); }
139 const KyUInt32& ValueAsUInt32(
KyUInt32 idx)
const {
return m_values.GetValues()[idx]; }
140 const KyInt32& ValueAsInt32(
KyUInt32 idx)
const {
char* v = (
char*)(&m_values.GetValues()[idx]);
return *(
KyInt32*)v; }
143 KyUInt32 GetValueAsUInt32(
KyUInt32 idx)
const {
return m_values.GetValues()[idx]; }
144 KyInt32 GetValueAsInt32(
KyUInt32 idx)
const {
char* v = (
char*)(&m_values.GetValues()[idx]);
return *(
KyInt32*)v; }
147 void SetValueAsUInt32(
KyUInt32 idx,
KyUInt32 value) { m_values.GetValues()[idx] = value; }
148 void SetValueAsInt32(
KyUInt32 idx,
KyInt32 value) {
char* v = (
char*)&value; m_values.GetValues()[idx] = *((
KyUInt32*)v); }
149 void SetValueAsFloat32(
KyUInt32 idx,
KyFloat32 value) {
char* v = (
char*)&value; m_values.GetValues()[idx] = *((
KyUInt32*)v); }
152 BlobArray<char> m_name;
153 BlobArray<char> m_category;
155 BlobArray<KyUInt32> m_values;
159 SwapEndianness(e,
self.m_name);
160 SwapEndianness(e,
self.m_category);
161 SwapEndianness(e,
self.m_valueType);
162 SwapEndianness(e,
self.m_values);
166 class BlobMultiField32Mapping
170 BlobMultiField32Mapping()
171 : m_valueType(BlobField32::Type_Unset), m_name(
KY_NULL), m_category (KY_NULL), m_values(KY_NULL) {}
173 BlobMultiField32Mapping(
KyUInt32 type,
const char* name,
const char* category,
KyUInt32 size)
174 : m_valueType(type), m_name(name), m_category(category), m_values(size) {}
177 KyUInt32 GetCount()
const {
return m_values.GetCount(); }
179 void MapUInt32(
KyUInt32 index,
const KyUInt32& value) { m_values[index] = (
char*)&value; }
180 void MapInt32(
KyUInt32 index,
const KyInt32& value) { m_values[index] = (
char*)&value; }
181 void MapFloat32(
KyUInt32 index,
const KyFloat32& value) { m_values[index] = (
char*)&value; }
189 if (m_valueType == BlobField32::Type_Bool)
190 *((
bool*)m_values[index]) = (blobValue32 != 1);
192 *((
KyUInt32*)m_values[index]) = blobValue32;
198 const char* m_category;
199 KyArrayPOD<char*> m_values;
203 template <
class OSTREAM>
204 inline OSTREAM& operator<<(OSTREAM& os, BlobMultiField32Mapping& mapping)
206 os << mapping.m_name <<
"(" << mapping.m_category <<
") : ";
208 for (
KyUInt32 idx = 0; idx < mapping.GetCount(); ++idx)
210 switch(mapping.m_valueType)
212 case BlobField32::Type_KyUInt32 : os <<((
KyUInt32) (mapping.ValueAsUInt32(idx)));
break;
213 case BlobField32::Type_KyInt32 : os <<((
KyInt32) (mapping.ValueAsInt32(idx)));
break;
214 case BlobField32::Type_KyFloat32 : os <<((
KyFloat32)(mapping.ValueAsFloat32(idx)));
break;
226 class BlobMultiField32Builder :
public BaseBlobBuilder<BlobMultiField32>
229 BlobMultiField32Builder(BlobMultiField32Mapping& mapping) : m_mapping(&mapping) {}
232 virtual void DoBuild()
238 KyUInt32 count = m_mapping->GetCount();
242 for (
KyUInt32 idx = 0; idx < count; ++idx)
244 blobValues[idx] = m_mapping->ValueAsUInt32(idx);
249 BlobMultiField32Mapping* m_mapping;
#define BLOB_SET(blob, value)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:136
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
BlobField32 * m_blob
The blob maintained by this builder. Only modify using the macros listed under DoBuild().
Definition: baseblobbuilder.h:117
Definition: gamekitcrowddispersion.h:20
bool IsWriteMode()
Indicates whether the builder is operating in COUNT mode or in WRITE mode.
Definition: baseblobbuilder.h:47
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
#define BLOB_STRING(str, src)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:179
#define BLOB_ARRAY(blobArray, count)
Use this macro only in implementations of BaseBlobBuilder::DoBuild().
Definition: baseblobbuilder.h:147
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43