index c179fea84b142f836a24eb4791eb12194344f12e..558e1668272e327f4719ac041c9faa28af8a80e7 100644 (file)
--- a/src/include/core/data.h
+++ b/src/include/core/data.h
enum {
SDB_TYPE_NULL = 0,
+ SDB_TYPE_BOOLEAN,
SDB_TYPE_INTEGER,
SDB_TYPE_DECIMAL,
SDB_TYPE_STRING,
};
#define SDB_TYPE_TO_STRING(t) \
- (((t) == SDB_TYPE_INTEGER) ? "INTEGER" \
+ (((t) == SDB_TYPE_NULL) ? "NULL" \
+ : ((t) == SDB_TYPE_BOOLEAN) ? "BOOLEAN" \
+ : ((t) == SDB_TYPE_INTEGER) ? "INTEGER" \
: ((t) == SDB_TYPE_DECIMAL) ? "DECIMAL" \
: ((t) == SDB_TYPE_STRING) ? "STRING" \
: ((t) == SDB_TYPE_DATETIME) ? "DATETIME" \
: ((t) == SDB_TYPE_BINARY) ? "BINARY" \
: ((t) == SDB_TYPE_REGEX) ? "REGEX" \
+ : ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_BOOLEAN)) ? "[]BOOLEAN" \
: ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_INTEGER)) ? "[]INTEGER" \
: ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_DECIMAL)) ? "[]DECIMAL" \
: ((t) == (SDB_TYPE_ARRAY | SDB_TYPE_STRING)) ? "[]STRING" \
typedef union sdb_datum sdb_datum_t;
union sdb_datum {
+ bool boolean; /* SDB_TYPE_BOOLEAN */
int64_t integer; /* SDB_TYPE_INTEGER */
double decimal; /* SDB_TYPE_DECIMAL */
char *string; /* SDB_TYPE_STRING */
* - the number of characters written to the buffer (excluding the terminated
* null byte) or the number of characters which would have been written in
* case the output was truncated
- * - a negative value else
*/
-int
+size_t
sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted);
/*
@@ -302,24 +306,16 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted);
* character of the string is "0"), sedecimal (base 16, if the string includes
* the "0x" prefix), or decimal. Decimal numbers may also be "infinity" or
* "NaN" or may use a decimal exponent. Date-time values are expected to be
- * specified as (floating point) number of seconds since the epoch. For string
- * and binary data, the input string is passed to the datum. The function does
- * not allocate new memory for that purpose. Use sdb_data_copy() if you want
- * to do that. For regex data, the input string is copied to newly allocated
- * memory and also compiled to a regex. Use sdb_data_free_datum() to free the
- * dynamically allocated memory.
- *
- * The input string may be stored in 'data', that is, the function may be used
- * to do an inline cast from a string to any other type. It is the callers
- * responsibility to free the memory used by the string in case the target
- * type does not keep a reference to it.
+ * specified as (floating point) number of seconds since the epoch. New memory
+ * will be allocated as necessary and will have to be free'd using
+ * sdb_data_free_datum().
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_data_parse(char *str, int type, sdb_data_t *data);
+sdb_data_parse(const char *str, int type, sdb_data_t *data);
/*
* sdb_data_sizeof: