vars: use const in most api functions

The idea of not using const was to reduce copy operations.
However, it is not very intuitive to know when and which arguments are const
so to simplify working with this new module and make it as close as possible
to GWEN_DB we use const now as in GWEN_DB.
At least AQH_Vars_SetStringData() still doesn't use const so if the need
arises to avoid copying we can.
This commit is contained in:
Martin Preuss
2024-05-09 14:56:46 +02:00
parent b6e4a5265a
commit 2c584bbff9
2 changed files with 10 additions and 15 deletions

View File

@@ -97,16 +97,16 @@ void AQH_Vars_free(AQH_VARS *vt)
AQH_VARS *AQH_Vars_CreateGroup(char *s)
AQH_VARS *AQH_Vars_CreateGroup(const char *s)
{
return _newStringElement(s, AQH_Vars_DataType_Group);
return _newStringElement(s?strdup(s):NULL, AQH_Vars_DataType_Group);
}
AQH_VARS *AQH_Vars_CreateVariable(char *s)
AQH_VARS *AQH_Vars_CreateVariable(const char *s)
{
return _newStringElement(s, AQH_Vars_DataType_Variable);
return _newStringElement(s?strdup(s):NULL, AQH_Vars_DataType_Variable);
}
@@ -265,7 +265,7 @@ AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt)
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, char *value)
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value)
{
if (vt) {
AQH_VARS *vtChild;
@@ -276,7 +276,7 @@ int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, char *
DBG_ERROR(AQH_LOGDOMAIN, "Error getting path for var \"%s\"", path);
return GWEN_ERROR_GENERIC;
}
vtValue=AQH_Vars_CreateStringValue(value);
vtValue=AQH_Vars_CreateStringValue(value?strdup(value):NULL);
AQH_Vars_Tree2_AddChild(vtChild, vtValue);
return 0;
}
@@ -397,10 +397,5 @@ AQH_VARS *_getNodeByTypeAndName(const AQH_VARS *vt, AQH_VARS_DATATYPE dt, const
#include "./vars-t.c"

View File

@@ -33,8 +33,8 @@ typedef struct AQH_VARS AQH_VARS;
GWEN_TREE2_FUNCTION_DEFS(AQH_VARS, AQH_Vars);
AQH_VARS *AQH_Vars_CreateGroup(char *s);
AQH_VARS *AQH_Vars_CreateVariable(char *s);
AQH_VARS *AQH_Vars_CreateGroup(const char *s);
AQH_VARS *AQH_Vars_CreateVariable(const char *s);
AQH_VARS *AQH_Vars_CreateStringValue(char *s);
AQH_VARS *AQH_Vars_CreateIntValue(int d);
AQH_VARS *AQH_Vars_CreateDoubleValue(double d);
@@ -59,7 +59,7 @@ AQH_VARS *AQH_Vars_GetFirstChildByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt)
AQH_VARS *AQH_Vars_GetNextByType(const AQH_VARS *vt, AQH_VARS_DATATYPE dt);
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, char *value);
int AQH_Vars_SetCharValue(AQH_VARS *vt, uint32_t flags, const char *path, const char *value);
const char *AQH_Vars_GetCharValue(AQH_VARS *vt, const char *path, int idx, const char *defaultValue);