[haiku-commits] r40353 - in haiku/trunk: headers/os/package src/kits/package

Author: zooey
Date: 2011-02-04 18:34:19 +0100 (Fri, 04 Feb 2011)
New Revision: 40353
Changeset: http://dev.haiku-os.org/changeset/40353

Modified:
   haiku/trunk/headers/os/package/PackageResolvableExpression.h
   haiku/trunk/src/kits/package/PackageInfo.cpp
   haiku/trunk/src/kits/package/PackageResolvableExpression.cpp
Log:
* made resolvable expression operator an enum instead of a string
* fixed a couple of copy'n'paste bugs during parsing of resolvable
  expression lists (they were all added as 'requires')


Modified: haiku/trunk/headers/os/package/PackageResolvableExpression.h
===================================================================
--- haiku/trunk/headers/os/package/PackageResolvableExpression.h        
2011-02-03 20:37:41 UTC (rev 40352)
+++ haiku/trunk/headers/os/package/PackageResolvableExpression.h        
2011-02-04 17:34:19 UTC (rev 40353)
@@ -8,6 +8,7 @@
 
 #include <String.h>
 
+#include <package/PackageResolvableOperator.h>
 #include <package/PackageVersion.h>
 
 
@@ -34,27 +35,32 @@
                                                                
BPackageResolvableExpression();
                                                                
BPackageResolvableExpression(
                                                                        const 
BString& name,
-                                                                       const 
BString& _operator = "",
+                                                                       
BPackageResolvableOperator _op
+                                                                               
= B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT,
                                                                        const 
BPackageVersion& version
                                                                                
= BPackageVersion());
 
                        status_t                        InitCheck() const;
 
                        const BString&          Name() const;
-                       const BString&          Operator() const;
+                       BPackageResolvableOperator      Operator() const;
                        const BPackageVersion& Version() const;
 
                        BString                         AsString() const;
 
                        void                            SetTo(const BString& 
name,
-                                                                       const 
BString& _operator = "",
+                                                                       
BPackageResolvableOperator _op
+                                                                               
= B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT,
                                                                        const 
BPackageVersion& version
                                                                                
= BPackageVersion());
                        void                            Clear();
 
+public:
+       static  const char*                     kOperatorNames[];
+
 private:
                        BString                         fName;
-                       BString                         fOperator;
+                       BPackageResolvableOperator      fOperator;
                        BPackageVersion         fVersion;
 };
 

Modified: haiku/trunk/src/kits/package/PackageInfo.cpp
===================================================================
--- haiku/trunk/src/kits/package/PackageInfo.cpp        2011-02-03 20:37:41 UTC 
(rev 40352)
+++ haiku/trunk/src/kits/package/PackageInfo.cpp        2011-02-04 17:34:19 UTC 
(rev 40353)
@@ -506,6 +506,7 @@
                if (op.type == TOKEN_OPERATOR_LESS
                        || op.type == TOKEN_OPERATOR_LESS_EQUAL
                        || op.type == TOKEN_OPERATOR_EQUAL
+                       || op.type == TOKEN_OPERATOR_NOT_EQUAL
                        || op.type == TOKEN_OPERATOR_GREATER_EQUAL
                        || op.type == TOKEN_OPERATOR_GREATER)
                        _ParseVersionValue(&version, true);
@@ -513,11 +514,15 @@
                        _RewindTo(op);
                else {
                        throw ParseError(
-                               "expected '<', '<=', '==', '>=', '>', comma or 
']'", op.pos);
+                               "expected '<', '<=', '==', '!=', '>=', '>', 
comma or ']'",
+                               op.pos);
                }
 
-               value->AddItem(
-                       new BPackageResolvableExpression(name.text, op.text, 
version));
+               BPackageResolvableOperator resolvableOperator
+                       = (BPackageResolvableOperator)(op.type - 
TOKEN_OPERATOR_LESS);
+
+               value->AddItem(new BPackageResolvableExpression(name.text,
+                       resolvableOperator, version));
        }
 }
 
@@ -683,7 +688,7 @@
                        _ParseResolvableExprList(&supplementsList);
                        int count = supplementsList.CountItems();
                        for (int i = 0; i < count; ++i)
-                               
packageInfo->AddRequires(*(supplementsList.ItemAt(i)));
+                               
packageInfo->AddSupplements(*(supplementsList.ItemAt(i)));
                        seen[B_PACKAGE_INFO_SUPPLEMENTS] = true;
                } else if (t.text.ICompare(names[B_PACKAGE_INFO_CONFLICTS]) == 
0) {
                        if (seen[B_PACKAGE_INFO_CONFLICTS]) {
@@ -696,7 +701,7 @@
                        _ParseResolvableExprList(&conflictsList);
                        int count = conflictsList.CountItems();
                        for (int i = 0; i < count; ++i)
-                               
packageInfo->AddRequires(*(conflictsList.ItemAt(i)));
+                               
packageInfo->AddConflicts(*(conflictsList.ItemAt(i)));
                        seen[B_PACKAGE_INFO_CONFLICTS] = true;
                } else if (t.text.ICompare(names[B_PACKAGE_INFO_FRESHENS]) == 
0) {
                        if (seen[B_PACKAGE_INFO_FRESHENS]) {
@@ -709,7 +714,7 @@
                        _ParseResolvableExprList(&freshensList);
                        int count = freshensList.CountItems();
                        for (int i = 0; i < count; ++i)
-                               
packageInfo->AddRequires(*(freshensList.ItemAt(i)));
+                               
packageInfo->AddFreshens(*(freshensList.ItemAt(i)));
                        seen[B_PACKAGE_INFO_FRESHENS] = true;
                } else if (t.text.ICompare(names[B_PACKAGE_INFO_REPLACES]) == 
0) {
                        if (seen[B_PACKAGE_INFO_REPLACES]) {
@@ -722,7 +727,7 @@
                        _ParseStringList(&replacesList, false);
                        int count = replacesList.CountItems();
                        for (int i = 0; i < count; ++i)
-                               
packageInfo->AddRequires(*(replacesList.ItemAt(i)));
+                               
packageInfo->AddReplaces(*(replacesList.ItemAt(i)));
                        seen[B_PACKAGE_INFO_REPLACES] = true;
                }
        }
@@ -749,10 +754,10 @@
        "licenses",
        "provides",
        "requires",
+       "supplements",
        "conflicts",
-       "supplements",
+       "freshens",
        "replaces",
-       "freshens",
 };
 
 

Modified: haiku/trunk/src/kits/package/PackageResolvableExpression.cpp
===================================================================
--- haiku/trunk/src/kits/package/PackageResolvableExpression.cpp        
2011-02-03 20:37:41 UTC (rev 40352)
+++ haiku/trunk/src/kits/package/PackageResolvableExpression.cpp        
2011-02-04 17:34:19 UTC (rev 40353)
@@ -10,13 +10,27 @@
 namespace BPackageKit {
 
 
+const char*
+BPackageResolvableExpression
+::kOperatorNames[B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT] = {
+       "<",
+       "<=",
+       "==",
+       "!=",
+       ">=",
+       ">",
+};
+
+
 BPackageResolvableExpression::BPackageResolvableExpression()
+       :
+       fOperator(B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT)
 {
 }
 
 
 BPackageResolvableExpression::BPackageResolvableExpression(const BString& name,
-       const BString& _operator, const BPackageVersion& version)
+       BPackageResolvableOperator _operator, const BPackageVersion& version)
        :
        fName(name),
        fOperator(_operator),
@@ -32,12 +46,12 @@
                return B_NO_INIT;
 
        // either both or none of operator and version must be set
-       if (fOperator.Length() == 0 && fVersion.InitCheck() == B_OK)
+       if ((fOperator == B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT
+                       && fVersion.InitCheck() == B_OK)
+               || (fOperator >= 0 && fOperator < 
B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT
+                       && fVersion.InitCheck() != B_OK))
                return B_NO_INIT;
 
-       if (fOperator.Length() > 0 && fVersion.InitCheck() != B_OK)
-               return B_NO_INIT;
-
        return B_OK;
 }
 
@@ -49,7 +63,7 @@
 }
 
 
-const BString&
+BPackageResolvableOperator
 BPackageResolvableExpression::Operator() const
 {
        return fOperator;
@@ -77,7 +91,7 @@
 
 void
 BPackageResolvableExpression::SetTo(const BString& name,
-       const BString& _operator, const BPackageVersion& version)
+       BPackageResolvableOperator _operator, const BPackageVersion& version)
 {
        fName = name;
        fOperator = _operator;
@@ -89,7 +103,7 @@
 BPackageResolvableExpression::Clear()
 {
        fName.Truncate(0);
-       fOperator.Truncate(0);
+       fOperator = B_PACKAGE_RESOLVABLE_OP_ENUM_COUNT;
        fVersion.Clear();
 }
 


Other related posts: