From e884bc4d7acafd1844fa8d645bcd345fc588d037 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 4 Nov 2014 23:48:09 -0800 Subject: [PATCH] Util: Add helper functions for setting overloaded Configuration types --- src/util/configuration.c | 20 ++++++++++++++++++++ src/util/configuration.h | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/util/configuration.c b/src/util/configuration.c index 26b674e63..e0e7b60d0 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -4,6 +4,8 @@ #include "third-party/inih/ini.h" +#include + static void _sectionDeinit(void* string) { free(string); } @@ -53,6 +55,24 @@ void ConfigurationSetValue(struct Configuration* configuration, const char* sect } } +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) { const struct Table* currentSection = &configuration->root; if (section) { diff --git a/src/util/configuration.h b/src/util/configuration.h index 197db7c57..11983dc05 100644 --- a/src/util/configuration.h +++ b/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);