* Added missing bool type support.

* Added Bytes(), returning a pointer to the "raw" data, and Size(), returning
  the data size.
* Added SetToTypedData(), which initializes the object from a data buffer and a
  type code.
* Added SwapEndianess() to swap the endianess of the contained data (if
  possible).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31627 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-07-18 23:01:48 +00:00
parent 591eab0aba
commit b5d6fc7173
2 changed files with 173 additions and 5 deletions
+31 -3
View File
@@ -19,6 +19,7 @@ enum {
class BVariant {
public:
inline BVariant();
inline BVariant(bool value);
inline BVariant(int8 value);
inline BVariant(uint8 value);
inline BVariant(int16 value);
@@ -36,6 +37,7 @@ public:
~BVariant();
inline void SetTo(const BVariant& other);
inline void SetTo(bool value);
inline void SetTo(int8 value);
inline void SetTo(uint8 value);
inline void SetTo(int16 value);
@@ -49,17 +51,22 @@ public:
inline void SetTo(const void* value);
inline void SetTo(const char* value,
uint32 flags = 0);
status_t SetToTypedData(const void* data,
type_code type);
void Unset();
inline BVariant& operator=(const BVariant& other);
type_code Type() const { return fType; }
inline type_code Type() const { return fType; }
size_t Size() const;
const uint8* Bytes() const;
bool IsNumber() const;
bool IsInteger() const;
bool IsFloat() const;
// floating point, not just float
bool ToBool() const;
int8 ToInt8() const;
uint8 ToUInt8() const;
int16 ToInt16() const;
@@ -73,10 +80,15 @@ public:
void* ToPointer() const;
const char* ToString() const;
static size_t SizeOfType(uint32 type);
void SwapEndianess();
// has effect only on scalar types (pointer
// counting as scalar, not string, though)
static size_t SizeOfType(type_code type);
private:
void _SetTo(const BVariant& other);
void _SetTo(bool value);
void _SetTo(int8 value);
void _SetTo(uint8 value);
void _SetTo(int16 value);
@@ -88,7 +100,7 @@ private:
void _SetTo(float value);
void _SetTo(double value);
void _SetTo(const void* value);
void _SetTo(const char* value,
bool _SetTo(const char* value,
uint32 flags);
template<typename NumberType>
@@ -98,6 +110,7 @@ private:
type_code fType;
uint32 fFlags;
union {
bool fBool;
int8 fInt8;
uint8 fUInt8;
int16 fInt16;
@@ -110,6 +123,7 @@ private:
double fDouble;
void* fPointer;
char* fString;
uint8 fBytes[8];
};
};
@@ -122,6 +136,12 @@ BVariant::BVariant()
}
BVariant::BVariant(bool value)
{
_SetTo(value);
}
BVariant::BVariant(int8 value)
{
_SetTo(value);
@@ -217,6 +237,14 @@ BVariant::SetTo(const BVariant& other)
}
void
BVariant::SetTo(bool value)
{
Unset();
_SetTo(value);
}
void
BVariant::SetTo(int8 value)
{