Experimental usage.
[vlp.git] / src / global / AppConfiguration.cpp
index b29b76ec59e43bfecfb7e94a530baea7ebedbe30..6b718ce578d154f1d2ad50b606f7efa3cca0f2f7 100644 (file)
@@ -1,9 +1,54 @@
+#include <stdlib.h>
+#include "genint1.h"
 #include "AppConfiguration.h"
 
-void AppConfiguration::error(config_t *cfg)
+AppConfiguration::AppConfiguration(const char * fname)
 {
+  config_init(&cfg);
+  
+  /* Read the file. If there is an error, report it and exit. */
+  if(!config_read_file(&cfg, fname)) 
+  {
+    error();
+    config_destroy(&cfg);
+    exit(3);/* from original code. */
+  }
+}
+int AppConfiguration::getInt(const char * path)
+{
+    int value = 0;
+    if (config_lookup_int(&cfg, path, &value) == CONFIG_FALSE)
+    {
+        fprintf(stderr, "Warning: %s was not found, or bad type requested\n", path);
+    }
+    return value;
+}
+
+const char * AppConfiguration::getString(const char * path)
+{
+    const char * value;
+    if (config_lookup_string(&cfg, path, &value) == CONFIG_FALSE)
+    {
+        fprintf(stderr, "Warning: %s was not found, or bad type requested\n", path);
+    }
+    return value;
+}
+
+int AppConfiguration::error()
+{
+    if (config_error_type(&cfg) == CONFIG_ERR_NONE)
+    {
+        return FALSE;
+    }
+    
     fprintf(stderr, "%s: In file %s, line %d\n",
-        config_error_text(cfg),
-        config_error_file(cfg),
-        config_error_line(cfg));
+        config_error_text(&cfg),
+        config_error_file(&cfg),
+        config_error_line(&cfg));
+    return TRUE;
+}
+
+void AppConfiguration::release()
+{
+    config_destroy(&cfg);
 }