INGOR
ytKeyValues.h
1/*
2 util/ytKeyValues.{h,c} : Key-value pairs.
3 Copyright (C) 2018, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Kyoto University nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#ifndef __YTLIB_KEY_VALUES_H
37#define __YTLIB_KEY_VALUES_H
38
39#include "ytStrArray.h"
40#include "ytArray.h"
41#include "ytIntArray.h"
42#include "ytDoubleArray.h"
43
47
52
56
60
64
65#ifdef DOXY
68#define ytKeyValues_ERROR_VALUE
69#else
70#define ytKeyValues_ERROR_VALUE ((size_t) -1)
71#endif
72
73typedef struct ytKeyValues_t ytKeyValues;
74
75
76
77#ifdef YTLIB_MEMCHECK
78ytKeyValues * ytKeyValues_newm(const char * file, int line);
79void ytKeyValues_deletem(ytKeyValues * this, const char * file, int line);
80#define ytKeyValues_new() ytKeyValues_newm(__FILE__,__LINE__)
81#define ytKeyValues_delete(this) ytKeyValues_deletem(this,__FILE__,__LINE__)
82#else
85#endif
86
88void ytKeyValues_deleteAllv(void * this);
90ytObject * ytKeyValues_cloneI(const ytObject * this);
93ytObject * ytKeyValues_pObj(ytKeyValues ** ptr);
94ytKeyValues ** ytKeyValues_objP(ytObject * obj);
95void ytKeyValues_dump(ytKeyValues * this, FILE * fp);
96void ytKeyValues_setPR(ytObject * a, ytKeyValues * v);
98 const char * key, ytObject * value);
99void ytKeyValues_add2(ytKeyValues * this,
100 char * key, ytObject * value);
102 const char * key, int value);
104 const char * key, const char * value);
106 const char * key, ytIntArray * value);
108 const char * key, ytDoubleArray * value);
109void ytKeyValues_set(ytKeyValues * this, const char * key, ytObject * value);
110void ytKeyValues_setDelete(ytKeyValues * this, const char * key, ytObject * value);
111ytObject * ytKeyValues_get(const ytKeyValues * this, const char * key);
112int ytKeyValues_getInt(const ytKeyValues * this, const char * key, int def);
113double ytKeyValues_getDouble(const ytKeyValues * this, const char * key, double def);
114char * ytKeyValues_getString(const ytKeyValues * this, const char * key);
115ytIntArray * ytKeyValues_getIntArray(const ytKeyValues * this, const char * key);
116ytStrArray * ytKeyValues_getStrArray(const ytKeyValues * this, const char * key);
117ytObject * ytKeyValues_remove(ytKeyValues * this, const char * key);
118size_t ytKeyValues_size(const ytKeyValues * this);
119const char * ytKeyValues_getKey(const ytKeyValues * this, size_t index);
120ytObject * ytKeyValues_getValue(const ytKeyValues * this, size_t index);
121int ytKeyValues_getKeyIndex(const ytKeyValues * this, const char * key);
122ytKeyValues * ytKeyValues_parse(const char * str);
124void ytKeyValues_print(const ytKeyValues * this, FILE * fp);
125void ytKeyValues_printI(const ytObject * this, FILE * fp);
126size_t ytKeyValues_memorySize(const ytKeyValues * this);
127ytByte * ytKeyValues_serialize(const ytKeyValues * this, ytByte ** pptr);
128ytKeyValues * ytKeyValues_deserialize(ytByte ** const pptr);
129ytByte * ytKeyValues_serializeI(const ytObject * obj, ytByte ** pptr);
130ytObject * ytKeyValues_deserializeI(ytByte ** const pptr);
131
132
133#define ytKV(str) ytKeyValues_parse(str)
134
135int ytKeyValues_test(int argc, char * argv[]);
136
137#ifdef USE_MPI
138#include <mpi.h>
139void ytKeyValues_MPI_Bcast(ytKeyValues ** pObject, int root, MPI_Comm comm);
140#endif /* USE_MPI */
141
142
143#endif /* __YTLIB_KEY_VALUES_H */
Expandable array.
Expandable array.
key-value pairs.
void ytKeyValues_addDoubleArray(ytKeyValues *this, const char *key, ytDoubleArray *value)
Adds a double-precision float array to the ytKeyValues instance.
Definition: ytKeyValues.c:310
void ytKeyValues_delete(ytKeyValues *this)
Deletes the ytKeyValues instance.
Definition: ytKeyValues.c:93
ytStrArray * ytKeyValues_getStrArray(const ytKeyValues *this, const char *key)
Returns the value associated with the given key as a ytStrArray instance.
Definition: ytKeyValues.c:414
ytObject * ytKeyValues_get(const ytKeyValues *this, const char *key)
Returns the value associated with the given key.
Definition: ytKeyValues.c:323
void ytKeyValues_addInt(ytKeyValues *this, const char *key, int value)
Adds an integer value to the ytKeyValues instance.
Definition: ytKeyValues.c:271
void ytKeyValues_addString(ytKeyValues *this, const char *key, const char *value)
Adds a string value to the ytKeyValues instance.
Definition: ytKeyValues.c:283
ytKeyValues * ytKeyValues_new()
Creates a new ytKeyValues instance.
Definition: ytKeyValues.c:73
void ytKeyValues_print(const ytKeyValues *this, FILE *fp)
Prints the contents of the ytKeyValues instance.
Definition: ytKeyValues.c:565
ytObject * ytKeyValues_getValue(const ytKeyValues *this, size_t index)
Returns the value at the specified position.
Definition: ytKeyValues.c:447
void ytKeyValues_deleteAll(ytKeyValues *this)
Deletes the ytKeyValues instance and stored values.
Definition: ytKeyValues.c:110
ytObject * ytKeyValues_remove(ytKeyValues *this, const char *key)
Removes a key value pair.
Definition: ytKeyValues.c:335
double ytKeyValues_getDouble(const ytKeyValues *this, const char *key, double def)
Returns the value associated with the given key as a double value.
Definition: ytKeyValues.c:377
char * ytKeyValues_getString(const ytKeyValues *this, const char *key)
Returns the value associated with the given key as a string value.
Definition: ytKeyValues.c:390
void ytKeyValues_add(ytKeyValues *this, const char *key, ytObject *value)
Adds a value to the ytKeyValues instance.
Definition: ytKeyValues.c:203
int * ytKeyValues_DEFAULT_VALUE_OFF
Value representing OFF.
Definition: ytKeyValues.h:63
ytStrArray * ytKeyValues_getKeys(const ytKeyValues *this, ytStrArray *ar)
Returns the added keys.
Definition: ytKeyValues.c:552
ytObject * ytKeyValues_obj(ytKeyValues *kv)
Returns the pointer of ytObject.
Definition: ytKeyValues.c:160
ytKeyValues * ytKeyValues_from(ytObject *this)
Converts an ytObject instance to ytKeyValues.
Definition: ytKeyValues.c:172
char * ytKeyValues_DEFAULT_KEY
Value representing the default key, that is, the key used for values without keys.
Definition: ytKeyValues.h:51
size_t ytKeyValues_size(const ytKeyValues *this)
Returns the number of key-value pairs.
Definition: ytKeyValues.c:426
ytKeyValues * ytKeyValues_deserialize(ytByte **const pptr)
Deserializes the object from the serialized binary sequence.
Definition: ytKeyValues.c:662
void ytKeyValues_set(ytKeyValues *this, const char *key, ytObject *value)
Sets a key and its value to the ytKeyValues instance.
Definition: ytKeyValues.c:222
ytByte * ytKeyValues_serialize(const ytKeyValues *this, ytByte **pptr)
Serializes the objects onto the memory.
Definition: ytKeyValues.c:621
ytKeyValues * ytKeyValues_parse(const char *str)
Parses a ytKeyValue format string and store keys and values in the generated ytKeyValues instance.
Definition: ytKeyValues.c:534
int * ytKeyValues_DEFAULT_VALUE_ON
Value representing ON.
Definition: ytKeyValues.h:59
char * ytKeyValues_ERROR_KEY
Value representing error key.
Definition: ytKeyValues.h:55
const char * ytKeyValues_getKey(const ytKeyValues *this, size_t index)
Returns the key at the specified index.
Definition: ytKeyValues.c:435
char * ytKeyValues_DEFAULT_VALUE
Value used as a default value for no argument keys.
Definition: ytKeyValues.h:46
ytIntArray * ytKeyValues_getIntArray(const ytKeyValues *this, const char *key)
Returns the value associated with the given key as a ytIntArray instance.
Definition: ytKeyValues.c:402
ytKeyValues * ytKeyValues_clone(const ytKeyValues *this)
Generates a clone of this ytKeyValue instance.
Definition: ytKeyValues.c:134
void ytKeyValues_setDelete(ytKeyValues *this, const char *key, ytObject *value)
Sets a key and its value to the ytKeyValues instance.
Definition: ytKeyValues.c:238
int ytKeyValues_getInt(const ytKeyValues *this, const char *key, int def)
Returns the value associated with the given key as an integer value.
Definition: ytKeyValues.c:357
void ytKeyValues_addIntArray(ytKeyValues *this, const char *key, ytIntArray *value)
Adds an integer array to the ytKeyValues instance.
Definition: ytKeyValues.c:296
The basis class.
Expandable array.