Changeset 692 for mylib/trunk/rconfig

Show
Ignore:
Timestamp:
01/07/08 18:28:27 (2 years ago)
Author:
tapted
Message:

Add hello world and support strings as unititialised

Location:
mylib/trunk/rconfig
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • mylib/trunk/rconfig/rconfig.cpp

    r691 r692  
    201201} 
    202202 
     203template <class T> 
     204static void addvar_uninitialised(const char* cname, T& var, const char* initval, const char* context) { 
     205    std::string name(cname); 
     206    if (IDEBUG) { 
     207        std::cerr.setf(std::ios_base::left, std::ios_base::adjustfield); 
     208        std::cerr 
     209            << "(cfg) " << std::setw(15) << DEMANGLE(T) 
     210            << ' ' << std::setw(30) << name 
     211            << " = " << std::setw(20) << initval; 
     212        if (context) 
     213            std::cerr << " (" << context << ")"; 
     214        std::cerr << std::endl; 
     215 
     216    } 
     217    varmap->insert(VARMAP::value_type(name, make_varreader(var, name))); 
     218} 
     219 
    203220/** Add a VarReaderV to the map of variables we want to look for */ 
    204221template <class T> 
     
    285302    addvar(name, ref, context); 
    286303} 
     304 
     305void rcfile_tellstr(const char* name, std::string &ref, const char* defval, const char* context) { 
     306    addvar_uninitialised(name, ref, defval, context); 
     307} 
     308 
    287309/* 
    288310void rcfile_tell(const char* name, std::vector<bool> &ref) { 
  • mylib/trunk/rconfig/rconfig.h

    r691 r692  
    6767void rcfile_tell(const char* name, unsigned &ref, const char* context = 0); 
    6868void rcfile_tell(const char* name, std::string &ref, const char* context = 0); 
     69void rcfile_tellstr(const char* name, std::string &ref, const char* defval = 0, const char* context = 0); 
    6970//void rcfile_tell(const char* name, std::vector<bool> &ref); 
    7071void rcfile_tell(const char* name, std::vector<int> &ref, const char* context = 0); 
     
    7576//@} 
    7677 
    77 template<class T> 
    78     T rcfile_initwrap(const char* name, T& ref, const T& initval, const char* context = 0) { 
    79         ref = initval; 
     78template<class T, class V> 
     79    T rcfile_initwrap(const char* name, T& ref, const V& initval, const char* context = 0) { 
     80        ref = initval; //this only works for primitive types 
    8081        rcfile_tell(name, ref, context); 
     82        return initval; 
     83    } 
     84 
     85template<class V> 
     86    std::string rcfile_initwrap(const char* name, std::string& ref, const V& initval, const char* context = 0) { 
     87        rcfile_tellstr(name, ref, initval, context); 
    8188        return initval; 
    8289    }