Added support for containing BReferenceables of arbitrary actual type.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31744 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6feb776265
commit
d8c41ef38f
@ -9,10 +9,13 @@
|
||||
#include <SupportDefs.h>
|
||||
#include <TypeConstants.h>
|
||||
|
||||
#include <Referenceable.h>
|
||||
|
||||
|
||||
enum {
|
||||
B_VARIANT_DONT_COPY_DATA = 0x01,
|
||||
B_VARIANT_OWNS_DATA = 0x02
|
||||
B_VARIANT_DONT_COPY_DATA = 0x01,
|
||||
B_VARIANT_OWNS_DATA = 0x02,
|
||||
B_VARIANT_REFERENCEABLE_DATA = 0x04
|
||||
};
|
||||
|
||||
|
||||
@ -33,6 +36,8 @@ public:
|
||||
inline BVariant(const void* value);
|
||||
inline BVariant(const char* value,
|
||||
uint32 flags = 0);
|
||||
inline BVariant(BReferenceable* value, type_code type);
|
||||
// type must be a custom type
|
||||
inline BVariant(const BVariant& other);
|
||||
~BVariant();
|
||||
|
||||
@ -51,6 +56,8 @@ public:
|
||||
inline void SetTo(const void* value);
|
||||
inline void SetTo(const char* value,
|
||||
uint32 flags = 0);
|
||||
inline void SetTo(BReferenceable* value, type_code type);
|
||||
// type must be a custom type
|
||||
status_t SetToTypedData(const void* data,
|
||||
type_code type);
|
||||
void Unset();
|
||||
@ -102,6 +109,7 @@ private:
|
||||
void _SetTo(const void* value);
|
||||
bool _SetTo(const char* value,
|
||||
uint32 flags);
|
||||
void _SetTo(BReferenceable* value, type_code type);
|
||||
|
||||
template<typename NumberType>
|
||||
inline NumberType _ToNumber() const;
|
||||
@ -123,6 +131,7 @@ private:
|
||||
double fDouble;
|
||||
void* fPointer;
|
||||
char* fString;
|
||||
BReferenceable* fReferenceable;
|
||||
uint8 fBytes[8];
|
||||
};
|
||||
};
|
||||
@ -214,6 +223,12 @@ BVariant::BVariant(const char* value, uint32 flags)
|
||||
}
|
||||
|
||||
|
||||
BVariant::BVariant(BReferenceable* value, type_code type)
|
||||
{
|
||||
_SetTo(value, type);
|
||||
}
|
||||
|
||||
|
||||
BVariant::BVariant(const BVariant& other)
|
||||
{
|
||||
_SetTo(other);
|
||||
@ -341,4 +356,12 @@ BVariant::SetTo(const char* value, uint32 flags)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BVariant::SetTo(BReferenceable* value, type_code type)
|
||||
{
|
||||
Unset();
|
||||
_SetTo(value, type);
|
||||
}
|
||||
|
||||
|
||||
#endif // _VARIANT_H
|
||||
|
@ -115,6 +115,9 @@ BVariant::Unset()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if ((fFlags & B_VARIANT_REFERENCEABLE_DATA) != 0) {
|
||||
if (fReferenceable != NULL)
|
||||
fReferenceable->ReleaseReference();
|
||||
}
|
||||
|
||||
fType = 0;
|
||||
@ -127,6 +130,8 @@ BVariant::Size() const
|
||||
{
|
||||
if (fType == B_STRING_TYPE)
|
||||
return fString != NULL ? strlen(fString) + 1 : 0;
|
||||
if ((fFlags & B_VARIANT_REFERENCEABLE_DATA) != 0)
|
||||
return sizeof(this->fReferenceable);
|
||||
return SizeOfType(fType);
|
||||
}
|
||||
|
||||
@ -329,6 +334,9 @@ BVariant::_SetTo(const BVariant& other)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if ((other.fFlags & B_VARIANT_REFERENCEABLE_DATA) != 0) {
|
||||
if (other.fReferenceable != NULL)
|
||||
fReferenceable->AcquireReference();
|
||||
}
|
||||
|
||||
memcpy(this, &other, sizeof(BVariant));
|
||||
@ -509,3 +517,14 @@ BVariant::_SetTo(const char* value, uint32 flags)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BVariant::_SetTo(BReferenceable* value, type_code type)
|
||||
{
|
||||
fType = type;
|
||||
fFlags = B_VARIANT_REFERENCEABLE_DATA;
|
||||
fReferenceable = value;
|
||||
|
||||
if (fReferenceable != NULL)
|
||||
fReferenceable->AcquireReference();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user