17575abbcSIngo Weinhold/*
27575abbcSIngo Weinhold * Copyright 2009,2011, Haiku, Inc.
37575abbcSIngo Weinhold * Distributed under the terms of the MIT License.
47575abbcSIngo Weinhold */
57575abbcSIngo Weinhold#ifndef _PACKAGE__HPKG__V1__PACKAGE_ATTRIBUTE_VALUE_H_
67575abbcSIngo Weinhold#define _PACKAGE__HPKG__V1__PACKAGE_ATTRIBUTE_VALUE_H_
77575abbcSIngo Weinhold
87575abbcSIngo Weinhold
97575abbcSIngo Weinhold#include <string.h>
107575abbcSIngo Weinhold
117575abbcSIngo Weinhold#include <package/hpkg/v1/HPKGDefs.h>
127575abbcSIngo Weinhold
137575abbcSIngo Weinhold
147575abbcSIngo Weinholdnamespace BPackageKit {
157575abbcSIngo Weinhold
167575abbcSIngo Weinholdnamespace BHPKG {
177575abbcSIngo Weinhold
187575abbcSIngo Weinholdnamespace V1 {
197575abbcSIngo Weinhold
207575abbcSIngo Weinhold
217575abbcSIngo Weinholdstruct BPackageAttributeValue {
227575abbcSIngo Weinhold			union {
237575abbcSIngo Weinhold				int64			signedInt;
247575abbcSIngo Weinhold				uint64			unsignedInt;
257575abbcSIngo Weinhold				const char*		string;
267575abbcSIngo Weinhold				struct {
277575abbcSIngo Weinhold					uint64		size;
287575abbcSIngo Weinhold					union {
297575abbcSIngo Weinhold						uint64	offset;
307575abbcSIngo Weinhold						uint8	raw[B_HPKG_MAX_INLINE_DATA_SIZE];
317575abbcSIngo Weinhold					};
327575abbcSIngo Weinhold				} data;
337575abbcSIngo Weinhold			};
347575abbcSIngo Weinhold			uint8				type;
357575abbcSIngo Weinhold			uint8				encoding;
367575abbcSIngo Weinhold
377575abbcSIngo Weinholdpublic:
387575abbcSIngo Weinhold	inline						BPackageAttributeValue();
397575abbcSIngo Weinhold
407575abbcSIngo Weinhold	inline	void				SetTo(int8 value);
417575abbcSIngo Weinhold	inline	void				SetTo(uint8 value);
427575abbcSIngo Weinhold	inline	void				SetTo(int16 value);
437575abbcSIngo Weinhold	inline	void				SetTo(uint16 value);
447575abbcSIngo Weinhold	inline	void				SetTo(int32 value);
457575abbcSIngo Weinhold	inline	void				SetTo(uint32 value);
467575abbcSIngo Weinhold	inline	void				SetTo(int64 value);
477575abbcSIngo Weinhold	inline	void				SetTo(uint64 value);
487575abbcSIngo Weinhold	inline	void				SetTo(const char* value);
497575abbcSIngo Weinhold	inline	void				SetToData(uint64 size, uint64 offset);
507575abbcSIngo Weinhold	inline	void				SetToData(uint64 size, const void* rawData);
517575abbcSIngo Weinhold};
527575abbcSIngo Weinhold
537575abbcSIngo Weinhold
547575abbcSIngo WeinholdBPackageAttributeValue::BPackageAttributeValue()
557575abbcSIngo Weinhold	:
567575abbcSIngo Weinhold	type(B_HPKG_ATTRIBUTE_TYPE_INVALID)
577575abbcSIngo Weinhold{
587575abbcSIngo Weinhold}
597575abbcSIngo Weinhold
607575abbcSIngo Weinhold
617575abbcSIngo Weinholdvoid
627575abbcSIngo WeinholdBPackageAttributeValue::SetTo(int8 value)
637575abbcSIngo Weinhold{
647575abbcSIngo Weinhold	signedInt = value;
657575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
667575abbcSIngo Weinhold}
677575abbcSIngo Weinhold
687575abbcSIngo Weinhold
697575abbcSIngo Weinholdvoid
707575abbcSIngo WeinholdBPackageAttributeValue::SetTo(uint8 value)
717575abbcSIngo Weinhold{
727575abbcSIngo Weinhold	unsignedInt = value;
737575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
747575abbcSIngo Weinhold}
757575abbcSIngo Weinhold
767575abbcSIngo Weinhold
777575abbcSIngo Weinholdvoid
787575abbcSIngo WeinholdBPackageAttributeValue::SetTo(int16 value)
797575abbcSIngo Weinhold{
807575abbcSIngo Weinhold	signedInt = value;
817575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
827575abbcSIngo Weinhold}
837575abbcSIngo Weinhold
847575abbcSIngo Weinhold
857575abbcSIngo Weinholdvoid
867575abbcSIngo WeinholdBPackageAttributeValue::SetTo(uint16 value)
877575abbcSIngo Weinhold{
887575abbcSIngo Weinhold	unsignedInt = value;
897575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
907575abbcSIngo Weinhold}
917575abbcSIngo Weinhold
927575abbcSIngo Weinhold
937575abbcSIngo Weinholdvoid
947575abbcSIngo WeinholdBPackageAttributeValue::SetTo(int32 value)
957575abbcSIngo Weinhold{
967575abbcSIngo Weinhold	signedInt = value;
977575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
987575abbcSIngo Weinhold}
997575abbcSIngo Weinhold
1007575abbcSIngo Weinhold
1017575abbcSIngo Weinholdvoid
1027575abbcSIngo WeinholdBPackageAttributeValue::SetTo(uint32 value)
1037575abbcSIngo Weinhold{
1047575abbcSIngo Weinhold	unsignedInt = value;
1057575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
1067575abbcSIngo Weinhold}
1077575abbcSIngo Weinhold
1087575abbcSIngo Weinhold
1097575abbcSIngo Weinholdvoid
1107575abbcSIngo WeinholdBPackageAttributeValue::SetTo(int64 value)
1117575abbcSIngo Weinhold{
1127575abbcSIngo Weinhold	signedInt = value;
1137575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
1147575abbcSIngo Weinhold}
1157575abbcSIngo Weinhold
1167575abbcSIngo Weinhold
1177575abbcSIngo Weinholdvoid
1187575abbcSIngo WeinholdBPackageAttributeValue::SetTo(uint64 value)
1197575abbcSIngo Weinhold{
1207575abbcSIngo Weinhold	unsignedInt = value;
1217575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
1227575abbcSIngo Weinhold}
1237575abbcSIngo Weinhold
1247575abbcSIngo Weinhold
1257575abbcSIngo Weinholdvoid
1267575abbcSIngo WeinholdBPackageAttributeValue::SetTo(const char* value)
1277575abbcSIngo Weinhold{
1287575abbcSIngo Weinhold	string = value;
1297575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_STRING;
1307575abbcSIngo Weinhold}
1317575abbcSIngo Weinhold
1327575abbcSIngo Weinhold
1337575abbcSIngo Weinholdvoid
1347575abbcSIngo WeinholdBPackageAttributeValue::SetToData(uint64 size, uint64 offset)
1357575abbcSIngo Weinhold{
1367575abbcSIngo Weinhold	data.size = size;
1377575abbcSIngo Weinhold	data.offset = offset;
1387575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_RAW;
1397575abbcSIngo Weinhold	encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP;
1407575abbcSIngo Weinhold}
1417575abbcSIngo Weinhold
1427575abbcSIngo Weinhold
1437575abbcSIngo Weinholdvoid
1447575abbcSIngo WeinholdBPackageAttributeValue::SetToData(uint64 size, const void* rawData)
1457575abbcSIngo Weinhold{
1467575abbcSIngo Weinhold	data.size = size;
1477575abbcSIngo Weinhold	if (size > 0)
1487575abbcSIngo Weinhold		memcpy(data.raw, rawData, size);
1497575abbcSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_RAW;
1507575abbcSIngo Weinhold	encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE;
1517575abbcSIngo Weinhold}
1527575abbcSIngo Weinhold
1537575abbcSIngo Weinhold
1547575abbcSIngo Weinhold}	// namespace V1
1557575abbcSIngo Weinhold
1567575abbcSIngo Weinhold}	// namespace BHPKG
1577575abbcSIngo Weinhold
1587575abbcSIngo Weinhold}	// namespace BPackageKit
1597575abbcSIngo Weinhold
1607575abbcSIngo Weinhold
1617575abbcSIngo Weinhold#endif	// _PACKAGE__HPKG__V1__PACKAGE_ATTRIBUTE_VALUE_H_
162