2009-11-13 16:45:49 +03:00
|
|
|
/*
|
2011-01-30 18:15:33 +03:00
|
|
|
* Copyright 2009,2011, Haiku, Inc.
|
2009-11-13 16:45:49 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-30 18:05:38 +03:00
|
|
|
#ifndef _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
|
|
|
|
#define _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
#include <package/hpkg/HPKGDefs.h>
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
namespace BHPKG {
|
2011-01-28 02:17:03 +03:00
|
|
|
|
2009-11-13 16:45:49 +03:00
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
struct BPackageAttributeValue {
|
2009-11-13 16:45:49 +03:00
|
|
|
union {
|
|
|
|
int64 signedInt;
|
|
|
|
uint64 unsignedInt;
|
|
|
|
const char* string;
|
|
|
|
struct {
|
|
|
|
uint64 size;
|
|
|
|
union {
|
|
|
|
uint64 offset;
|
|
|
|
uint8 raw[B_HPKG_MAX_INLINE_DATA_SIZE];
|
|
|
|
};
|
|
|
|
} data;
|
|
|
|
};
|
|
|
|
uint8 type;
|
|
|
|
uint8 encoding;
|
|
|
|
|
|
|
|
public:
|
2011-01-30 18:05:38 +03:00
|
|
|
inline BPackageAttributeValue();
|
2009-11-13 16:45:49 +03:00
|
|
|
|
|
|
|
inline void SetTo(int8 value);
|
|
|
|
inline void SetTo(uint8 value);
|
|
|
|
inline void SetTo(int16 value);
|
|
|
|
inline void SetTo(uint16 value);
|
|
|
|
inline void SetTo(int32 value);
|
|
|
|
inline void SetTo(uint32 value);
|
|
|
|
inline void SetTo(int64 value);
|
|
|
|
inline void SetTo(uint64 value);
|
|
|
|
inline void SetTo(const char* value);
|
|
|
|
inline void SetToData(uint64 size, uint64 offset);
|
|
|
|
inline void SetToData(uint64 size, const void* rawData);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::BPackageAttributeValue()
|
2009-11-13 16:45:49 +03:00
|
|
|
:
|
|
|
|
type(B_HPKG_ATTRIBUTE_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(int8 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
signedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(uint8 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
unsignedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(int16 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
signedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(uint16 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
unsignedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(int32 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
signedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(uint32 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
unsignedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(int64 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
signedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_INT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(uint64 value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
unsignedInt = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_UINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetTo(const char* value)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
string = value;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetToData(uint64 size, uint64 offset)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
data.size = size;
|
|
|
|
data.offset = offset;
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_RAW;
|
|
|
|
encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2011-01-30 18:05:38 +03:00
|
|
|
BPackageAttributeValue::SetToData(uint64 size, const void* rawData)
|
2009-11-13 16:45:49 +03:00
|
|
|
{
|
|
|
|
data.size = size;
|
|
|
|
if (size > 0)
|
|
|
|
memcpy(data.raw, rawData, size);
|
|
|
|
type = B_HPKG_ATTRIBUTE_TYPE_RAW;
|
|
|
|
encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
} // namespace BHPKG
|
2011-01-28 02:17:03 +03:00
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
2011-01-30 18:05:38 +03:00
|
|
|
#endif // _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
|