Simple config file class with added support for floats
Fork of ConfigFile by
Diff: ConfigFile.h
- Revision:
- 1:a802df951169
- Parent:
- 0:57f3e167586f
- Child:
- 2:ba316099c799
--- a/ConfigFile.h Thu Jan 27 21:08:51 2011 +0000 +++ b/ConfigFile.h Thu Jan 27 21:23:19 2011 +0000 @@ -31,20 +31,53 @@ * * note: NULL key does nothing */ - + #include "mbed.h" #ifndef _CONFIG_FILE_H_ #define _CONFIG_FILE_H_ + /** Simple config file object + * 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 + * @endcode + */ class ConfigFile { - public: +public: + /// 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. + */ ConfigFile(char *name); + ~ConfigFile(); + +/** Read 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 buffer that receives the value + * @param maxlen the maximum length of the value. If the actual value is longer, it is truncated + * @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) + */ bool Value(char *key, char *value, size_t maxlen, char *def); + +/** 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) + */ bool Value(char *key, int *value, int def); - private: + +private: FILE *fp; + }; #endif