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 #include <package/PackageInfo.h> 11 12 13 namespace BPackageKit { 14 15 16 BPackageResolvable::BPackageResolvable() 17 { 18 } 19 20 21 BPackageResolvable::BPackageResolvable(const BPackageResolvableData& data) 22 : 23 fName(data.name), 24 fVersion(data.version), 25 fCompatibleVersion(data.compatibleVersion) 26 { 27 } 28 29 30 BPackageResolvable::BPackageResolvable(const BString& name, 31 const BPackageVersion& version, const BPackageVersion& compatibleVersion) 32 : 33 fName(name), 34 fVersion(version), 35 fCompatibleVersion(compatibleVersion) 36 { 37 fName.ToLower(); 38 } 39 40 41 status_t 42 BPackageResolvable::InitCheck() const 43 { 44 return fName.Length() > 0 ? B_OK : B_NO_INIT; 45 } 46 47 48 const BString& 49 BPackageResolvable::Name() const 50 { 51 return fName; 52 } 53 54 55 const BPackageVersion& 56 BPackageResolvable::Version() const 57 { 58 return fVersion; 59 } 60 61 62 const BPackageVersion& 63 BPackageResolvable::CompatibleVersion() const 64 { 65 return fCompatibleVersion; 66 } 67 68 69 BString 70 BPackageResolvable::ToString() const 71 { 72 // the type is part of the name 73 BString string = fName; 74 75 if (fVersion.InitCheck() == B_OK) 76 string << '=' << fVersion.ToString(); 77 78 if (fCompatibleVersion.InitCheck() == B_OK) 79 string << " compat>=" << fCompatibleVersion.ToString(); 80 81 return string; 82 } 83 84 85 status_t 86 BPackageResolvable::SetToString(const BString& expressionString) 87 { 88 fName.Truncate(0); 89 fVersion.Clear(); 90 fCompatibleVersion.Clear(); 91 92 return BPackageInfo::ParseResolvableString(expressionString, 93 *this); 94 } 95 96 97 void 98 BPackageResolvable::SetTo(const BString& name, const BPackageVersion& version, 99 const BPackageVersion& compatibleVersion) 100 { 101 fName = name; 102 fVersion = version; 103 fCompatibleVersion = compatibleVersion; 104 105 fName.ToLower(); 106 } 107 108 109 void 110 BPackageResolvable::Clear() 111 { 112 fName.Truncate(0); 113 fVersion.Clear(); 114 fCompatibleVersion.Clear(); 115 } 116 117 118 } // namespace BPackageKit 119