RAVE
rave_utilities.c File Reference

Contains various utility functions that makes life easier when working with the rave framework. More...

#include "rave_utilities.h"
#include "rave_object.h"
#include "rave_debug.h"
#include "rave_alloc.h"
#include <string.h>
#include <stdio.h>

Functions

int RaveUtilities_addLongAttributeToList (RaveObjectList_t *l, const char *name, long value)
 Adds a long attribute to an object list.
 
int RaveUtilities_addDoubleAttributeToList (RaveObjectList_t *l, const char *name, double value)
 Adds a double attribute to an object list.
 
int RaveUtilities_addStringAttributeToList (RaveObjectList_t *l, const char *name, const char *value)
 Adds a string attribute to an object list.
 
int RaveUtilities_replaceLongAttributeInList (RaveObjectList_t *l, const char *name, long value)
 Replaces the content of a attribute in the object list.
 
int RaveUtilities_replaceDoubleAttributeInList (RaveObjectList_t *l, const char *name, double value)
 Replaces the content of a attribute in the object list.
 
int RaveUtilities_replaceStringAttributeInList (RaveObjectList_t *l, const char *name, const char *value)
 Replaces the content of a attribute in the object list.
 
void RaveUtilities_removeAttributeFromList (RaveObjectList_t *l, const char *name)
 Removes the rave attribute with specified name from the list.
 
int RaveUtilities_getRaveAttributeDoubleFromHash (RaveObjectHashTable_t *h, const char *name, double *v)
 Gets the double value from a rave attribute that resides in a hash table.
 
int RaveUtilities_iswhitespace (char c)
 Returns if the character is a whitespace character or not, i.e.
 
char * RaveUtilities_trimText (const char *str, int len)
 Trims the text from all leading and trailing whitespaces.
 
RaveList_tRaveUtilities_getTrimmedTokens (const char *str, int c)
 Returns a list of tokens delimited by 'c'.
 
int RaveUtilities_isXmlSupported (void)
 Returns if xml support is activated or not since expat support is optional and ought to be tested.
 
int RaveUtilities_isCFConventionSupported (void)
 Returns if CF convention IO support is activated or not.
 
int RaveUtilities_isLegacyProjEnabled (void)
 Returns if legacy PROJ (PROJ.4 and PROJ 5) is enabled or not.
 
char * RaveUtilities_handleSourceVersion (const char *source, RaveIO_ODIM_Version version)
 Handles the source value according to version.
 
int RaveUtilities_isSourceValid (const char *source, RaveIO_ODIM_Version version)
 Verifies if the source is valid according to ODIM version rules.
 

Detailed Description

Contains various utility functions that makes life easier when working with the rave framework.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2010-06-10

Function Documentation

◆ RaveUtilities_addDoubleAttributeToList()

int RaveUtilities_addDoubleAttributeToList ( RaveObjectList_t * l,
const char * name,
double value )

Adds a double attribute to an object list.

Parameters
[in]l- the list
[in]name- the name of the attribute
[in]value- the double
Returns
1 on success otherwise 0

◆ RaveUtilities_addLongAttributeToList()

int RaveUtilities_addLongAttributeToList ( RaveObjectList_t * l,
const char * name,
long value )

Adds a long attribute to an object list.

Parameters
[in]l- the list
[in]name- the name of the attribute
[in]value- the long
Returns
1 on success otherwise 0

◆ RaveUtilities_addStringAttributeToList()

int RaveUtilities_addStringAttributeToList ( RaveObjectList_t * l,
const char * name,
const char * value )

Adds a string attribute to an object list.

Parameters
[in]l- the list
[in]name- the name of the attribute
[in]value- the string
Returns
1 on success otherwise 0

◆ RaveUtilities_getRaveAttributeDoubleFromHash()

int RaveUtilities_getRaveAttributeDoubleFromHash ( RaveObjectHashTable_t * h,
const char * name,
double * v )

Gets the double value from a rave attribute that resides in a hash table.

Parameters
[in]h- the hash table
[in]name- the name
[in,out]v- the value
Returns
1 on success otherwise 0

◆ RaveUtilities_getTrimmedTokens()

RaveList_t * RaveUtilities_getTrimmedTokens ( const char * str,
int c )

Returns a list of tokens delimited by 'c'.

The tokens will be trimmed from any leading and trailing whitespaces.

Parameters
[in]str- the string to tokenize
[in]c- the delimiter
Returns
a list of tokens, use RaveList_freeAndDestroy to delete

◆ RaveUtilities_handleSourceVersion()

char * RaveUtilities_handleSourceVersion ( const char * source,
RaveIO_ODIM_Version version )

Handles the source value according to version.

For example, if version < 2.3, then WIGOS will be removed.

Parameters
[in]source- source to be verified
[in]version- what version we want to validate against.
Returns
the modified version. Note, should be freed with RAVE_FREE.

◆ RaveUtilities_isCFConventionSupported()

int RaveUtilities_isCFConventionSupported ( void )

Returns if CF convention IO support is activated or not.

Returns
0 if CF convention IO isn't supported in the build, otherwise 1

◆ RaveUtilities_isLegacyProjEnabled()

int RaveUtilities_isLegacyProjEnabled ( void )

Returns if legacy PROJ (PROJ.4 and PROJ 5) is enabled or not.

Returns
0 if legacy PROJ isn't enabled in the build, otherwise 1

◆ RaveUtilities_isSourceValid()

int RaveUtilities_isSourceValid ( const char * source,
RaveIO_ODIM_Version version )

Verifies if the source is valid according to ODIM version rules.

Currently the only restriction is for version >= 2.4 which says that either NOD or ORG must exist in the file depending on object type. We will not care about object type and only check if one or both of NOD or ORG exists.

Parameters
[in]source- the source to check
[in]version- the version we are testing against.
Returns
1 if source is valid, otherwise 0

◆ RaveUtilities_iswhitespace()

int RaveUtilities_iswhitespace ( char c)

Returns if the character is a whitespace character or not, i.e.

' ', '\t', '\r' or '
'

Parameters
[in]c- the character to check
Returns
true if character is a whitespace otherwise 0

◆ RaveUtilities_isXmlSupported()

int RaveUtilities_isXmlSupported ( void )

Returns if xml support is activated or not since expat support is optional and ought to be tested.

Returns
0 if xml isn't supported in the build, otherwise 1

◆ RaveUtilities_removeAttributeFromList()

void RaveUtilities_removeAttributeFromList ( RaveObjectList_t * l,
const char * name )

Removes the rave attribute with specified name from the list.

Parameters
[in]l- the list
[in]name- the name

◆ RaveUtilities_replaceDoubleAttributeInList()

int RaveUtilities_replaceDoubleAttributeInList ( RaveObjectList_t * l,
const char * name,
double value )

Replaces the content of a attribute in the object list.

If the attribute does not exist a new one will be created.

Parameters
[in]l- the list
[in]name- the name of the attribute
[in]value- the double
Returns
1 on success otherwise 0

◆ RaveUtilities_replaceLongAttributeInList()

int RaveUtilities_replaceLongAttributeInList ( RaveObjectList_t * l,
const char * name,
long value )

Replaces the content of a attribute in the object list.

If the attribute does not exist a new one will be created.

Parameters
[in]l- the list
[in]name- the name of the attribute
[in]value- the long
Returns
1 on success otherwise 0

◆ RaveUtilities_replaceStringAttributeInList()

int RaveUtilities_replaceStringAttributeInList ( RaveObjectList_t * l,
const char * name,
const char * value )

Replaces the content of a attribute in the object list.

If the attribute does not exist a new one will be created.

Parameters
[in]l- the list
[in]name- the name of the attribute
[in]value- the string
Returns
1 on success otherwise 0

◆ RaveUtilities_trimText()

char * RaveUtilities_trimText ( const char * str,
int len )

Trims the text from all leading and trailing whitespaces.

Parameters
[in]str- the string to trim
[in]len- the length of the string to trim
Returns
a new trimmed string, release with RAVE_FREE