INGOR
Loading...
Searching...
No Matches
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
83ytKeyValues * ytKeyValues_new();
84void ytKeyValues_delete(ytKeyValues * this);
85#endif
86
87void ytKeyValues_deleteAll(ytKeyValues * this);
88void ytKeyValues_deleteAllv(void * this);
89ytKeyValues * ytKeyValues_clone(const ytKeyValues * this);
90ytObject * ytKeyValues_cloneI(const ytObject * this);
91ytObject * ytKeyValues_obj(ytKeyValues * kv);
92ytKeyValues * ytKeyValues_from(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);
97void ytKeyValues_add(ytKeyValues * this,
98 const char * key, ytObject * value);
99void ytKeyValues_add2(ytKeyValues * this,
100 char * key, ytObject * value);
101void ytKeyValues_addInt(ytKeyValues * this,
102 const char * key, int value);
103void ytKeyValues_addString(ytKeyValues * this,
104 const char * key, const char * value);
105void ytKeyValues_addIntArray(ytKeyValues * this,
106 const char * key, ytIntArray * value);
107void ytKeyValues_addDoubleArray(ytKeyValues * this,
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);
123ytStrArray * ytKeyValues_getKeys(const ytKeyValues * this, ytStrArray * ar);
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.
int * ytKeyValues_DEFAULT_VALUE_OFF
Value representing OFF.
Definition ytKeyValues.h:63
char * ytKeyValues_DEFAULT_KEY
Value representing the default key, that is, the key used for values without keys.
Definition ytKeyValues.h:51
int * ytKeyValues_DEFAULT_VALUE_ON
Value representing ON.
Definition ytKeyValues.h:59
char * ytKeyValues_ERROR_KEY
Value representing error key.
Definition ytKeyValues.h:55
char * ytKeyValues_DEFAULT_VALUE
Value used as a default value for no argument keys.
Definition ytKeyValues.h:46
The basis class.
Expandable array.