Author: sayer
Date: 2009-02-12 21:58:40 +0100 (Thu, 12 Feb 2009)
New Revision: 1270
Modified:
trunk/core/AmArg.cpp
trunk/core/AmArg.h
Log:
equality check for AmArg
Modified: trunk/core/AmArg.cpp
===================================================================
--- trunk/core/AmArg.cpp 2009-02-12 13:18:38 UTC (rev 1269)
+++ trunk/core/AmArg.cpp 2009-02-12 20:58:40 UTC (rev 1270)
@@ -257,6 +257,24 @@
return (*v_struct)[key];
}
+bool operator==(const AmArg& lhs, const AmArg& rhs) {
+ if (lhs.type != rhs.type)
+ return false;
+
+ switch(lhs.type){
+ case AmArg::Int: { return lhs.v_int == rhs.v_int; } break;
+ case AmArg::Double: { return lhs.v_double == rhs.v_double; } break;
+ case AmArg::CStr: { return !strcmp(lhs.v_cstr,rhs.v_cstr); } break;
+ case AmArg::AObject:{ return lhs.v_obj == rhs.v_obj; } break;
+ case AmArg::Array: { return lhs.v_array == rhs.v_array; } break;
+ case AmArg::Struct: { return lhs.v_struct == rhs.v_struct; } break;
+ case AmArg::Blob: { return (lhs.v_blob->len == rhs.v_blob->len) &&
+ !memcmp(lhs.v_blob->data, rhs.v_blob->data, lhs.v_blob->len); } break;
+ case AmArg::Undef: return true;
+ default: assert(0);
+ }
+}
+
bool AmArg::hasMember(const char* name) const {
return type == Struct && v_struct->find(name) != v_struct->end();
}
Modified: trunk/core/AmArg.h
===================================================================
--- trunk/core/AmArg.h 2009-02-12 13:18:38 UTC (rev 1269)
+++ trunk/core/AmArg.h 2009-02-12 20:58:40 UTC (rev 1270)
@@ -216,6 +216,7 @@
const char* asCStr() const { return v_cstr; }
ArgObject* asObject() const { return v_obj; }
ArgBlob* asBlob() const { return v_blob; }
+ ValueStruct* asStruct() const { return v_struct; }
vector<string> asStringVector() const;
vector<int> asIntVector() const;
@@ -279,7 +280,11 @@
void assertArrayFmt(const char* format) const;
void clear();
+ friend bool operator==(const AmArg& lhs, const AmArg& rhs);
};
+// equality
+bool operator==(const AmArg& lhs, const AmArg& rhs);
+
#endif
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev