A simple .ini file interface.

Dependents:   Smart-WiFly-WebServer SignalGenerator WattEye X10Svr

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Wed Mar 26 11:20:18 2014 +0000
Parent:
4:70042853d43b
Child:
6:cd28ab597256
Commit message:
Update to permit deferring the filespec to later, which also permits changing the filespec w/o having to destroy and reconstruct the object.

Changed in this revision

IniManager.cpp Show annotated file Show diff for this revision Revisions of this file
IniManager.h Show annotated file Show diff for this revision Revisions of this file
--- a/IniManager.cpp	Sun Mar 16 22:23:11 2014 +0000
+++ b/IniManager.cpp	Wed Mar 26 11:20:18 2014 +0000
@@ -31,6 +31,8 @@
         iniFile = (char *)malloc(strlen(file)+1);
         if (iniFile)
             strcpy(iniFile, file);
+        else
+            iniFile = NULL;
     }
 }
 
@@ -42,6 +44,22 @@
 }
 
 
+bool INI::SetFile(const char * file)
+{
+    if (file) {
+        if (iniFile)
+            free(iniFile);
+        iniFile = (char *)malloc(strlen(file)+1);
+        if (iniFile) {
+            strcpy(iniFile, file);
+            return true;
+        }
+        else
+            iniFile = NULL;        
+    }
+    return false;
+}
+
 bool INI::ReadString(const char * section, const char * key, char * buffer, size_t bufferSize, const char * defaultString)
 {
     bool found = false;
--- a/IniManager.h	Sun Mar 16 22:23:11 2014 +0000
+++ b/IniManager.h	Wed Mar 26 11:20:18 2014 +0000
@@ -35,7 +35,7 @@
     *       a private copy of the filename. Be sure that this parameter
     *       has the right path prefix based on what file system you have.
     */
-    INI(const char * file);
+    INI(const char * file = NULL);
 
     /** destructor for the ini manager.
     *
@@ -43,6 +43,16 @@
     */
     ~INI(void);
 
+    /** set the file to use
+    *
+    * If not set at the time of construction, or if a change is needed, this
+    * API can be used.
+    *
+    * @param file is the filename to manage.
+    * @returns true if success, false if memory could not be allocated.
+    */
+    bool SetFile(const char * file);
+
     /** Read a string from the ini file - if it exists.
     *
     * This searches the ini file for the named section and key and if found it will