1050aa61bSIngo Weinhold/*
295d84e41SOliver Tappe * Copyright 2009,2011, Haiku, Inc.
3050aa61bSIngo Weinhold * Distributed under the terms of the MIT License.
4050aa61bSIngo Weinhold */
55fb1c6ffSOliver Tappe#ifndef _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
65fb1c6ffSOliver Tappe#define _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
7050aa61bSIngo Weinhold
8050aa61bSIngo Weinhold
9050aa61bSIngo Weinhold#include <string.h>
10050aa61bSIngo Weinhold
115fb1c6ffSOliver Tappe#include <package/hpkg/HPKGDefs.h>
120d6b3b20SOliver Tappe
130d6b3b20SOliver Tappe
140d6b3b20SOliver Tappenamespace BPackageKit {
150d6b3b20SOliver Tappe
165fb1c6ffSOliver Tappenamespace BHPKG {
170d6b3b20SOliver Tappe
18050aa61bSIngo Weinhold
195fb1c6ffSOliver Tappestruct BPackageAttributeValue {
20050aa61bSIngo Weinhold			union {
21050aa61bSIngo Weinhold				int64			signedInt;
22050aa61bSIngo Weinhold				uint64			unsignedInt;
23050aa61bSIngo Weinhold				const char*		string;
24050aa61bSIngo Weinhold				struct {
25050aa61bSIngo Weinhold					uint64		size;
26050aa61bSIngo Weinhold					union {
27050aa61bSIngo Weinhold						uint64	offset;
28050aa61bSIngo Weinhold						uint8	raw[B_HPKG_MAX_INLINE_DATA_SIZE];
29050aa61bSIngo Weinhold					};
30050aa61bSIngo Weinhold				} data;
31050aa61bSIngo Weinhold			};
32050aa61bSIngo Weinhold			uint8				type;
33050aa61bSIngo Weinhold			uint8				encoding;
34050aa61bSIngo Weinhold
35050aa61bSIngo Weinholdpublic:
365fb1c6ffSOliver Tappe	inline						BPackageAttributeValue();
37050aa61bSIngo Weinhold
38050aa61bSIngo Weinhold	inline	void				SetTo(int8 value);
39050aa61bSIngo Weinhold	inline	void				SetTo(uint8 value);
40050aa61bSIngo Weinhold	inline	void				SetTo(int16 value);
41050aa61bSIngo Weinhold	inline	void				SetTo(uint16 value);
42050aa61bSIngo Weinhold	inline	void				SetTo(int32 value);
43050aa61bSIngo Weinhold	inline	void				SetTo(uint32 value);
44050aa61bSIngo Weinhold	inline	void				SetTo(int64 value);
45050aa61bSIngo Weinhold	inline	void				SetTo(uint64 value);
46050aa61bSIngo Weinhold	inline	void				SetTo(const char* value);
47050aa61bSIngo Weinhold	inline	void				SetToData(uint64 size, uint64 offset);
48050aa61bSIngo Weinhold	inline	void				SetToData(uint64 size, const void* rawData);
49050aa61bSIngo Weinhold};
50050aa61bSIngo Weinhold
51050aa61bSIngo Weinhold
525fb1c6ffSOliver TappeBPackageAttributeValue::BPackageAttributeValue()
53050aa61bSIngo Weinhold	:
54050aa61bSIngo Weinhold	type(B_HPKG_ATTRIBUTE_TYPE_INVALID)
55050aa61bSIngo Weinhold{
56050aa61bSIngo Weinhold}
57050aa61bSIngo Weinhold
58050aa61bSIngo Weinhold
59050aa61bSIngo Weinholdvoid
605fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(int8 value)
61050aa61bSIngo Weinhold{
62050aa61bSIngo Weinhold	signedInt = value;
63050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
64050aa61bSIngo Weinhold}
65050aa61bSIngo Weinhold
66050aa61bSIngo Weinhold
67050aa61bSIngo Weinholdvoid
685fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(uint8 value)
69050aa61bSIngo Weinhold{
70050aa61bSIngo Weinhold	unsignedInt = value;
71050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
72050aa61bSIngo Weinhold}
73050aa61bSIngo Weinhold
74050aa61bSIngo Weinhold
75050aa61bSIngo Weinholdvoid
765fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(int16 value)
77050aa61bSIngo Weinhold{
78050aa61bSIngo Weinhold	signedInt = value;
79050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
80050aa61bSIngo Weinhold}
81050aa61bSIngo Weinhold
82050aa61bSIngo Weinhold
83050aa61bSIngo Weinholdvoid
845fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(uint16 value)
85050aa61bSIngo Weinhold{
86050aa61bSIngo Weinhold	unsignedInt = value;
87050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
88050aa61bSIngo Weinhold}
89050aa61bSIngo Weinhold
90050aa61bSIngo Weinhold
91050aa61bSIngo Weinholdvoid
925fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(int32 value)
93050aa61bSIngo Weinhold{
94050aa61bSIngo Weinhold	signedInt = value;
95050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
96050aa61bSIngo Weinhold}
97050aa61bSIngo Weinhold
98050aa61bSIngo Weinhold
99050aa61bSIngo Weinholdvoid
1005fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(uint32 value)
101050aa61bSIngo Weinhold{
102050aa61bSIngo Weinhold	unsignedInt = value;
103050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
104050aa61bSIngo Weinhold}
105050aa61bSIngo Weinhold
106050aa61bSIngo Weinhold
107050aa61bSIngo Weinholdvoid
1085fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(int64 value)
109050aa61bSIngo Weinhold{
110050aa61bSIngo Weinhold	signedInt = value;
111050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_INT;
112050aa61bSIngo Weinhold}
113050aa61bSIngo Weinhold
114050aa61bSIngo Weinhold
115050aa61bSIngo Weinholdvoid
1165fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(uint64 value)
117050aa61bSIngo Weinhold{
118050aa61bSIngo Weinhold	unsignedInt = value;
119050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_UINT;
120050aa61bSIngo Weinhold}
121050aa61bSIngo Weinhold
122050aa61bSIngo Weinhold
123050aa61bSIngo Weinholdvoid
1245fb1c6ffSOliver TappeBPackageAttributeValue::SetTo(const char* value)
125050aa61bSIngo Weinhold{
126050aa61bSIngo Weinhold	string = value;
127050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_STRING;
128050aa61bSIngo Weinhold}
129050aa61bSIngo Weinhold
130050aa61bSIngo Weinhold
131050aa61bSIngo Weinholdvoid
1325fb1c6ffSOliver TappeBPackageAttributeValue::SetToData(uint64 size, uint64 offset)
133050aa61bSIngo Weinhold{
134050aa61bSIngo Weinhold	data.size = size;
135050aa61bSIngo Weinhold	data.offset = offset;
136050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_RAW;
137050aa61bSIngo Weinhold	encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP;
138050aa61bSIngo Weinhold}
139050aa61bSIngo Weinhold
140050aa61bSIngo Weinhold
141050aa61bSIngo Weinholdvoid
1425fb1c6ffSOliver TappeBPackageAttributeValue::SetToData(uint64 size, const void* rawData)
143050aa61bSIngo Weinhold{
144050aa61bSIngo Weinhold	data.size = size;
145050aa61bSIngo Weinhold	if (size > 0)
146050aa61bSIngo Weinhold		memcpy(data.raw, rawData, size);
147050aa61bSIngo Weinhold	type = B_HPKG_ATTRIBUTE_TYPE_RAW;
148050aa61bSIngo Weinhold	encoding = B_HPKG_ATTRIBUTE_ENCODING_RAW_INLINE;
149050aa61bSIngo Weinhold}
150050aa61bSIngo Weinhold
151050aa61bSIngo Weinhold
1525fb1c6ffSOliver Tappe}	// namespace BHPKG
1530d6b3b20SOliver Tappe
1540d6b3b20SOliver Tappe}	// namespace BPackageKit
1550d6b3b20SOliver Tappe
1560d6b3b20SOliver Tappe
1575fb1c6ffSOliver Tappe#endif	// _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
158