diff options
author | Dmitri Pal <dpal@redhat.com> | 2010-06-10 11:57:25 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-09-22 14:57:53 -0400 |
commit | 30eeb8e833570c9117f298005d33e6e238561237 (patch) | |
tree | d77ed4494d05bcee7991c54e43a7374eba846cfc /ini/ini_valueobj.h | |
parent | 6f41753879870c35b2192fe6d6e7c0fca8f5ef17 (diff) | |
download | ding-libs-30eeb8e833570c9117f298005d33e6e238561237.tar.gz ding-libs-30eeb8e833570c9117f298005d33e6e238561237.tar.xz ding-libs-30eeb8e833570c9117f298005d33e6e238561237.zip |
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
Diffstat (limited to 'ini/ini_valueobj.h')
-rw-r--r-- | ini/ini_valueobj.h | 130 |
1 files changed, 130 insertions, 0 deletions
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 <dpal@redhat.com> 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 <http://www.gnu.org/licenses/>. +*/ + + +#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 |