[cig-commits] [commit] master: Add default param setter (f3022ce)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue Oct 21 16:27:31 PDT 2014


Repository : https://github.com/geodynamics/vc

On branch  : master
Link       : https://github.com/geodynamics/vc/compare/64c223c129f70f3916341f1ebdf52f6d2ae1deae...de41758e125fcac4ea5fb0935597c3b662ff523c

>---------------------------------------------------------------

commit f3022ce57abc2ed49a73b57b404012c483492c79
Author: Eric Heien <emheien at ucdavis.edu>
Date:   Tue Oct 21 15:44:45 2014 -0700

    Add default param setter


>---------------------------------------------------------------

f3022ce57abc2ed49a73b57b404012c483492c79
 src/misc/ConfigFile.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/misc/ConfigFile.h b/src/misc/ConfigFile.h
index 4a49474..7a37c50 100644
--- a/src/misc/ConfigFile.h
+++ b/src/misc/ConfigFile.h
@@ -51,6 +51,7 @@ class ConfigFile {
         // Search for key and read value or optional default value
         template<class T> T read( const string &key ) const;  // call as read<T>
         template<class T> T read( const string &key, const T &value ) const;
+        template<class T> T readSet( const string &key, const T &value );
         template<class T> bool readInto( T &var, const string &key ) const;
         template<class T>
         bool readInto( T &var, const string &key, const T &value ) const;
@@ -183,6 +184,20 @@ T ConfigFile::read( const string &key, const T &value ) const {
     return string_as_T<T>( p->second );
 }
 
+template<class T>
+T ConfigFile::readSet( const string &key, const T &value ) {
+    // Return the value corresponding to key or given default value
+    // if key is not found. If key is not found, stores the default value
+    mapci p = myContents.find(key);
+
+    if ( p == myContents.end() ) {
+        add<T>(key, value);
+        return value;
+    }
+
+    return string_as_T<T>( p->second );
+}
+
 
 template<class T>
 bool ConfigFile::readInto( T &var, const string &key ) const {



More information about the CIG-COMMITS mailing list