xref: /haiku/src/kits/package/PackageResolvable.cpp (revision 8b5f785b6a4baacea04971694acdb20c6a1b7cd3)
13aeae97fSOliver Tappe /*
23aeae97fSOliver Tappe  * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
33aeae97fSOliver Tappe  * Distributed under the terms of the MIT License.
43aeae97fSOliver Tappe  */
53aeae97fSOliver Tappe 
63aeae97fSOliver Tappe 
73aeae97fSOliver Tappe #include <package/PackageResolvable.h>
83aeae97fSOliver Tappe 
90d68f6afSOliver Tappe #include <package/hpkg/PackageInfoAttributeValue.h>
10*8b5f785bSX512 #include <package/PackageInfo.h>
110d68f6afSOliver Tappe 
123aeae97fSOliver Tappe 
133aeae97fSOliver Tappe namespace BPackageKit {
143aeae97fSOliver Tappe 
153aeae97fSOliver Tappe 
BPackageResolvable()163aeae97fSOliver Tappe BPackageResolvable::BPackageResolvable()
173aeae97fSOliver Tappe {
183aeae97fSOliver Tappe }
193aeae97fSOliver Tappe 
203aeae97fSOliver Tappe 
BPackageResolvable(const BPackageResolvableData & data)210d68f6afSOliver Tappe BPackageResolvable::BPackageResolvable(const BPackageResolvableData& data)
220d68f6afSOliver Tappe 	:
230d68f6afSOliver Tappe 	fName(data.name),
24c2f56ca0SIngo Weinhold 	fVersion(data.version),
25c2f56ca0SIngo Weinhold 	fCompatibleVersion(data.compatibleVersion)
260d68f6afSOliver Tappe {
270d68f6afSOliver Tappe }
280d68f6afSOliver Tappe 
290d68f6afSOliver Tappe 
BPackageResolvable(const BString & name,const BPackageVersion & version,const BPackageVersion & compatibleVersion)303aeae97fSOliver Tappe BPackageResolvable::BPackageResolvable(const BString& name,
31df295396SIngo Weinhold 	const BPackageVersion& version, const BPackageVersion& compatibleVersion)
323aeae97fSOliver Tappe 	:
333aeae97fSOliver Tappe 	fName(name),
34c2f56ca0SIngo Weinhold 	fVersion(version),
35c2f56ca0SIngo Weinhold 	fCompatibleVersion(compatibleVersion)
363aeae97fSOliver Tappe {
37437651ffSIngo Weinhold 	fName.ToLower();
383aeae97fSOliver Tappe }
393aeae97fSOliver Tappe 
403aeae97fSOliver Tappe 
413aeae97fSOliver Tappe status_t
InitCheck() const423aeae97fSOliver Tappe BPackageResolvable::InitCheck() const
433aeae97fSOliver Tappe {
443aeae97fSOliver Tappe 	return fName.Length() > 0 ? B_OK : B_NO_INIT;
453aeae97fSOliver Tappe }
463aeae97fSOliver Tappe 
473aeae97fSOliver Tappe 
482f7778f3SOliver Tappe const BString&
Name() const492f7778f3SOliver Tappe BPackageResolvable::Name() const
502f7778f3SOliver Tappe {
512f7778f3SOliver Tappe 	return fName;
522f7778f3SOliver Tappe }
532f7778f3SOliver Tappe 
542f7778f3SOliver Tappe 
552f7778f3SOliver Tappe const BPackageVersion&
Version() const562f7778f3SOliver Tappe BPackageResolvable::Version() const
572f7778f3SOliver Tappe {
582f7778f3SOliver Tappe 	return fVersion;
592f7778f3SOliver Tappe }
602f7778f3SOliver Tappe 
612f7778f3SOliver Tappe 
62c2f56ca0SIngo Weinhold const BPackageVersion&
CompatibleVersion() const63c2f56ca0SIngo Weinhold BPackageResolvable::CompatibleVersion() const
64c2f56ca0SIngo Weinhold {
65c2f56ca0SIngo Weinhold 	return fCompatibleVersion;
66c2f56ca0SIngo Weinhold }
67c2f56ca0SIngo Weinhold 
68c2f56ca0SIngo Weinhold 
692f7778f3SOliver Tappe BString
ToString() const70ceb993abSOliver Tappe BPackageResolvable::ToString() const
713aeae97fSOliver Tappe {
723aeae97fSOliver Tappe 	// the type is part of the name
732f7778f3SOliver Tappe 	BString string = fName;
743aeae97fSOliver Tappe 
752f7778f3SOliver Tappe 	if (fVersion.InitCheck() == B_OK)
76ceb993abSOliver Tappe 		string << '=' << fVersion.ToString();
772f7778f3SOliver Tappe 
78c2f56ca0SIngo Weinhold 	if (fCompatibleVersion.InitCheck() == B_OK)
79c2f56ca0SIngo Weinhold 		string << " compat>=" << fCompatibleVersion.ToString();
80c2f56ca0SIngo Weinhold 
812f7778f3SOliver Tappe 	return string;
823aeae97fSOliver Tappe }
833aeae97fSOliver Tappe 
843aeae97fSOliver Tappe 
85*8b5f785bSX512 status_t
SetToString(const BString & expressionString)86*8b5f785bSX512 BPackageResolvable::SetToString(const BString& expressionString)
87*8b5f785bSX512 {
88*8b5f785bSX512 	fName.Truncate(0);
89*8b5f785bSX512 	fVersion.Clear();
90*8b5f785bSX512 	fCompatibleVersion.Clear();
91*8b5f785bSX512 
92*8b5f785bSX512 	return BPackageInfo::ParseResolvableString(expressionString,
93*8b5f785bSX512 		*this);
94*8b5f785bSX512 }
95*8b5f785bSX512 
96*8b5f785bSX512 
973aeae97fSOliver Tappe void
SetTo(const BString & name,const BPackageVersion & version,const BPackageVersion & compatibleVersion)98df295396SIngo Weinhold BPackageResolvable::SetTo(const BString& name, const BPackageVersion& version,
99df295396SIngo Weinhold 	const BPackageVersion& compatibleVersion)
1003aeae97fSOliver Tappe {
1013aeae97fSOliver Tappe 	fName = name;
1023aeae97fSOliver Tappe 	fVersion = version;
103c2f56ca0SIngo Weinhold 	fCompatibleVersion = compatibleVersion;
104437651ffSIngo Weinhold 
105437651ffSIngo Weinhold 	fName.ToLower();
1063aeae97fSOliver Tappe }
1073aeae97fSOliver Tappe 
1083aeae97fSOliver Tappe 
1093aeae97fSOliver Tappe void
Clear()1103aeae97fSOliver Tappe BPackageResolvable::Clear()
1113aeae97fSOliver Tappe {
1123aeae97fSOliver Tappe 	fName.Truncate(0);
1133aeae97fSOliver Tappe 	fVersion.Clear();
114c2f56ca0SIngo Weinhold 	fCompatibleVersion.Clear();
1153aeae97fSOliver Tappe }
1163aeae97fSOliver Tappe 
1173aeae97fSOliver Tappe 
1183aeae97fSOliver Tappe }	// namespace BPackageKit
119