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 { 38 } 39 40 41 BPackageResolvable::BPackageResolvable(const BString& name, 42 BPackageResolvableType type, const BPackageVersion& version) 43 : 44 fName(name), 45 fType(type), 46 fVersion(version) 47 { 48 } 49 50 51 status_t 52 BPackageResolvable::InitCheck() const 53 { 54 return fName.Length() > 0 ? B_OK : B_NO_INIT; 55 } 56 57 58 const BString& 59 BPackageResolvable::Name() const 60 { 61 return fName; 62 } 63 64 65 BPackageResolvableType 66 BPackageResolvable::Type() const 67 { 68 return fType; 69 } 70 71 72 const BPackageVersion& 73 BPackageResolvable::Version() const 74 { 75 return fVersion; 76 } 77 78 79 BString 80 BPackageResolvable::ToString() const 81 { 82 // the type is part of the name 83 BString string = fName; 84 85 if (fVersion.InitCheck() == B_OK) 86 string << '=' << fVersion.ToString(); 87 88 return string; 89 } 90 91 92 void 93 BPackageResolvable::SetTo(const BString& name, BPackageResolvableType type, 94 const BPackageVersion& version) 95 { 96 fName = name; 97 fType = type; 98 fVersion = version; 99 } 100 101 102 void 103 BPackageResolvable::Clear() 104 { 105 fName.Truncate(0); 106 fVersion.Clear(); 107 } 108 109 110 } // namespace BPackageKit 111