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:
@@ -9,10 +9,13 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
|
|
||||||
|
#include <Referenceable.h>
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
B_VARIANT_DONT_COPY_DATA = 0x01,
|
B_VARIANT_DONT_COPY_DATA = 0x01,
|
||||||
B_VARIANT_OWNS_DATA = 0x02
|
B_VARIANT_OWNS_DATA = 0x02,
|
||||||
|
B_VARIANT_REFERENCEABLE_DATA = 0x04
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -33,6 +36,8 @@ public:
|
|||||||
inline BVariant(const void* value);
|
inline BVariant(const void* value);
|
||||||
inline BVariant(const char* value,
|
inline BVariant(const char* value,
|
||||||
uint32 flags = 0);
|
uint32 flags = 0);
|
||||||
|
inline BVariant(BReferenceable* value, type_code type);
|
||||||
|
// type must be a custom type
|
||||||
inline BVariant(const BVariant& other);
|
inline BVariant(const BVariant& other);
|
||||||
~BVariant();
|
~BVariant();
|
||||||
|
|
||||||
@@ -51,6 +56,8 @@ public:
|
|||||||
inline void SetTo(const void* value);
|
inline void SetTo(const void* value);
|
||||||
inline void SetTo(const char* value,
|
inline void SetTo(const char* value,
|
||||||
uint32 flags = 0);
|
uint32 flags = 0);
|
||||||
|
inline void SetTo(BReferenceable* value, type_code type);
|
||||||
|
// type must be a custom type
|
||||||
status_t SetToTypedData(const void* data,
|
status_t SetToTypedData(const void* data,
|
||||||
type_code type);
|
type_code type);
|
||||||
void Unset();
|
void Unset();
|
||||||
@@ -102,6 +109,7 @@ private:
|
|||||||
void _SetTo(const void* value);
|
void _SetTo(const void* value);
|
||||||
bool _SetTo(const char* value,
|
bool _SetTo(const char* value,
|
||||||
uint32 flags);
|
uint32 flags);
|
||||||
|
void _SetTo(BReferenceable* value, type_code type);
|
||||||
|
|
||||||
template<typename NumberType>
|
template<typename NumberType>
|
||||||
inline NumberType _ToNumber() const;
|
inline NumberType _ToNumber() const;
|
||||||
@@ -123,6 +131,7 @@ private:
|
|||||||
double fDouble;
|
double fDouble;
|
||||||
void* fPointer;
|
void* fPointer;
|
||||||
char* fString;
|
char* fString;
|
||||||
|
BReferenceable* fReferenceable;
|
||||||
uint8 fBytes[8];
|
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)
|
BVariant::BVariant(const BVariant& other)
|
||||||
{
|
{
|
||||||
_SetTo(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
|
#endif // _VARIANT_H
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ BVariant::Unset()
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if ((fFlags & B_VARIANT_REFERENCEABLE_DATA) != 0) {
|
||||||
|
if (fReferenceable != NULL)
|
||||||
|
fReferenceable->ReleaseReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
fType = 0;
|
fType = 0;
|
||||||
@@ -127,6 +130,8 @@ BVariant::Size() const
|
|||||||
{
|
{
|
||||||
if (fType == B_STRING_TYPE)
|
if (fType == B_STRING_TYPE)
|
||||||
return fString != NULL ? strlen(fString) + 1 : 0;
|
return fString != NULL ? strlen(fString) + 1 : 0;
|
||||||
|
if ((fFlags & B_VARIANT_REFERENCEABLE_DATA) != 0)
|
||||||
|
return sizeof(this->fReferenceable);
|
||||||
return SizeOfType(fType);
|
return SizeOfType(fType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,6 +334,9 @@ BVariant::_SetTo(const BVariant& other)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if ((other.fFlags & B_VARIANT_REFERENCEABLE_DATA) != 0) {
|
||||||
|
if (other.fReferenceable != NULL)
|
||||||
|
fReferenceable->AcquireReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(this, &other, sizeof(BVariant));
|
memcpy(this, &other, sizeof(BVariant));
|
||||||
@@ -509,3 +517,14 @@ BVariant::_SetTo(const char* value, uint32 flags)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BVariant::_SetTo(BReferenceable* value, type_code type)
|
||||||
|
{
|
||||||
|
fType = type;
|
||||||
|
fFlags = B_VARIANT_REFERENCEABLE_DATA;
|
||||||
|
fReferenceable = value;
|
||||||
|
|
||||||
|
if (fReferenceable != NULL)
|
||||||
|
fReferenceable->AcquireReference();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user