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 fName.ToLower(); 42 } 43 44 45 BPackageResolvableExpression::BPackageResolvableExpression(const BString& name, 46 BPackageResolvableOperator _operator, const BPackageVersion& version) 47 : 48 fName(name), 49 fOperator(_operator), 50 fVersion(version) 51 { 52 fName.ToLower(); 53 } 54 55 56 status_t 57 BPackageResolvableExpression::InitCheck() const 58 { 59 if (fName.Length() == 0) 60 return B_NO_INIT; 61 62 // either both or none of operator and version must be set 63 if ((fOperator >= 0 && fOperator < B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT) 64 != (fVersion.InitCheck() == B_OK)) 65 return B_NO_INIT; 66 67 return B_OK; 68 } 69 70 71 const BString& 72 BPackageResolvableExpression::Name() const 73 { 74 return fName; 75 } 76 77 78 BPackageResolvableOperator 79 BPackageResolvableExpression::Operator() const 80 { 81 return fOperator; 82 } 83 84 85 const BPackageVersion& 86 BPackageResolvableExpression::Version() const 87 { 88 return fVersion; 89 } 90 91 92 BString 93 BPackageResolvableExpression::ToString() const 94 { 95 BString string = fName; 96 97 if (fVersion.InitCheck() == B_OK) 98 string << fOperator << fVersion.ToString(); 99 100 return string; 101 } 102 103 104 void 105 BPackageResolvableExpression::SetTo(const BString& name, 106 BPackageResolvableOperator _operator, const BPackageVersion& version) 107 { 108 fName = name; 109 fOperator = _operator; 110 fVersion = version; 111 112 fName.ToLower(); 113 } 114 115 116 void 117 BPackageResolvableExpression::Clear() 118 { 119 fName.Truncate(0); 120 fOperator = B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT; 121 fVersion.Clear(); 122 } 123 124 125 } // namespace BPackageKit 126