RAVE
rave_value.h
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2025 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of RAVE.
5
6RAVE is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11RAVE is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with RAVE. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
26#ifndef RAVE_VALUE_H
27#define RAVE_VALUE_H
28#include "rave_object.h"
30#include <stdarg.h>
31
43
48
53
60
66
72RaveValue_t* RaveValue_createString(const char* value);
73
79RaveValue_t* RaveValue_createStringFmt(const char* fmt, ...);
80
87int RaveValue_setString(RaveValue_t* self, const char* value);
88
95int RaveValue_getString(RaveValue_t* self, char** value);
96
102const char* RaveValue_toString(RaveValue_t* self);
103
104RaveValue_t* RaveValueString_trim(RaveValue_t* self);
105
113RaveValue_t* RaveValueString_substring(RaveValue_t* self, int start, int len);
114
122
129
135void RaveValue_setLong(RaveValue_t* self, long value);
136
143int RaveValue_getLong(RaveValue_t* self, long* value);
144
150long RaveValue_toLong(RaveValue_t* self);
151
152
159
165void RaveValue_setDouble(RaveValue_t* self, double value);
166
173int RaveValue_getDouble(RaveValue_t* self, double* value);
174
180double RaveValue_toDouble(RaveValue_t* self);
181
188
194 void RaveValue_setBoolean(RaveValue_t* self, int value);
195
202 int RaveValue_getBoolean(RaveValue_t* self, int* value);
203
210
217
223
230
237
244RaveValue_t* RaveValue_createStringArray(const char** value, int len);
245
253int RaveValue_setStringArray(RaveValue_t* self, const char** value, int len);
254
262int RaveValue_getStringArray(RaveValue_t* self, char*** value, int* len);
263
270
277RaveValue_t* RaveValue_createLongArray(long* value, int len);
278
286int RaveValue_setLongArray(RaveValue_t* self, long* value, int len);
287
295int RaveValue_getLongArray(RaveValue_t* self, long** value, int* len);
296
303
310RaveValue_t* RaveValue_createDoubleArray(double* value, int len);
311
319int RaveValue_setDoubleArray(RaveValue_t* self, double* value, int len);
320
328int RaveValue_getDoubleArray(RaveValue_t* self, double** value, int* len);
329
336
344
352
359
367int RaveValueHash_put(RaveValue_t* self, const char* key, RaveValue_t* value);
368
375 RaveValue_t* RaveValueHash_get(RaveValue_t* self, const char* key);
376
377
384
391int RaveValueHash_exists(RaveValue_t* self, const char* key);
392
398void RaveValueHash_remove(RaveValue_t* self, const char* key);
399
405
412
419
427
435
442
449int RaveValueList_add(RaveValue_t* self, RaveValue_t* value);
450
458int RaveValueList_insert(RaveValue_t* self, int index, RaveValue_t* value);
459
467RaveValue_t* RaveValueList_join(RaveValue_t* self, const char* sep);
468
475
482RaveValue_t* RaveValueList_get(RaveValue_t* self, int index);
483
489void RaveValueList_release(RaveValue_t* self, int index);
490
496
502char* RaveValue_toJSON(RaveValue_t* self);
503
509RaveValue_t* RaveValue_fromJSON(const char* json);
510
516RaveValue_t* RaveValue_loadJSON(const char* filename);
517
518#endif /* RAVE_VALUE_H */
519
struct _RaveList_t RaveList_t
Defines a list.
Definition rave_list.h:33
Generic implementation of an object that is used within rave.
struct _raveobjecttype RaveCoreObjectType
The rave object type definition.
RaveCoreObjectType RaveValue_TYPE
Type definition to use when creating a rave object.
Definition rave_value.c:1406
void RaveValueHash_clear(RaveValue_t *self)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_clear.
Definition rave_value.c:1004
void RaveValueList_release(RaveValue_t *self, int index)
If rave value is list, then this provides same functionality as RaveObjectList_release.
Definition rave_value.c:1142
int RaveValue_setString(RaveValue_t *self, const char *value)
Sets a string value in self.
Definition rave_value.c:205
RaveValue_t * RaveValueHash_get(RaveValue_t *self, const char *key)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_get.
Definition rave_value.c:960
int RaveValue_getString(RaveValue_t *self, char **value)
Returns the value as a string.
Definition rave_value.c:228
int RaveValue_getLongArray(RaveValue_t *self, long **value, int *len)
Returns the value as a long array.
Definition rave_value.c:726
int RaveValue_getList(RaveValue_t *self, RaveObjectList_t **rlist)
Returns the rave list if possible.
Definition rave_value.c:1055
int RaveValueHash_size(RaveValue_t *self)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_size.
Definition rave_value.c:974
RaveValue_t * RaveValue_createString(const char *value)
Creates a string rave value.
Definition rave_value.c:177
void RaveValue_setBoolean(RaveValue_t *self, int value)
Sets the value as a boolean.
Definition rave_value.c:499
int RaveValue_getHashTable(RaveValue_t *self, RaveObjectHashTable_t **table)
Returns the hash table if possible.
Definition rave_value.c:933
char * RaveValue_toJSON(RaveValue_t *self)
Translates self to a json representation.
Definition rave_value.c:1237
RaveValue_t * RaveValueString_tokenize(RaveValue_t *self, int delim)
Tokenizes a string into a string array of tokens.
Definition rave_value.c:349
RaveValue_t * RaveValue_loadJSON(const char *filename)
Loads a JSON object from a file.
Definition rave_value.c:1388
RaveValue_t * RaveValue_createList(RaveObjectList_t *rlist)
Creates a rave value list.
Definition rave_value.c:1022
RaveValue_Type RaveValue_type(RaveValue_t *self)
Returns the format for this attribute.
Definition rave_value.c:157
int RaveValueHash_exists(RaveValue_t *self, const char *key)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_exists.
Definition rave_value.c:983
int RaveValue_setStringArray(RaveValue_t *self, const char **value, int len)
Sets the value as a simple 1-dimensional string array.
Definition rave_value.c:582
int RaveValue_isStringArray(RaveValue_t *self)
Returns if the rave value can be represented as a string array (list of strings only)
Definition rave_value.c:549
int RaveValue_toBoolean(RaveValue_t *self)
Returns the boolean value.
Definition rave_value.c:519
int RaveValue_getStringArray(RaveValue_t *self, char ***value, int *len)
Returns the value as a string array.
Definition rave_value.c:615
RaveList_t * RaveValueHash_keys(RaveValue_t *self)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_keys.
Definition rave_value.c:1012
const char * RaveValue_toString(RaveValue_t *self)
Returns the string value.
Definition rave_value.c:240
int RaveValueList_add(RaveValue_t *self, RaveValue_t *value)
If rave value is list, then this provides same functionality as RaveObjectList_add.
Definition rave_value.c:1072
RaveValue_t * RaveValue_createLongArray(long *value, int len)
Creates a long array rave value.
Definition rave_value.c:687
RaveValue_t * RaveValueList_get(RaveValue_t *self, int index)
If rave value is list, then this provides same functionality as RaveObjectList_get.
Definition rave_value.c:1133
void RaveValue_setLong(RaveValue_t *self, long value)
Sets the value as a long.
Definition rave_value.c:424
RaveValue_t * RaveValue_createNull()
Creates a null rave value.
Definition rave_value.c:525
RaveValue_t * RaveValue_createStringArray(const char **value, int len)
Creates a string array rave value.
Definition rave_value.c:571
int RaveValue_setHashTable(RaveValue_t *self, RaveObjectHashTable_t *table)
Sets the value as a hash table.
Definition rave_value.c:922
void RaveValueHash_remove(RaveValue_t *self, const char *key)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_remove except tha...
Definition rave_value.c:995
int RaveValue_setLongArray(RaveValue_t *self, long *value, int len)
Sets the value as a simple 1-dimensional long array.
Definition rave_value.c:698
RaveObjectList_t * RaveValue_toList(RaveValue_t *self)
NOTE!
Definition rave_value.c:1066
int RaveValue_setList(RaveValue_t *self, RaveObjectList_t *rlist)
Sets the value as a rave list.
Definition rave_value.c:1043
RaveValue_t * RaveValue_createBoolean(int value)
Creates a boolean rave value.
Definition rave_value.c:488
int RaveValue_isLongArray(RaveValue_t *self)
Returns if the rave value can be represented as a long array (list of long only)
Definition rave_value.c:666
RaveValue_t * RaveValue_createStringFmt(const char *fmt,...)
Creates a string rave value from a varargs list.
Definition rave_value.c:188
RaveValue_t * RaveValueList_join(RaveValue_t *self, const char *sep)
Creates a rave value string from the list of strings and adds the separator between each entry.
Definition rave_value.c:1092
RaveObjectHashTable_t * RaveValue_toHashTable(RaveValue_t *self)
NOTE!
Definition rave_value.c:944
int RaveValueList_insert(RaveValue_t *self, int index, RaveValue_t *value)
If rave value is list, then this provides same functionality as RaveObjectList_insert.
Definition rave_value.c:1082
RaveValue_t * RaveValueString_substring(RaveValue_t *self, int start, int len)
Creates a substring from self.
Definition rave_value.c:306
int RaveValue_getDouble(RaveValue_t *self, double *value)
Returns the value as a double.
Definition rave_value.c:470
int RaveValue_getLong(RaveValue_t *self, long *value)
Returns the value as a long.
Definition rave_value.c:432
struct _RaveValue_t RaveValue_t
Defines a rave value.
Definition rave_value.h:47
void RaveValue_reset(RaveValue_t *self)
Resets the value object.
Definition rave_value.c:163
long RaveValue_toLong(RaveValue_t *self)
Returns the long value.
Definition rave_value.c:444
RaveValue_t * RaveValue_createDoubleArray(double *value, int len)
Creates a double array rave value.
Definition rave_value.c:789
int RaveValueHash_put(RaveValue_t *self, const char *key, RaveValue_t *value)
If rave value is hash, then this provides same functionality as RaveObjectHashTable_put.
Definition rave_value.c:950
int RaveValue_isDoubleArray(RaveValue_t *self)
Returns if the rave value can be represented as a double array (list of double only)
Definition rave_value.c:768
RaveValue_t * RaveValue_createDouble(double value)
Creates a double rave value.
Definition rave_value.c:450
RaveValue_t * RaveValue_createLong(long value)
Creates a long rave value.
Definition rave_value.c:413
int RaveValue_isNull(RaveValue_t *self)
Returns if the value is null or not.
Definition rave_value.c:543
double RaveValue_toDouble(RaveValue_t *self)
Returns the double value.
Definition rave_value.c:482
RaveValue_Type
Definition rave_value.h:32
@ RaveValue_Type_String
String.
Definition rave_value.h:34
@ RaveValue_Type_Long
Long.
Definition rave_value.h:35
@ RaveValue_Type_Boolean
Boolean.
Definition rave_value.h:37
@ RaveValue_Type_Hashtable
Hash table.
Definition rave_value.h:40
@ RaveValue_Type_Data2D
2D array
Definition rave_value.h:39
@ RaveValue_Type_Undefined
Undefined.
Definition rave_value.h:33
@ RaveValue_Type_Null
Null.
Definition rave_value.h:38
@ RaveValue_Type_Double
Double.
Definition rave_value.h:36
int RaveValueList_size(RaveValue_t *self)
If rave value is list, then this provides same functionality as RaveObjectList_size.
Definition rave_value.c:1124
RaveValue_t * RaveValue_fromJSON(const char *json)
Support function for translating a json structure to a rave value.
Definition rave_value.c:1366
int RaveValue_setDoubleArray(RaveValue_t *self, double *value, int len)
Sets the value as a simple 1-dimensional double array.
Definition rave_value.c:800
void RaveValue_setDouble(RaveValue_t *self, double value)
Sets the value as a double.
Definition rave_value.c:462
RaveValue_t * RaveValue_createHashTable(RaveObjectHashTable_t *hashtable)
Creates a rave value hash table.
Definition rave_value.c:874
int RaveValue_getBoolean(RaveValue_t *self, int *value)
Returns the value as a boolean.
Definition rave_value.c:507
int RaveValue_getDoubleArray(RaveValue_t *self, double **value, int *len)
Returns the value as a double array.
Definition rave_value.c:828
void RaveValueList_clear(RaveValue_t *self)
If rave value is list, then this provides same functionality as RaveObjectList_clear.
Definition rave_value.c:1150
void RaveValue_setNull(RaveValue_t *self)
Sets the value as a null value.
Definition rave_value.c:536
Implementation of a rave object hashtable that maps between strings and rave core objects.
struct _RaveObjectHashTable_t RaveObjectHashTable_t
Defines a hash table.
Definition raveobject_hashtable.h:38
struct _RaveObjectList_t RaveObjectList_t
Defines a list.
Definition raveobject_list.h:38
Represents one scan in a volume.
Definition rave_value.c:47
RaveObjectHashTable_t * hashtable
the hash table
Definition rave_value.c:54