summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c659b3f)
raw | patch | inline | side by side (parent: c659b3f)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Jun 2014 15:46:46 +0000 (17:46 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Jun 2014 15:46:46 +0000 (17:46 +0200) |
Also, reshuffled some functions a bit to have a more natural order now that
the matcher approach is greatly simplified.
the matcher approach is greatly simplified.
src/core/store-private.h | patch | blob | history | |
src/core/store_lookup.c | patch | blob | history |
index f33768579575524857b9991376b55c2262364439..0db46f84b5d6c28393d8a7d49b8e8dd453471335 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
};
#define M(m) ((sdb_store_matcher_t *)(m))
-/* logical infix operator matcher */
+/* infix operator matcher */
typedef struct {
sdb_store_matcher_t super;
} op_matcher_t;
#define OP_M(m) ((op_matcher_t *)(m))
-/* logical unary operator matcher */
+/* unary operator matcher */
typedef struct {
sdb_store_matcher_t super;
index b5c936aae355419eadf52dfd7e1c99110e38701f..52739a6a836155fd3ba465a688cb5db222f4aa91 100644 (file)
--- a/src/core/store_lookup.c
+++ b/src/core/store_lookup.c
* matcher implementations
*/
-static int
-match_logical(sdb_store_matcher_t *m, sdb_store_base_t *obj);
-static int
-match_unary(sdb_store_matcher_t *m, sdb_store_base_t *obj);
-
-/* specific matchers */
-
static int
match_string(string_matcher_t *m, const char *name)
{
return 1;
} /* match_string */
-static char *
-string_tostring(string_matcher_t *m, char *buf, size_t buflen)
+static int
+match_logical(sdb_store_matcher_t *m, sdb_store_base_t *obj)
{
- snprintf(buf, buflen, "{ %s%s%s, %p }",
- m->name ? "'" : "", m->name ? m->name : "NULL", m->name ? "'" : "",
- m->name_re);
- return buf;
-} /* string_tostring */
+ int status;
-static char *
-logical_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char left[buflen + 1], right[buflen + 1];
+ assert(m && obj);
+ assert(OP_M(m)->left && OP_M(m)->right);
- if (! m) {
- /* this should not happen */
- snprintf(buf, buflen, "()");
- return buf;
- }
+ status = sdb_store_matcher_matches(OP_M(m)->left, obj);
+ /* lazy evaluation */
+ if ((! status) && (m->type == MATCHER_AND))
+ return status;
+ else if (status && (m->type == MATCHER_OR))
+ return status;
- assert((m->type == MATCHER_OR) || (m->type == MATCHER_AND));
- snprintf(buf, buflen, "(%s, %s, %s)",
- m->type == MATCHER_OR ? "OR" : "AND",
- sdb_store_matcher_tostring(OP_M(m)->left, left, sizeof(left)),
- sdb_store_matcher_tostring(OP_M(m)->right, right, sizeof(right)));
- return buf;
-} /* logical_tostring */
+ return sdb_store_matcher_matches(OP_M(m)->right, obj);
+} /* match_logical */
-static char *
-unary_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
+static int
+match_unary(sdb_store_matcher_t *m, sdb_store_base_t *obj)
{
- char op[buflen + 1];
-
- if (! m) {
- /* this should not happen */
- snprintf(buf, buflen, "()");
- return buf;
- }
+ assert(m && obj);
+ assert(UOP_M(m)->op);
assert(m->type == MATCHER_NOT);
- snprintf(buf, buflen, "(NOT, %s)",
- sdb_store_matcher_tostring(UOP_M(m)->op, op, sizeof(op)));
- return buf;
-} /* unary_tostring */
-
-static char *
-name_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char name[buflen + 1];
- assert(m->type == MATCHER_NAME);
- snprintf(buf, buflen, "OBJ[%s]{ NAME%s }",
- SDB_STORE_TYPE_TO_NAME(NAME_M(m)->obj_type),
- string_tostring(&NAME_M(m)->name, name, sizeof(name)));
- return buf;
-} /* name_tostring */
-
-static char *
-attr_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
-{
- char value[buflen + 1];
-
- if (! m) {
- snprintf(buf, buflen, "ATTR{}");
- return buf;
- }
- assert(m->type == MATCHER_ATTR);
- snprintf(buf, buflen, "ATTR[%s]{ VALUE%s }", ATTR_M(m)->name,
- string_tostring(&ATTR_M(m)->value, value, sizeof(value)));
- return buf;
-} /* attr_tostring */
+ return !sdb_store_matcher_matches(UOP_M(m)->op, obj);
+} /* match_unary */
static int
match_name(sdb_store_matcher_t *m, sdb_store_base_t *obj)
return status;
} /* match_attr */
-/* generic matchers */
-
typedef int (*matcher_cb)(sdb_store_matcher_t *, sdb_store_base_t *);
/* this array needs to be indexable by the matcher types;
match_attr,
};
-typedef char *(*matcher_tostring_cb)(sdb_store_matcher_t *, char *, size_t);
-
-static matcher_tostring_cb matchers_tostring[] = {
- logical_tostring,
- logical_tostring,
- unary_tostring,
- name_tostring,
- attr_tostring,
-};
-
-static int
-match_logical(sdb_store_matcher_t *m, sdb_store_base_t *obj)
-{
- int status;
-
- assert(m && obj);
- assert(OP_M(m)->left && OP_M(m)->right);
-
- status = sdb_store_matcher_matches(OP_M(m)->left, obj);
- /* lazy evaluation */
- if ((! status) && (m->type == MATCHER_AND))
- return status;
- else if (status && (m->type == MATCHER_OR))
- return status;
-
- return sdb_store_matcher_matches(OP_M(m)->right, obj);
-} /* match_logical */
-
-static int
-match_unary(sdb_store_matcher_t *m, sdb_store_base_t *obj)
-{
- assert(m && obj);
- assert(UOP_M(m)->op);
-
- return !sdb_store_matcher_matches(UOP_M(m)->op, obj);
-} /* match_unary */
-
/*
* private matcher types
*/
}
} /* string_matcher_destroy */
+static char *
+string_tostring(string_matcher_t *m, char *buf, size_t buflen)
+{
+ snprintf(buf, buflen, "{ %s%s%s, %p }",
+ m->name ? "'" : "", m->name ? m->name : "NULL", m->name ? "'" : "",
+ m->name_re);
+ return buf;
+} /* string_tostring */
+
/* initializes a name matcher */
static int
name_matcher_init(sdb_object_t *obj, va_list ap)
string_matcher_destroy(&m->name);
} /* name_matcher_destroy */
+static char *
+name_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
+{
+ char name[buflen + 1];
+ assert(m->type == MATCHER_NAME);
+ snprintf(buf, buflen, "OBJ[%s]{ NAME%s }",
+ SDB_STORE_TYPE_TO_NAME(NAME_M(m)->obj_type),
+ string_tostring(&NAME_M(m)->name, name, sizeof(name)));
+ return buf;
+} /* name_tostring */
+
static int
attr_matcher_init(sdb_object_t *obj, va_list ap)
{
string_matcher_destroy(&attr->value);
} /* attr_matcher_destroy */
+static char *
+attr_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
+{
+ char value[buflen + 1];
+
+ if (! m) {
+ snprintf(buf, buflen, "ATTR{}");
+ return buf;
+ }
+
+ assert(m->type == MATCHER_ATTR);
+ snprintf(buf, buflen, "ATTR[%s]{ VALUE%s }", ATTR_M(m)->name,
+ string_tostring(&ATTR_M(m)->value, value, sizeof(value)));
+ return buf;
+} /* attr_tostring */
+
static int
op_matcher_init(sdb_object_t *obj, va_list ap)
{
sdb_object_deref(SDB_OBJ(OP_M(obj)->right));
} /* op_matcher_destroy */
+static char *
+op_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
+{
+ char left[buflen + 1], right[buflen + 1];
+
+ if (! m) {
+ /* this should not happen */
+ snprintf(buf, buflen, "()");
+ return buf;
+ }
+
+ assert((m->type == MATCHER_OR) || (m->type == MATCHER_AND));
+ snprintf(buf, buflen, "(%s, %s, %s)",
+ m->type == MATCHER_OR ? "OR" : "AND",
+ sdb_store_matcher_tostring(OP_M(m)->left, left, sizeof(left)),
+ sdb_store_matcher_tostring(OP_M(m)->right, right, sizeof(right)));
+ return buf;
+} /* op_tostring */
+
static int
uop_matcher_init(sdb_object_t *obj, va_list ap)
{
sdb_object_deref(SDB_OBJ(UOP_M(obj)->op));
} /* uop_matcher_destroy */
+static char *
+uop_tostring(sdb_store_matcher_t *m, char *buf, size_t buflen)
+{
+ char op[buflen + 1];
+
+ if (! m) {
+ /* this should not happen */
+ snprintf(buf, buflen, "()");
+ return buf;
+ }
+
+ assert(m->type == MATCHER_NOT);
+ snprintf(buf, buflen, "(NOT, %s)",
+ sdb_store_matcher_tostring(UOP_M(m)->op, op, sizeof(op)));
+ return buf;
+} /* uop_tostring */
+
static sdb_type_t name_type = {
/* size = */ sizeof(name_matcher_t),
/* init = */ name_matcher_init,
/* destroy = */ uop_matcher_destroy,
};
+typedef char *(*matcher_tostring_cb)(sdb_store_matcher_t *, char *, size_t);
+
+/* this array needs to be indexable by the matcher types;
+ * -> update the enum in store-private.h when updating this */
+static matcher_tostring_cb matchers_tostring[] = {
+ op_tostring,
+ op_tostring,
+ uop_tostring,
+ name_tostring,
+ attr_tostring,
+};
+
/*
* public API
*/