From 30eeb8e833570c9117f298005d33e6e238561237 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Thu, 10 Jun 2010 11:57:25 -0400 Subject: Introducing Value object Value object is an object that combines a potentially multiline value comment and some statistical information regarding a configuration value. Patch includes: Source Header Unit test Makefile changes --- ini/ini_valueobj.h | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 ini/ini_valueobj.h (limited to 'ini/ini_valueobj.h') diff --git a/ini/ini_valueobj.h b/ini/ini_valueobj.h new file mode 100644 index 0000000..d8e10de --- /dev/null +++ b/ini/ini_valueobj.h @@ -0,0 +1,130 @@ +/* + INI LIBRARY + + Header file for the value object. + + Copyright (C) Dmitri Pal 2010 + + INI Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + INI Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with INI Library. If not, see . +*/ + + +#ifndef INI_VALUEOBJ_H +#define INI_VALUEOBJ_H + +#include "ref_array.h" +#include "simplebuffer.h" +#include "ini_comment.h" + +struct value_obj; + +#define INI_VALUE_READ 0 /* Value is read from the file */ +#define INI_VALUE_CREATED 1 /* Value is created in memory */ + +/* + * Create value from a referenced array. + * + * NOTE: arrays and comment are NOT treated as + * objects that keep reference count. + * They are created externally and passed in + * as separate parts that are glued together + * by the value object. + * The caller should not free it himself + * (only in case of failure) since + * after the call the arrays and comment + * are owned by the value object and will + * be freed when it is destroyed. + */ +int value_create_from_refarray(struct ref_array *raw_lines, + struct ref_array *raw_lengths, + uint32_t line, + uint32_t origin, + uint32_t key_len, + uint32_t boundary, + struct ini_comment *ic, + struct value_obj **vo); + +/* Cleanup callback for lines array */ +void value_lines_cleanup_cb(void *elem, + ref_array_del_enum type, + void *data); + +/* Create a pair of arrays */ +int value_create_arrays(struct ref_array **raw_lines, + struct ref_array **raw_lengths); + +/* Add a raw read line to the arrays */ +int value_add_to_arrays(const char *strvalue, + uint32_t len, + struct ref_array *raw_lines, + struct ref_array *raw_lengths); + +/* Create a pair of arrays */ +void value_destroy_arrays(struct ref_array *raw_lines, + struct ref_array *raw_lengths); + +/* Create value object from string buffer. + * NOTE: see note above + * in the description of the + * value_create_from_refarray function. + */ +int value_create_new(const char *strvalue, + uint32_t length, + uint32_t origin, + uint32_t key_len, + uint32_t boundary, + struct ini_comment *ic, + struct value_obj **vo); + +/* Destroy a value object */ +void value_destroy(struct value_obj *vo); + +/* Get concatenated value */ +int value_get_concatenated(struct value_obj *vo, + const char **fullstr); + +/* Get value's origin */ +int value_get_origin(struct value_obj *vo, + uint32_t *origin); + +/* Get value's line */ +int value_get_line(struct value_obj *vo, + uint32_t *line); + +/* Update key length */ +int value_set_keylen(struct value_obj *vo, + uint32_t key_len); + +/* Update value */ +int value_update(struct value_obj *vo, + const char *value, + uint32_t length, + uint32_t origin, + uint32_t boundary); + +/* Get comment from the value */ +int value_extract_comment(struct value_obj *vo, + struct ini_comment **ic); + +/* Set comment into the value */ +int value_put_comment(struct value_obj *vo, + struct ini_comment *ic); + +/* Serialize value */ +int value_serialize(struct value_obj *vo, + const char *key, + struct simplebuffer **sbobj); + + +#endif -- cgit