RAVE
rave_value.c File Reference

Data value abstraction. More...

#include "rave_value.h"
#include "rave_debug.h"
#include "rave_alloc.h"
#include <string.h>
#include "rave_list.h"
#include "rave_object.h"
#include "rave_data2d.h"
#include "raveobject_hashtable.h"
#include "raveobject_list.h"
#include <errno.h>
#include <stdio.h>

Classes

struct  _RaveValue_t
 Represents one scan in a volume. More...
 

Functions

RaveValue_Type RaveValue_type (RaveValue_t *self)
 Returns the format for this attribute.
 
void RaveValue_reset (RaveValue_t *self)
 Resets the value object.
 
RaveValue_tRaveValue_createString (const char *value)
 Creates a string rave value.
 
int RaveValue_setString (RaveValue_t *self, const char *value)
 Sets a string value in self.
 
int RaveValue_getString (RaveValue_t *self, char **value)
 Returns the value as a string.
 
const char * RaveValue_toString (RaveValue_t *self)
 Returns the string value.
 
RaveValue_tRaveValue_createLong (long value)
 Creates a long rave value.
 
void RaveValue_setLong (RaveValue_t *self, long value)
 Sets the value as a long.
 
int RaveValue_getLong (RaveValue_t *self, long *value)
 Returns the value as a long.
 
long RaveValue_toLong (RaveValue_t *self)
 Returns the long value.
 
RaveValue_tRaveValue_createDouble (double value)
 Creates a double rave value.
 
void RaveValue_setDouble (RaveValue_t *self, double value)
 Sets the value as a double.
 
int RaveValue_getDouble (RaveValue_t *self, double *value)
 Returns the value as a double.
 
double RaveValue_toDouble (RaveValue_t *self)
 Returns the double value.
 
RaveValue_tRaveValue_createBoolean (int value)
 Creates a boolean rave value.
 
void RaveValue_setBoolean (RaveValue_t *self, int value)
 Sets the value as a boolean.
 
int RaveValue_getBoolean (RaveValue_t *self, int *value)
 Returns the value as a boolean.
 
int RaveValue_toBoolean (RaveValue_t *self)
 Returns the boolean value.
 
RaveValue_tRaveValue_createNull ()
 Creates a null rave value.
 
void RaveValue_setNull (RaveValue_t *self)
 Sets the value as a null value.
 
int RaveValue_isNull (RaveValue_t *self)
 Returns if the value is null or not.
 
int RaveValue_isStringArray (RaveValue_t *self)
 Returns if the rave value can be represented as a string array (list of strings only)
 
RaveValue_tRaveValue_createStringArray (const char **value, int len)
 Creates a string array rave value.
 
int RaveValue_setStringArray (RaveValue_t *self, const char **value, int len)
 Sets the value as a simple 1-dimensional string array.
 
int RaveValue_getStringArray (RaveValue_t *self, char ***value, int *len)
 Returns the value as a string array.
 
int RaveValue_isLongArray (RaveValue_t *self)
 Returns if the rave value can be represented as a long array (list of long only)
 
RaveValue_tRaveValue_createLongArray (long *value, int len)
 Creates a long array rave value.
 
int RaveValue_setLongArray (RaveValue_t *self, long *value, int len)
 Sets the value as a simple 1-dimensional long array.
 
int RaveValue_getLongArray (RaveValue_t *self, long **value, int *len)
 Returns the value as a long array.
 
int RaveValue_isDoubleArray (RaveValue_t *self)
 Returns if the rave value can be represented as a double array (list of double only)
 
RaveValue_tRaveValue_createDoubleArray (double *value, int len)
 Creates a double array rave value.
 
int RaveValue_setDoubleArray (RaveValue_t *self, double *value, int len)
 Sets the value as a simple 1-dimensional double array.
 
int RaveValue_getDoubleArray (RaveValue_t *self, double **value, int *len)
 Returns the value as a double array.
 
RaveValue_tRaveValue_createHashTable (RaveObjectHashTable_t *hashtable)
 Creates a rave value hash table.
 
int RaveValue_setHashTable (RaveValue_t *self, RaveObjectHashTable_t *table)
 Sets the value as a hash table.
 
int RaveValue_getHashTable (RaveValue_t *self, RaveObjectHashTable_t **table)
 Returns the hash table if possible.
 
RaveObjectHashTable_tRaveValue_toHashTable (RaveValue_t *self)
 NOTE!
 
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.
 
RaveValue_tRaveValueHash_get (RaveValue_t *self, const char *key)
 If rave value is hash, then this provides same functionality as RaveObjectHashTable_get.
 
int RaveValueHash_size (RaveValue_t *self)
 If rave value is hash, then this provides same functionality as RaveObjectHashTable_size.
 
int RaveValueHash_exists (RaveValue_t *self, const char *key)
 If rave value is hash, then this provides same functionality as RaveObjectHashTable_exists.
 
void RaveValueHash_remove (RaveValue_t *self, const char *key)
 If rave value is hash, then this provides same functionality as RaveObjectHashTable_remove except that the value is destrouyed.
 
void RaveValueHash_clear (RaveValue_t *self)
 If rave value is hash, then this provides same functionality as RaveObjectHashTable_clear.
 
RaveList_tRaveValueHash_keys (RaveValue_t *self)
 If rave value is hash, then this provides same functionality as RaveObjectHashTable_keys.
 
RaveValue_tRaveValue_createList (RaveObjectList_t *rlist)
 Creates a rave value list.
 
int RaveValue_setList (RaveValue_t *self, RaveObjectList_t *rlist)
 Sets the value as a rave list.
 
int RaveValue_getList (RaveValue_t *self, RaveObjectList_t **rlist)
 Returns the rave list if possible.
 
RaveObjectList_tRaveValue_toList (RaveValue_t *self)
 NOTE!
 
int RaveValueList_add (RaveValue_t *self, RaveValue_t *value)
 If rave value is list, then this provides same functionality as RaveObjectList_add.
 
int RaveValueList_insert (RaveValue_t *self, int index, RaveValue_t *value)
 If rave value is list, then this provides same functionality as RaveObjectList_insert.
 
int RaveValueList_size (RaveValue_t *self)
 If rave value is list, then this provides same functionality as RaveObjectList_size.
 
RaveValue_tRaveValueList_get (RaveValue_t *self, int index)
 If rave value is list, then this provides same functionality as RaveObjectList_get.
 
void RaveValueList_release (RaveValue_t *self, int index)
 If rave value is list, then this provides same functionality as RaveObjectList_release.
 
void RaveValueList_clear (RaveValue_t *self)
 If rave value is list, then this provides same functionality as RaveObjectList_clear.
 
char * RaveValue_toJSON (RaveValue_t *self)
 Translates self to a json representation.
 
RaveValue_tRaveValue_fromJSON (const char *json)
 Support function for translating a json structure to a rave value.
 
RaveValue_tRaveValue_loadJSON (const char *filename)
 Loads a JSON object from a file.
 

Variables

RaveCoreObjectType RaveValue_TYPE
 Type definition to use when creating a rave object.
 

Detailed Description

Data value abstraction.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2025-02-14

Function Documentation

◆ RaveValue_createBoolean()

RaveValue_t * RaveValue_createBoolean ( int value)

Creates a boolean rave value.

Parameters
[in]value- the boolean. 0 means false, other values means true
Returns
the value on success otherwise NULL

◆ RaveValue_createDouble()

RaveValue_t * RaveValue_createDouble ( double value)

Creates a double rave value.

Parameters
[in]value- the double
Returns
the value on success otherwise NULL

◆ RaveValue_createDoubleArray()

RaveValue_t * RaveValue_createDoubleArray ( double * value,
int len )

Creates a double array rave value.

Parameters
[in]value- the double array
[in]len- the length of the array
Returns
the value on success otherwise NULL

◆ RaveValue_createHashTable()

RaveValue_t * RaveValue_createHashTable ( RaveObjectHashTable_t * hashtable)

Creates a rave value hash table.

Parameters
[in]hashtable- the hashtable
Returns
the rave value on success otherwise NULL

◆ RaveValue_createList()

RaveValue_t * RaveValue_createList ( RaveObjectList_t * rlist)

Creates a rave value list.

Parameters
[in]rlist- the rave list
Returns
the rave value on success otherwise NULL

◆ RaveValue_createLong()

RaveValue_t * RaveValue_createLong ( long value)

Creates a long rave value.

Parameters
[in]value- the long
Returns
the value on success otherwise NULL

◆ RaveValue_createLongArray()

RaveValue_t * RaveValue_createLongArray ( long * value,
int len )

Creates a long array rave value.

Parameters
[in]value- the long array
[in]len- the length of the array
Returns
the value on success otherwise NULL

◆ RaveValue_createNull()

RaveValue_t * RaveValue_createNull ( )

Creates a null rave value.

Parameters
[in]value- the null value
Returns
the value on success otherwise NULL

◆ RaveValue_createString()

RaveValue_t * RaveValue_createString ( const char * value)

Creates a string rave value.

Parameters
[in]value- the string
Returns
the value on success otherwise NULL

◆ RaveValue_createStringArray()

RaveValue_t * RaveValue_createStringArray ( const char ** value,
int len )

Creates a string array rave value.

Parameters
[in]value- the string array
[in]len- the length of the array
Returns
the value on success otherwise NULL

◆ RaveValue_fromJSON()

RaveValue_t * RaveValue_fromJSON ( const char * json)

Support function for translating a json structure to a rave value.

Parameters
[in]json- the json string
Returns
the rave value

◆ RaveValue_getBoolean()

int RaveValue_getBoolean ( RaveValue_t * self,
int * value )

Returns the value as a boolean.

Parameters
[in]self- self
[out]value- the boolean value
Returns
1 on success or 0 if format of the data not is a boolean

◆ RaveValue_getDouble()

int RaveValue_getDouble ( RaveValue_t * self,
double * value )

Returns the value as a double.

Parameters
[in]self- self
[out]value- the double value
Returns
1 on success or 0 if format of the data not is a double

◆ RaveValue_getDoubleArray()

int RaveValue_getDoubleArray ( RaveValue_t * self,
double ** value,
int * len )

Returns the value as a double array.

Parameters
[in]self- self
[out]value- the double array, Release memory
[out]len- the number of values in the array
Returns
1 on success or 0 if format of the data not is a double array

◆ RaveValue_getHashTable()

int RaveValue_getHashTable ( RaveValue_t * self,
RaveObjectHashTable_t ** table )

Returns the hash table if possible.

Parameters
[in]self
[out]table- a reference to the hash table
Returns
1 if value is a hash table otherwise 0

◆ RaveValue_getList()

int RaveValue_getList ( RaveValue_t * self,
RaveObjectList_t ** rlist )

Returns the rave list if possible.

Parameters
[in]self
[out]rlist- a reference to the rave list
Returns
1 if value is a rave list otherwise 0

◆ RaveValue_getLong()

int RaveValue_getLong ( RaveValue_t * self,
long * value )

Returns the value as a long.

Parameters
[in]self- self
[out]value- the long value
Returns
1 on success or 0 if format of the data not is a long

◆ RaveValue_getLongArray()

int RaveValue_getLongArray ( RaveValue_t * self,
long ** value,
int * len )

Returns the value as a long array.

Parameters
[in]self- self
[out]value- the long array, Release memory
[out]len- the number of values in the array
Returns
1 on success or 0 if format of the data not is a long array

◆ RaveValue_getString()

int RaveValue_getString ( RaveValue_t * self,
char ** value )

Returns the value as a string.

Parameters
[in]self- self
[out]value- the internal 0-terminated string, DO NOT RELEASE memory
Returns
1 on success or 0 if format of the data not is a string

◆ RaveValue_getStringArray()

int RaveValue_getStringArray ( RaveValue_t * self,
char *** value,
int * len )

Returns the value as a string array.

Parameters
[in]self- self
[out]value- the a string array. Release memory.
[out]len- the number of values in the array
Returns
1 on success or 0 if format of the data not is a double array

◆ RaveValue_isDoubleArray()

int RaveValue_isDoubleArray ( RaveValue_t * self)

Returns if the rave value can be represented as a double array (list of double only)

Parameters
[in]self- self
Returns
1 if possible otherwise 0

◆ RaveValue_isLongArray()

int RaveValue_isLongArray ( RaveValue_t * self)

Returns if the rave value can be represented as a long array (list of long only)

Parameters
[in]self- self
Returns
1 if possible otherwise 0

◆ RaveValue_isNull()

int RaveValue_isNull ( RaveValue_t * self)

Returns if the value is null or not.

Parameters
[in]self- self
Returns
1 if null, otherwise 0

◆ RaveValue_isStringArray()

int RaveValue_isStringArray ( RaveValue_t * self)

Returns if the rave value can be represented as a string array (list of strings only)

Parameters
[in]self- self
Returns
1 if possible otherwise 0

◆ RaveValue_loadJSON()

RaveValue_t * RaveValue_loadJSON ( const char * filename)

Loads a JSON object from a file.

Parameters
[in]filename- the filename
Returns
the read JSON object

◆ RaveValue_reset()

void RaveValue_reset ( RaveValue_t * self)

Resets the value object.

Parameters
[in]self- self

◆ RaveValue_setBoolean()

void RaveValue_setBoolean ( RaveValue_t * self,
int value )

Sets the value as a boolean.

Parameters
[in]self- self
[in]value- the value

◆ RaveValue_setDouble()

void RaveValue_setDouble ( RaveValue_t * self,
double value )

Sets the value as a double.

Parameters
[in]self- self
[in]value- the value

◆ RaveValue_setDoubleArray()

int RaveValue_setDoubleArray ( RaveValue_t * self,
double * value,
int len )

Sets the value as a simple 1-dimensional double array.

Parameters
[in]self- self
[in]value- the value
[in]len- the number of doubles in the array
Returns
1 on success otherwise 0

◆ RaveValue_setHashTable()

int RaveValue_setHashTable ( RaveValue_t * self,
RaveObjectHashTable_t * table )

Sets the value as a hash table.

Parameters
[in]self- self
[in]table- the object hash table.
Returns
1 on success or 0 if not settable

◆ RaveValue_setList()

int RaveValue_setList ( RaveValue_t * self,
RaveObjectList_t * rlist )

Sets the value as a rave list.

Parameters
[in]self- self
[in]rlist- the object list.
Returns
1 on success or 0 if not settable

◆ RaveValue_setLong()

void RaveValue_setLong ( RaveValue_t * self,
long value )

Sets the value as a long.

Parameters
[in]self- self
[in]value- the value

◆ RaveValue_setLongArray()

int RaveValue_setLongArray ( RaveValue_t * self,
long * value,
int len )

Sets the value as a simple 1-dimensional long array.

Parameters
[in]self- self
[in]value- the value
[in]len- the number of longs in the array
Returns
1 on success otherwise 0

◆ RaveValue_setNull()

void RaveValue_setNull ( RaveValue_t * self)

Sets the value as a null value.

Parameters
[in]self- self

◆ RaveValue_setString()

int RaveValue_setString ( RaveValue_t * self,
const char * value )

Sets a string value in self.

Parameters
[in]self- self
[in]value- the value
Returns
1 on success otherwise 0

◆ RaveValue_setStringArray()

int RaveValue_setStringArray ( RaveValue_t * self,
const char ** value,
int len )

Sets the value as a simple 1-dimensional string array.

Parameters
[in]self- self
[in]value- the value
[in]len- the number of doubles in the array
Returns
1 on success otherwise 0

◆ RaveValue_toBoolean()

int RaveValue_toBoolean ( RaveValue_t * self)

Returns the boolean value.

NOTE! It up to user to ensure that value actually is a boolean otherwise behavior will be undefined.

Parameters
[in]self- self
Returns
the boolean or -

◆ RaveValue_toDouble()

double RaveValue_toDouble ( RaveValue_t * self)

Returns the double value.

NOTE! It up to user to ensure that value actually is a double otherwise behavior will be undefined.

Parameters
[in]self- self
Returns
the double value or -

◆ RaveValue_toHashTable()

RaveObjectHashTable_t * RaveValue_toHashTable ( RaveValue_t * self)

NOTE!

It up to user to ensure that value actually is a hash table otherwise behavior will be undefined.

Parameters
[in]self- self
Returns
the hash table or NULL

◆ RaveValue_toJSON()

char * RaveValue_toJSON ( RaveValue_t * self)

Translates self to a json representation.

Parameters
[in]self- self
Returns
the json representation of self.

◆ RaveValue_toList()

RaveObjectList_t * RaveValue_toList ( RaveValue_t * self)

NOTE!

It up to user to ensure that value actually is a rave list otherwise behavior will be undefined.

Parameters
[in]self- self
Returns
the rave list or NULL

◆ RaveValue_toLong()

long RaveValue_toLong ( RaveValue_t * self)

Returns the long value.

NOTE! It up to user to ensure that value actually is a long otherwise behavior will be undefined.

Parameters
[in]self- self
Returns
the long value or 0

◆ RaveValue_toString()

const char * RaveValue_toString ( RaveValue_t * self)

Returns the string value.

NOTE! It up to user to ensure that value actually is a string otherwise behavior will be undefined.

Parameters
[in]self- self
Returns
the string value or NULL

◆ RaveValue_type()

RaveValue_Type RaveValue_type ( RaveValue_t * self)

Returns the format for this attribute.

Parameters
[in]self- self
Returns
the format

◆ RaveValueHash_clear()

void RaveValueHash_clear ( RaveValue_t * self)

If rave value is hash, then this provides same functionality as RaveObjectHashTable_clear.

Parameters
[in]self- self

◆ RaveValueHash_exists()

int RaveValueHash_exists ( RaveValue_t * self,
const char * key )

If rave value is hash, then this provides same functionality as RaveObjectHashTable_exists.

Parameters
[in]self- self
[in]key- the key
Returns
1 if exists, otherwise 0

◆ RaveValueHash_get()

RaveValue_t * RaveValueHash_get ( RaveValue_t * self,
const char * key )

If rave value is hash, then this provides same functionality as RaveObjectHashTable_get.

Parameters
[in]self- self
[in]key- the key
Returns
the rave value or NULL if not possible

◆ RaveValueHash_keys()

RaveList_t * RaveValueHash_keys ( RaveValue_t * self)

If rave value is hash, then this provides same functionality as RaveObjectHashTable_keys.

Parameters
[in]self- self
Returns
the keys or NULL

◆ RaveValueHash_put()

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.

Parameters
[in]self- self
[in]key- the key
[in]value- the rave value
Returns
1 if ok, otherwise 0

◆ RaveValueHash_remove()

void RaveValueHash_remove ( RaveValue_t * self,
const char * key )

If rave value is hash, then this provides same functionality as RaveObjectHashTable_remove except that the value is destrouyed.

Parameters
[in]self- self
[in]key- the key

◆ RaveValueHash_size()

int RaveValueHash_size ( RaveValue_t * self)

If rave value is hash, then this provides same functionality as RaveObjectHashTable_size.

Parameters
[in]self- self
Returns
the number of items in this self.

◆ RaveValueList_add()

int RaveValueList_add ( RaveValue_t * self,
RaveValue_t * value )

If rave value is list, then this provides same functionality as RaveObjectList_add.

Parameters
[in]self- self
[in]value- the value
Returns
1 on success otherwise 0

◆ RaveValueList_clear()

void RaveValueList_clear ( RaveValue_t * self)

If rave value is list, then this provides same functionality as RaveObjectList_clear.

Parameters
[in]self- self

◆ RaveValueList_get()

RaveValue_t * RaveValueList_get ( RaveValue_t * self,
int index )

If rave value is list, then this provides same functionality as RaveObjectList_get.

Parameters
[in]self- self
[in]index- the index
Returns
the value if possible otherwise NULL

◆ RaveValueList_insert()

int RaveValueList_insert ( RaveValue_t * self,
int index,
RaveValue_t * value )

If rave value is list, then this provides same functionality as RaveObjectList_insert.

Parameters
[in]self- self
[in]index- the index where to insert the value
[in]value- the value
Returns
1 on success otherwise 0

◆ RaveValueList_release()

void RaveValueList_release ( RaveValue_t * self,
int index )

If rave value is list, then this provides same functionality as RaveObjectList_release.

Parameters
[in]self- self
[in]index- the index

◆ RaveValueList_size()

int RaveValueList_size ( RaveValue_t * self)

If rave value is list, then this provides same functionality as RaveObjectList_size.

Parameters
[in]self- self
Returns
the size of the list

Variable Documentation

◆ RaveValue_TYPE

RaveCoreObjectType RaveValue_TYPE
Initial value:
= {
"RaveValue",
sizeof(RaveValue_t),
RaveValue_constructor,
RaveValue_destructor,
RaveValue_copyconstructor
}
struct _RaveValue_t RaveValue_t
Defines a rave value.
Definition rave_value.h:47

Type definition to use when creating a rave object.