ConfigFile

Dependents:   ConfigFile_TestProgram StarBoardOrangeExpansion1 StarBoardOrangeExpansion2 Drive2ChoroQ ... more

Revision:
0:6b4ba48753b9
Child:
1:f02e081afe42
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ConfigFile.h	Sun Sep 12 07:11:54 2010 +0000
@@ -0,0 +1,104 @@
+#include "mbed.h"
+
+#ifndef _CONFIG_FILE_H_
+#define _CONFIG_FILE_H_
+
+/**
+ * Configuration File class.
+ */
+class ConfigFile {
+public:
+
+    /**
+     * Create a configuration file class.
+     */
+    ConfigFile();
+    
+    /**
+     * Destroy a configuration file class.
+     */
+    ~ConfigFile();
+    
+    /**
+     * Get a value for a key.
+     *
+     * @param key A target key name.
+     *
+     * @return A value or NULL.
+     */
+    char *getValue(char *key);
+    
+    /**
+     * Set a set of a key and value.
+     *
+     * @param key A key.
+     * @param value A value.
+     *
+     * @return True if it succeed.
+     */
+    bool setValue(char *key, char *value);
+    
+    /**
+     * Remove a config.
+     *
+     * @param key A key.
+     *
+     * @return True if it succeed.
+     */
+    bool remove(char *key);
+    
+    /**
+     * Remove all config.
+     *
+     * @return True if it succeed.
+     */
+    bool removeAll(void);
+    
+    /**
+     * Read from the target file.
+     *
+     * @param file A target file name.
+     */
+    bool read(char *file);
+    
+    /**
+     * Write from the target file.
+     *
+     * @param file A target file name.
+     */
+    bool write(char *file);
+    
+    /**
+     * Output for debugging.
+     *
+     * @deprecated Please do not use this method.
+     */
+    void debout(void) {
+        printf("===========================================================================\n");
+        for (int i = 0; i < MAXCONFIG; i++) {
+            config_t *cfg = configlist[i];
+            printf("[%03d]:", i);
+            if (cfg == NULL) {
+                printf("NULL\n");
+            } else {
+                printf("'%s'='%s'\n", cfg->key, cfg->value);
+            }
+        }
+        printf("===========================================================================\n");
+    }
+private:
+    typedef struct {
+        char *key;
+        char *value;
+    } config_t;
+    config_t **configlist;
+    static const int MAXCONFIG = 64;
+    static const int MAXLEN_KEY = 64;
+    static const int MAXLEN_VALUE = 128;
+    static const char SEPARATOR = '=';
+
+    config_t *search(char *key);
+    bool add(config_t *cfg);
+};
+
+#endif