From: Sebastian Harl Date: Sat, 25 Oct 2014 19:43:28 +0000 (+0200) Subject: store: Added support for ALL matchers. X-Git-Tag: sysdb-0.6.0~58 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=99d12b86d046b983801fd9381d5b9cea0200a64c store: Added support for ALL matchers. Similar to ANY, this matcher iterators over objects. It matches, if *all* of those objects match another matcher. --- diff --git a/src/core/store-private.h b/src/core/store-private.h index 4c38f15..a0f4ec6 100644 --- a/src/core/store-private.h +++ b/src/core/store-private.h @@ -136,6 +136,7 @@ enum { MATCHER_AND, MATCHER_NOT, MATCHER_ANY, + MATCHER_ALL, MATCHER_LT, MATCHER_LE, MATCHER_EQ, @@ -155,6 +156,7 @@ enum { : ((t) == MATCHER_NOT) ? "NOT" \ : ((t) == MATCHER_NAME) ? "NAME" \ : ((t) == MATCHER_ANY) ? "ANY" \ + : ((t) == MATCHER_ALL) ? "ALL" \ : ((t) == MATCHER_LT) ? "<" \ : ((t) == MATCHER_LE) ? "<=" \ : ((t) == MATCHER_EQ) ? "=" \ diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 11d85fe..513b6a6 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -114,9 +114,9 @@ match_iter(sdb_store_matcher_t *m, sdb_store_obj_t *obj, { sdb_avltree_iter_t *iter = NULL; int status; - int all = 0; + int all = (int)(m->type == MATCHER_ALL); - assert(m->type == MATCHER_ANY); + assert((m->type == MATCHER_ANY) || (m->type == MATCHER_ALL)); /* TODO: support all object types */ if (obj->type != SDB_HOST) @@ -361,6 +361,7 @@ matchers[] = { match_logical, match_unary, match_iter, + match_iter, match_lt, match_le, match_eq, @@ -529,7 +530,17 @@ sdb_store_any_matcher(int type, sdb_store_matcher_t *m) return NULL; return M(sdb_object_create("any-matcher", iter_type, MATCHER_ANY, type, m)); -} /* sdb_store_iter_matcher */ +} /* sdb_store_any_matcher */ + +sdb_store_matcher_t * +sdb_store_all_matcher(int type, sdb_store_matcher_t *m) +{ + if ((type != SDB_SERVICE) && (type != SDB_METRIC) + && (type != SDB_ATTRIBUTE)) + return NULL; + return M(sdb_object_create("all-matcher", iter_type, + MATCHER_ALL, type, m)); +} /* sdb_store_all_matcher */ sdb_store_matcher_t * sdb_store_lt_matcher(sdb_store_expr_t *left, sdb_store_expr_t *right) diff --git a/src/include/core/store.h b/src/include/core/store.h index ed445c3..9ba19b8 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -388,6 +388,14 @@ sdb_store_isnnull_matcher(sdb_store_expr_t *expr); sdb_store_matcher_t * sdb_store_any_matcher(int type, sdb_store_matcher_t *m); +/* + * sdb_store_all_matcher: + * Creates a matcher iterating over objects of the specified type. It matches + * if *all* of those objects match 'm'. + */ +sdb_store_matcher_t * +sdb_store_all_matcher(int type, sdb_store_matcher_t *m); + /* * sdb_store_lt_matcher, sdb_store_le_matcher, sdb_store_eq_matcher, * sdb_store_ge_matcher, sdb_store_gt_matcher: