ConfigFile

Dependents:   ConfigFile_TestProgram StarBoardOrangeExpansion1 StarBoardOrangeExpansion2 Drive2ChoroQ ... more

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Wed Sep 15 12:23:15 2010 +0000
Parent:
4:940510a29b44
Child:
6:f6ceafabe9f8
Commit message:

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	Sun Sep 12 07:53:10 2010 +0000
+++ b/ConfigFile.cpp	Wed Sep 15 12:23:15 2010 +0000
@@ -197,6 +197,36 @@
     return true;
 }
 
+int ConfigFile::getCount() {
+    int cnt = 0;
+    for (int i = 0; i < MAXCONFIG; i++) {
+        config_t *p = configlist[i];
+        if (p != NULL) {
+            cnt++;
+        }
+    }
+    return cnt;
+}
+
+bool ConfigFile::getKeyAndValue(int index, char *key, size_t keybufsiz, char *value, size_t valuebufsiz) {
+    int cnt = 0;
+    for (int i = 0; i < MAXCONFIG; i++) {
+        config_t *p = configlist[i];
+        if (p != NULL) {
+            if (cnt == index) {
+                if ((strlen(p->key) < keybufsiz) && (strlen(p->value) < valuebufsiz)) {
+                    strcpy(key, p->key);
+                    strcpy(value, p->value);
+                    return true;
+                }
+                return false;
+            }
+            cnt++;
+        }
+    }
+    return false;
+}
+
 bool ConfigFile::read(char *file) {
     /*
      * Open the target file.
--- a/ConfigFile.h	Sun Sep 12 07:53:10 2010 +0000
+++ b/ConfigFile.h	Wed Sep 15 12:23:15 2010 +0000
@@ -61,6 +61,10 @@
      */
     bool removeAll(void);
 
+    int getCount();
+    
+    bool getKeyAndValue(int index, char *key, size_t keybufsiz, char *value, size_t valuebufsiz);
+
     /**
      * Read from the target file.
      *
@@ -83,24 +87,6 @@
      */
     bool write(char *file, char *header = NULL, FileFormat ff = UNIX);
 
-    /**
-     * 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;