Revision: 40777
          http://brlcad.svn.sourceforge.net/brlcad/?rev=40777&view=rev
Author:   davidloman
Date:     2010-09-29 11:04:59 +0000 (Wed, 29 Sep 2010)

Log Message:
-----------
Upgraded config file loader to allow for optional verbosity during load.

Modified Paths:
--------------
    rt^3/trunk/include/Config.h
    rt^3/trunk/src/utility/Config.cxx

Modified: rt^3/trunk/include/Config.h
===================================================================
--- rt^3/trunk/include/Config.h 2010-09-29 10:47:28 UTC (rev 40776)
+++ rt^3/trunk/include/Config.h 2010-09-29 11:04:59 UTC (rev 40777)
@@ -38,7 +38,7 @@
        ~Config();
        static Config* getInstance();
 
-       bool loadFile(QString pathAndFileName);
+       bool loadFile(QString pathAndFileName, bool verbose = false);
        QString getConfigValue(QString key);
        void updateValue(QString key, QString value);
        QList<QString> getAllKeys();
@@ -48,7 +48,7 @@
        Config(const Config& c){}; //Turn off Copy cstr
        Config& operator=(const Config& c){}; //Turn off equal oper
 
-       void processLine(QString line);
+       QString processLine(QString line);
        void removeAllOccurances(QString* data, QString search,
                        QString replace);
 

Modified: rt^3/trunk/src/utility/Config.cxx
===================================================================
--- rt^3/trunk/src/utility/Config.cxx   2010-09-29 10:47:28 UTC (rev 40776)
+++ rt^3/trunk/src/utility/Config.cxx   2010-09-29 11:04:59 UTC (rev 40777)
@@ -25,6 +25,7 @@
 
 #include "Config.h"
 #include <QtCore/QFile>
+#include <QtCore/QFileInfo>
 #include <QtCore/QStringList>
 #include <QtCore/QMutexLocker>
 
@@ -49,7 +50,7 @@
     return Config::pInstance;
 }
 
-bool Config::loadFile(QString pathAndFileName)
+bool Config::loadFile(QString pathAndFileName, bool verbose)
 {
     QString msg;
     msg = "Attemping to load config from: " + pathAndFileName + ".";
@@ -60,31 +61,39 @@
 
     //verify & open
     if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
-       msg = "Loading config from: " + pathAndFileName + " FAILED.";
-       this->log->logFATAL("Config", msg);
-       return false;
+               msg = "Loading config from: " + pathAndFileName + " FAILED.";
+               this->log->logFATAL("Config", msg);
+               return false;
     }
 
     while (!f.atEnd()) {
-       QByteArray lineBytes = f.readLine();
+               QByteArray lineBytes = f.readLine();
 
-       QString line(lineBytes);
+               QString line(lineBytes);
 
-       //Rem newline:
-       this->removeAllOccurances(&line, "\n", "");
+               //Rem newline:
+               this->removeAllOccurances(&line, "\n", "");
 
-       //Check for comments
-       if (line[0] == '#') {
-           //log->logINFO("Config", "Ignoring Comment. (" + line + ")");
-       }
-       else {
-           this->processLine(line);
-       }
+               //Check for comments
+               if (line[0] == '#') {
+                       //log->logINFO("Config", "Ignoring Comment. (" + line + 
")");
+               } else {
+                       QString key = this->processLine(line);
+
+                       if (verbose && key != NULL && key.length() > 0) {
+                               QString value = this->configMap->value(key);
+                               log->logINFO("Config", "Read key/value: '" + 
key + "'->'" + value + "'");
+                       }
+
+               }
     }
-    log->logINFO("Config", "Done loading config from: " + f.fileName());
+    QFileInfo info(f);
+
+    log->logINFO("Config", "Done loading config from: " + 
info.absoluteFilePath());
 }
 
-void Config::processLine(QString line)
+QString
+Config::processLine(QString line)
 {
     //Process the string, clean it up.
 
@@ -94,7 +103,7 @@
     //Check for blankline
     if (line == "" || line == " ") {
        //this->log->logDEBUG("Config", "Empty Line");
-       return;
+       return "";
     }
 
     QStringList list = line.split(" ");
@@ -102,14 +111,14 @@
        this->log->logERROR("Config",
                "Not enough elements for Key/Value pair on Config Line: "
                        + line);
-       return;
+       return "";
     }
 
     QString key = list[0];
     QString value = list[1];
 
-    //this->log->logINFO("Config", "Key: '" + key + "' Value: '" + value + 
"'");
     this->updateValue(key, value);
+    return key;
 }
 
 void Config::removeAllOccurances(QString* data, QString search, QString 
replace)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to