conf: introduce WithDefault function

This patch introduces a new set of functions to the ConfGetChildValue
family. They permit to look under a default node if looking under
base node as failed. This will be used to access to default parameters
for a data type (for instance, first usage will be interface).
pull/262/head
Eric Leblond 13 years ago
parent 6b81430bcb
commit 0bddf4f02f

@ -286,6 +286,17 @@ int ConfGetChildValue(ConfNode *base, char *name, char **vptr)
}
}
int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, char **vptr)
{
int ret = ConfGetChildValue(base, name, vptr);
/* Get 'default' value */
if (ret == 0 && dflt) {
return ConfGetChildValue(dflt, name, vptr);
}
return ret;
}
/**
* \brief Retrieve a configuration value as an integer.
*
@ -337,6 +348,15 @@ int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val)
}
int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name, intmax_t *val)
{
int ret = ConfGetChildValueInt(base, name, val);
/* Get 'default' value */
if (ret == 0 && dflt) {
return ConfGetChildValueInt(dflt, name, val);
}
return ret;
}
/**
@ -376,6 +396,17 @@ int ConfGetChildValueBool(ConfNode *base, char *name, int *val)
return 1;
}
int ConfGetChildValueBoolWithDefault(ConfNode *base, ConfNode *dflt, char *name, int *val)
{
int ret = ConfGetChildValueBool(base, name, val);
/* Get 'default' value */
if (ret == 0 && dflt) {
return ConfGetChildValueBool(dflt, name, val);
}
return ret;
}
/**
* \brief Check if a value is true.
*

@ -80,6 +80,9 @@ ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *va
int ConfGetChildValue(ConfNode *base, char *name, char **vptr);
int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val);
int ConfGetChildValueBool(ConfNode *base, char *name, int *val);
int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, char **vptr);
int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name, intmax_t *val);
int ConfGetChildValueBoolWithDefault(ConfNode *base, ConfNode *dflt, char *name, int *val);
char *ConfLoadCompleteIncludePath(char *);
#endif /* ! __CONF_H__ */

Loading…
Cancel
Save