From: Sebastian Harl Date: Sun, 9 Nov 2014 09:36:07 +0000 (+0100) Subject: store.h: Use separate value ranges for object and field types. X-Git-Tag: sysdb-0.6.0~17 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=ea5d74f9f19a7a00ed993e6d6a5a5c9e03ab6ff8 store.h: Use separate value ranges for object and field types. This allows to use the same flag to store either object or field types or even a combination of both. --- diff --git a/src/include/core/store.h b/src/include/core/store.h index b84fc72..40374dd 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -49,6 +49,15 @@ enum { SDB_SERVICE, SDB_METRIC, SDB_ATTRIBUTE, + + /* + * Queryable fields of a stored object. + */ + SDB_FIELD_NAME = 1 << 8, /* type: string */ + SDB_FIELD_LAST_UPDATE, /* type: datetime */ + SDB_FIELD_AGE, /* type: datetime */ + SDB_FIELD_INTERVAL, /* type: datetime */ + SDB_FIELD_BACKEND, /* type: array of strings */ }; #define SDB_STORE_TYPE_TO_NAME(t) \ (((t) == SDB_HOST) ? "host" \ @@ -56,6 +65,21 @@ enum { : ((t) == SDB_METRIC) ? "metric" \ : ((t) == SDB_ATTRIBUTE) ? "attribute" : "unknown") +#define SDB_FIELD_TO_NAME(f) \ + (((f) == SDB_FIELD_NAME) ? "name" \ + : ((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \ + : ((f) == SDB_FIELD_AGE) ? "age" \ + : ((f) == SDB_FIELD_INTERVAL) ? "interval" \ + : ((f) == SDB_FIELD_BACKEND) ? "backend" : "unknown") + +#define SDB_FIELD_TYPE(f) \ + (((f) == SDB_FIELD_NAME) ? SDB_TYPE_STRING \ + : ((f) == SDB_FIELD_LAST_UPDATE) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_AGE) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_INTERVAL) ? SDB_TYPE_DATETIME \ + : ((f) == SDB_FIELD_BACKEND) ? (SDB_TYPE_ARRAY | SDB_TYPE_STRING) \ + : -1) + /* * sdb_store_obj_t represents the super-class of any object stored in the * database. It inherits from sdb_object_t and may safely be cast to a generic @@ -95,32 +119,6 @@ typedef struct sdb_store_matcher sdb_store_matcher_t; struct sdb_store_json_formatter; typedef struct sdb_store_json_formatter sdb_store_json_formatter_t; -/* - * Queryable fields of a stored object. - */ -enum { - SDB_FIELD_NAME = 1, /* string */ - SDB_FIELD_LAST_UPDATE, /* datetime */ - SDB_FIELD_AGE, /* datetime */ - SDB_FIELD_INTERVAL, /* datetime */ - SDB_FIELD_BACKEND, /* string */ -}; - -#define SDB_FIELD_TO_NAME(f) \ - (((f) == SDB_FIELD_NAME) ? "name" \ - : ((f) == SDB_FIELD_LAST_UPDATE) ? "last-update" \ - : ((f) == SDB_FIELD_AGE) ? "age" \ - : ((f) == SDB_FIELD_INTERVAL) ? "interval" \ - : ((f) == SDB_FIELD_BACKEND) ? "backend" : "unknown") - -#define SDB_FIELD_TYPE(f) \ - (((f) == SDB_FIELD_NAME) ? SDB_TYPE_STRING \ - : ((f) == SDB_FIELD_LAST_UPDATE) ? SDB_TYPE_DATETIME \ - : ((f) == SDB_FIELD_AGE) ? SDB_TYPE_DATETIME \ - : ((f) == SDB_FIELD_INTERVAL) ? SDB_TYPE_DATETIME \ - : ((f) == SDB_FIELD_BACKEND) ? (SDB_TYPE_ARRAY | SDB_TYPE_STRING) \ - : -1) - /* * sdb_store_clear: * Clear the entire store and remove all stored objects.