xref: /haiku/src/kits/package/PackageResolvable.cpp (revision 25a7b01d15612846f332751841da3579db313082)
1 /*
2  * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <package/PackageResolvable.h>
8 
9 #include <package/hpkg/PackageInfoAttributeValue.h>
10 
11 
12 namespace BPackageKit {
13 
14 
15 const char*
16 BPackageResolvable::kTypeNames[B_PACKAGE_RESOLVABLE_TYPE_ENUM_COUNT] = {
17 	"",
18 	"lib",
19 	"cmd",
20 	"app",
21 	"add_on",
22 };
23 
24 
25 BPackageResolvable::BPackageResolvable()
26 	:
27 	fType(B_PACKAGE_RESOLVABLE_TYPE_DEFAULT)
28 {
29 }
30 
31 
32 BPackageResolvable::BPackageResolvable(const BPackageResolvableData& data)
33 	:
34 	fName(data.name),
35 	fType(data.type),
36 	fVersion(data.version),
37 	fCompatibleVersion(data.compatibleVersion)
38 {
39 }
40 
41 
42 BPackageResolvable::BPackageResolvable(const BString& name,
43 	BPackageResolvableType type, const BPackageVersion& version,
44 	const BPackageVersion& compatibleVersion)
45 	:
46 	fName(name),
47 	fType(type),
48 	fVersion(version),
49 	fCompatibleVersion(compatibleVersion)
50 {
51 	fName.ToLower();
52 }
53 
54 
55 status_t
56 BPackageResolvable::InitCheck() const
57 {
58 	return fName.Length() > 0 ? B_OK : B_NO_INIT;
59 }
60 
61 
62 const BString&
63 BPackageResolvable::Name() const
64 {
65 	return fName;
66 }
67 
68 
69 BPackageResolvableType
70 BPackageResolvable::Type() const
71 {
72 	return fType;
73 }
74 
75 
76 const BPackageVersion&
77 BPackageResolvable::Version() const
78 {
79 	return fVersion;
80 }
81 
82 
83 const BPackageVersion&
84 BPackageResolvable::CompatibleVersion() const
85 {
86 	return fCompatibleVersion;
87 }
88 
89 
90 BString
91 BPackageResolvable::ToString() const
92 {
93 	// the type is part of the name
94 	BString string = fName;
95 
96 	if (fVersion.InitCheck() == B_OK)
97 		string << '=' << fVersion.ToString();
98 
99 	if (fCompatibleVersion.InitCheck() == B_OK)
100 		string << " compat>=" << fCompatibleVersion.ToString();
101 
102 	return string;
103 }
104 
105 
106 void
107 BPackageResolvable::SetTo(const BString& name, BPackageResolvableType type,
108 	const BPackageVersion& version, const BPackageVersion& compatibleVersion)
109 {
110 	fName = name;
111 	fType = type;
112 	fVersion = version;
113 	fCompatibleVersion = compatibleVersion;
114 
115 	fName.ToLower();
116 }
117 
118 
119 void
120 BPackageResolvable::Clear()
121 {
122 	fName.Truncate(0);
123 	fVersion.Clear();
124 	fCompatibleVersion.Clear();
125 }
126 
127 
128 }	// namespace BPackageKit
129