Simple config file class with added support for floats
Fork of ConfigFile by
Revision 2:ba316099c799, committed 2011-01-27
- Comitter:
- pbrier
- Date:
- Thu Jan 27 21:36:01 2011 +0000
- Parent:
- 1:a802df951169
- Child:
- 3:31c936f3b9df
- Commit message:
- 1.1
Changed in this revision
ConfigFile.cpp | Show annotated file Show diff for this revision Revisions of this file |
ConfigFile.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ConfigFile.cpp Thu Jan 27 21:23:19 2011 +0000 +++ b/ConfigFile.cpp Thu Jan 27 21:36:01 2011 +0000 @@ -1,4 +1,4 @@ -/* +/** * ConfigFile.cpp * Simple Config file reader class * @@ -22,21 +22,14 @@ */ #include "ConfigFile.h" -/// Make new config file object -/** Open config file. - * Note: the file handle is kept open during the lifetime of this object. - * To close the file: destroy this ConfigFile object! - * @param file Filename of the configuration file. - */ +// Make new config file object ConfigFile::ConfigFile(char *file) { // printf("ConfigFile(%s)\n\r", file); fp = fopen(file,"rb"); } - /** - * Destroy a config file (closes the file handle) - */ +// Destroy a config file (closes the file handle) ConfigFile::~ConfigFile() { // printf("~ConfigFile()\n\r"); @@ -44,7 +37,7 @@ fclose(fp); } - +// Read value bool ConfigFile::Value(char *key, char *value, size_t maxlen, char *def) { int m=0,n=0,c,s=0; @@ -122,17 +115,11 @@ } } - -/** Read Integer value. If file is not open, or key does not exist: copy default value (return false) - * @param key name of the key in the file - * @param value pointer to integer that receives the value - * @param def Default value. If the key is not found in the file, this value is copied. - * @return "true" if the key is found "false" is key is not found (default value is returned) - */ +// Read int value bool ConfigFile::Value(char *key, int *value, int def) { char val[16]; - bool b = Value(key, val, 15, ""); + bool b = Value(key, val, 12, ""); if ( b ) *value = atoi(val); else
--- a/ConfigFile.h Thu Jan 27 21:23:19 2011 +0000 +++ b/ConfigFile.h Thu Jan 27 21:36:01 2011 +0000 @@ -1,4 +1,4 @@ -/* +/** * ConfigFile.cpp * Simple Config file reader class * @@ -38,18 +38,24 @@ #define _CONFIG_FILE_H_ /** Simple config file object + * Only supports reading config files. Tries to limit memory usage. * Note: the file handle is kept open during the lifetime of this object. * To close the file: destroy this ConfigFile object! A simple way is to enclose the creation * of this object inside a code block * Example: * @code - * bla + * char ip[16]; + * int port; + * { + * ConfigFile cfg("/local/config.txt"); + * cfg.Value("ip", val, sizeof(val), "192.168.1.10"); + * cfg.Value("port", &port, 80); + * } * @endcode */ class ConfigFile { public: - /// Make new config file object - /** Open config file. + /** Make new ConfigFile object. Open config file. * Note: the file handle is kept open during the lifetime of this object. * To close the file: destroy this ConfigFile object! * @param file Filename of the configuration file.