all repos — mgba @ e884bc4d7acafd1844fa8d645bcd345fc588d037

mGBA Game Boy Advance Emulator

Util: Add helper functions for setting overloaded Configuration types
Jeffrey Pfau jeffrey@endrift.com
Tue, 04 Nov 2014 23:48:09 -0800
commit

e884bc4d7acafd1844fa8d645bcd345fc588d037

parent

11bf4fdfdad16a2a3b8059d652f41c2c6b2e2581

2 files changed, 24 insertions(+), 0 deletions(-)

jump to
M src/util/configuration.csrc/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.hsrc/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);