aqhome: added PATH module, started VARS module.
those might later get incorporated into libgwenhywfar.
This commit is contained in:
273
aqhome/data/vars.c
Normal file
273
aqhome/data/vars.c
Normal file
@@ -0,0 +1,273 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project Gwenhywfar.
|
||||
* Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include "./vars_p.h"
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
|
||||
GWEN_TREE2_FUNCTIONS(AQH_VARS, AQH_Vars);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static AQH_VARS *_newData(void);
|
||||
static void _releaseData(AQH_VARS *vt);
|
||||
static AQH_VARS *_newStringElement(char *s, AQH_VARS_DATATYPE dt);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
AQH_VARS *_newData(void)
|
||||
{
|
||||
AQH_VARS *vt;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_VARS, vt);
|
||||
GWEN_TREE2_INIT(AQH_VARS, vt, AQH_Vars);
|
||||
return vt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *_newStringElement(char *s, AQH_VARS_DATATYPE dt)
|
||||
{
|
||||
AQH_VARS *vt;
|
||||
|
||||
vt=_newData();
|
||||
vt->data.dataString=s;
|
||||
vt->dataType=dt;
|
||||
|
||||
return vt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void _releaseData(AQH_VARS *vt)
|
||||
{
|
||||
if (vt) {
|
||||
switch(vt->dataType) {
|
||||
case AQH_Vars_DataType_Group:
|
||||
case AQH_Vars_DataType_Variable:
|
||||
case AQH_Vars_DataType_ValueString:
|
||||
free(vt->data.dataString);
|
||||
vt->data.dataString=NULL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
vt->dataType=AQH_Vars_DataType_Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Vars_free(AQH_VARS *vt)
|
||||
{
|
||||
if (vt) {
|
||||
GWEN_TREE2_FINI(AQH_VARS, vt, AQH_Vars);
|
||||
_releaseData(vt);
|
||||
GWEN_FREE_OBJECT(vt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_CreateGroup(char *s)
|
||||
{
|
||||
return _newStringElement(s, AQH_Vars_DataType_Group);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_CreateVariable(char *s)
|
||||
{
|
||||
return _newStringElement(s, AQH_Vars_DataType_Variable);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_CreateStringValue(char *s)
|
||||
{
|
||||
return _newStringElement(s, AQH_Vars_DataType_ValueString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_CreateIntValue(int d)
|
||||
{
|
||||
AQH_VARS *vt;
|
||||
|
||||
vt=_newData();
|
||||
vt->data.dataInt=d;
|
||||
vt->dataType=AQH_Vars_DataType_ValueInt;
|
||||
|
||||
return vt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_CreateDoubleValue(double d)
|
||||
{
|
||||
AQH_VARS *vt;
|
||||
|
||||
vt=_newData();
|
||||
vt->data.dataDouble=d;
|
||||
vt->dataType=AQH_Vars_DataType_ValueDouble;
|
||||
|
||||
return vt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS_DATATYPE AQH_Vars_GetDataType(const AQH_VARS *vt)
|
||||
{
|
||||
return vt?vt->dataType:AQH_Vars_DataType_Unknown;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_Vars_GetFlags(const AQH_VARS *vt)
|
||||
{
|
||||
return vt?vt->flags:0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQH_Vars_GetStringData(const AQH_VARS *vt, const char *defValue)
|
||||
{
|
||||
if (vt) {
|
||||
switch(vt->dataType) {
|
||||
case AQH_Vars_DataType_Group:
|
||||
case AQH_Vars_DataType_Variable:
|
||||
case AQH_Vars_DataType_ValueString:
|
||||
return vt->data.dataString;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Vars_SetStringData(AQH_VARS *vt, char *s)
|
||||
{
|
||||
if (vt) {
|
||||
_releaseData(vt);
|
||||
vt->data.dataString=s;
|
||||
vt->dataType=AQH_Vars_DataType_ValueString;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_Vars_GetIntData(const AQH_VARS *vt, int defValue)
|
||||
{
|
||||
if (vt && vt->dataType==AQH_Vars_DataType_ValueInt)
|
||||
return vt->data.dataInt;
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Vars_SetIntData(AQH_VARS *vt, int d)
|
||||
{
|
||||
if (vt) {
|
||||
_releaseData(vt);
|
||||
vt->data.dataInt=d;
|
||||
vt->dataType=AQH_Vars_DataType_ValueInt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
double AQH_Vars_GetDoubleData(const AQH_VARS *vt, double defValue)
|
||||
{
|
||||
if (vt && vt->dataType==AQH_Vars_DataType_ValueDouble)
|
||||
return vt->data.dataDouble;
|
||||
|
||||
return defValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_Vars_SetDoubleData(AQH_VARS *vt, double d)
|
||||
{
|
||||
if (vt) {
|
||||
_releaseData(vt);
|
||||
vt->data.dataDouble=d;
|
||||
vt->dataType=AQH_Vars_DataType_ValueDouble;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_GetFirstChildByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt)
|
||||
{
|
||||
if (vt) {
|
||||
AQH_VARS *vtChild;
|
||||
|
||||
vtChild=AQH_Vars_Tree2_GetFirstChild(vt);
|
||||
while(vtChild) {
|
||||
if (vtChild->dataType==dt)
|
||||
return vtChild;
|
||||
vtChild=AQH_Vars_Tree2_GetNext(vtChild);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt)
|
||||
{
|
||||
if (vt) {
|
||||
AQH_VARS *vtNext;
|
||||
|
||||
vtNext=AQH_Vars_Tree2_GetNext(vt);
|
||||
while(vtNext) {
|
||||
if (vtNext->dataType==dt)
|
||||
return vtNext;
|
||||
vtNext=AQH_Vars_Tree2_GetNext(vtNext);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user