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