1 /* 2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <package/PackageResolvableExpression.h> 8 9 #include <package/hpkg/PackageInfoAttributeValue.h> 10 11 12 namespace BPackageKit { 13 14 15 const char* 16 BPackageResolvableExpression 17 ::kOperatorNames[B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT] = { 18 "<", 19 "<=", 20 "==", 21 "!=", 22 ">=", 23 ">", 24 }; 25 26 27 BPackageResolvableExpression::BPackageResolvableExpression() 28 : 29 fOperator(B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT) 30 { 31 } 32 33 34 BPackageResolvableExpression::BPackageResolvableExpression( 35 const BPackageResolvableExpressionData& data) 36 : 37 fName(data.name), 38 fOperator(data.op), 39 fVersion(data.version) 40 { 41 } 42 43 44 BPackageResolvableExpression::BPackageResolvableExpression(const BString& name, 45 BPackageResolvableOperator _operator, const BPackageVersion& version) 46 : 47 fName(name), 48 fOperator(_operator), 49 fVersion(version) 50 { 51 } 52 53 54 status_t 55 BPackageResolvableExpression::InitCheck() const 56 { 57 if (fName.Length() == 0) 58 return B_NO_INIT; 59 60 // either both or none of operator and version must be set 61 if ((fOperator >= 0 && fOperator < B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT) 62 != (fVersion.InitCheck() == B_OK)) 63 return B_NO_INIT; 64 65 return B_OK; 66 } 67 68 69 const BString& 70 BPackageResolvableExpression::Name() const 71 { 72 return fName; 73 } 74 75 76 BPackageResolvableOperator 77 BPackageResolvableExpression::Operator() const 78 { 79 return fOperator; 80 } 81 82 83 const BPackageVersion& 84 BPackageResolvableExpression::Version() const 85 { 86 return fVersion; 87 } 88 89 90 BString 91 BPackageResolvableExpression::ToString() const 92 { 93 BString string = fName; 94 95 if (fVersion.InitCheck() == B_OK) 96 string << fOperator << fVersion.ToString(); 97 98 return string; 99 } 100 101 102 void 103 BPackageResolvableExpression::SetTo(const BString& name, 104 BPackageResolvableOperator _operator, const BPackageVersion& version) 105 { 106 fName = name; 107 fOperator = _operator; 108 fVersion = version; 109 } 110 111 112 void 113 BPackageResolvableExpression::Clear() 114 { 115 fName.Truncate(0); 116 fOperator = B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT; 117 fVersion.Clear(); 118 } 119 120 121 } // namespace BPackageKit 122