xref: /haiku/headers/os/package/hpkg/PackageInfoAttributeValue.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2009,2011, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _PACKAGE__HPKG__PACKAGE_INFO_ATTRIBUTE_VALUE_H_
6 #define _PACKAGE__HPKG__PACKAGE_INFO_ATTRIBUTE_VALUE_H_
7 
8 
9 #include <SupportDefs.h>
10 
11 #include <package/PackageArchitecture.h>
12 #include <package/PackageInfoAttributes.h>
13 #include <package/PackageResolvableOperator.h>
14 #include <package/PackageResolvableType.h>
15 
16 
17 namespace BPackageKit {
18 
19 namespace BHPKG {
20 
21 
22 struct BPackageVersionData {
23 			const char*			major;
24 			const char*			minor;
25 			const char*			micro;
26 			const char*			preRelease;
27 			uint8				release;
28 };
29 
30 
31 struct BPackageResolvableData {
32 			BPackageResolvableType	type;
33 			const char*			name;
34 			bool				haveVersion;
35 			bool				haveCompatibleVersion;
36 			BPackageVersionData	version;
37 			BPackageVersionData	compatibleVersion;
38 };
39 
40 
41 struct BPackageResolvableExpressionData {
42 			const char*			name;
43 			bool				haveOpAndVersion;
44 			BPackageResolvableOperator	op;
45 			BPackageVersionData	version;
46 };
47 
48 
49 struct BPackageInfoAttributeValue {
50 			union {
51 				uint64			unsignedInt;
52 				const char*		string;
53 				BPackageVersionData version;
54 				BPackageResolvableData resolvable;
55 				BPackageResolvableExpressionData resolvableExpression;
56 			};
57 			BPackageInfoAttributeID	attributeID;
58 
59 public:
60 								BPackageInfoAttributeValue();
61 
62 			void				SetTo(BPackageInfoAttributeID id,
63 									uint8 value);
64 			void				SetTo(BPackageInfoAttributeID id,
65 									const char* value);
66 
67 			void				Clear();
68 };
69 
70 
71 inline
72 BPackageInfoAttributeValue::BPackageInfoAttributeValue()
73 {
74 	Clear();
75 }
76 
77 
78 inline void
79 BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id, uint8 value)
80 {
81 	attributeID = id;
82 	unsignedInt = value;
83 }
84 
85 
86 inline void
87 BPackageInfoAttributeValue::SetTo(BPackageInfoAttributeID id,
88 	const char* value)
89 {
90 	attributeID = id;
91 	string = value;
92 }
93 
94 
95 inline void
96 BPackageInfoAttributeValue::Clear()
97 {
98 	memset(this, 0, sizeof(BPackageInfoAttributeValue));
99 	attributeID = B_PACKAGE_INFO_ENUM_COUNT;
100 }
101 
102 
103 }	// namespace BHPKG
104 
105 }	// namespace BPackageKit
106 
107 
108 #endif	// _PACKAGE__HPKG__PACKAGE_ATTRIBUTE_VALUE_H_
109