Author: rhs
Date: Fri May 24 18:07:02 2013
New Revision: 1486140
URL: http://svn.apache.org/r1486140
Log:
added pn_list_index and pn_list_remove
Modified:
qpid/proton/trunk/proton-c/src/object/object.c
qpid/proton/trunk/proton-c/src/tests/object.c
Modified: qpid/proton/trunk/proton-c/src/object/object.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/object/object.c?rev=1486140&r1=1486139&r2=1486140&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/object/object.c (original)
+++ qpid/proton/trunk/proton-c/src/object/object.c Fri May 24 18:07:02 2013
@@ -174,6 +174,30 @@ int pn_list_add(pn_list_t *list, void *v
return 0;
}
+ssize_t pn_list_index(pn_list_t *list, void *value)
+{
+ for (size_t i = 0; i < list->size; i++) {
+ if (pn_equals(list->elements[i], value)) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+bool pn_list_remove(pn_list_t *list, void *value)
+{
+ assert(list);
+ ssize_t idx = pn_list_index(list, value);
+ if (idx < 0) {
+ return false;
+ } else {
+ pn_list_del(list, idx, 1);
+ }
+
+ return true;
+}
+
void pn_list_del(pn_list_t *list, int index, int n)
{
assert(list);
Modified: qpid/proton/trunk/proton-c/src/tests/object.c
URL:
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/src/tests/object.c?rev=1486140&r1=1486139&r2=1486140&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/src/tests/object.c (original)
+++ qpid/proton/trunk/proton-c/src/tests/object.c Fri May 24 18:07:02 2013
@@ -211,6 +211,49 @@ static void test_list_refcount(size_t ca
pn_decref(four);
}
+static void check_list_index(pn_list_t *list, void *value, ssize_t idx)
+{
+ assert(pn_list_index(list, value) == idx);
+}
+
+static void test_list_index()
+{
+ pn_list_t *l = pn_list(0, 0);
+ void *one = pn_string("one");
+ void *two = pn_string("two");
+ void *three = pn_string("three");
+ void *dup1 = pn_string("dup");
+ void *dup2 = pn_string("dup");
+ void *last = pn_string("last");
+
+ pn_list_add(l, one);
+ pn_list_add(l, two);
+ pn_list_add(l, three);
+ pn_list_add(l, dup1);
+ pn_list_add(l, dup2);
+ pn_list_add(l, last);
+
+ check_list_index(l, one, 0);
+ check_list_index(l, two, 1);
+ check_list_index(l, three, 2);
+ check_list_index(l, dup1, 3);
+ check_list_index(l, dup2, 3);
+ check_list_index(l, last, 5);
+
+ void *nonexistent = pn_string("nonexistent");
+
+ check_list_index(l, nonexistent, -1);
+
+ pn_free(l);
+ pn_free(one);
+ pn_free(two);
+ pn_free(three);
+ pn_free(dup1);
+ pn_free(dup2);
+ pn_free(last);
+ pn_free(nonexistent);
+}
+
static void test_map()
{
void *one = pn_new(0, NULL);
@@ -422,6 +465,8 @@ int main(int argc, char **argv)
test_list_refcount(i);
}
+ test_list_index();
+
test_map();
test_hash();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]