Util: Add helper functions for setting overloaded Configuration types
Jeffrey Pfau jeffrey@endrift.com
Tue, 04 Nov 2014 23:48:09 -0800
2 files changed,
24 insertions(+),
0 deletions(-)
M
src/util/configuration.c
→
src/util/configuration.c
@@ -4,6 +4,8 @@ #include "util/vfs.h"
#include "third-party/inih/ini.h" +#include <float.h> + static void _sectionDeinit(void* string) { free(string); }@@ -51,6 +53,24 @@ HashTableInsert(currentSection, key, strdup(value));
} else { HashTableRemove(currentSection, key); } +} + +void ConfigurationSetIntValue(struct Configuration* configuration, const char* section, const char* key, int value) { + char charValue[12]; + sprintf(charValue, "%i", value); + ConfigurationSetValue(configuration, section, key, charValue); +} + +void ConfigurationSetUIntValue(struct Configuration* configuration, const char* section, const char* key, unsigned value) { + char charValue[12]; + sprintf(charValue, "%u", value); + ConfigurationSetValue(configuration, section, key, charValue); +} + +void ConfigurationSetFloatValue(struct Configuration* configuration, const char* section, const char* key, float value) { + char charValue[FLT_DIG + 7]; + sprintf(charValue, "%.*g", FLT_DIG, value); + ConfigurationSetValue(configuration, section, key, charValue); } const char* ConfigurationGetValue(const struct Configuration* configuration, const char* section, const char* key) {
M
src/util/configuration.h
→
src/util/configuration.h
@@ -14,6 +14,10 @@ void ConfigurationInit(struct Configuration*);
void ConfigurationDeinit(struct Configuration*); void ConfigurationSetValue(struct Configuration*, const char* section, const char* key, const char* value); +void ConfigurationSetIntValue(struct Configuration*, const char* section, const char* key, int value); +void ConfigurationSetUIntValue(struct Configuration*, const char* section, const char* key, unsigned value); +void ConfigurationSetFloatValue(struct Configuration*, const char* section, const char* key, float value); + const char* ConfigurationGetValue(const struct Configuration*, const char* section, const char* key); bool ConfigurationRead(struct Configuration*, const char* path);