/* $Id$ $URL$ */ #ifndef RCONFIG_DOT_AITCH #define RCONFIG_DOT_AITCH /**\file rconfig.h * \ingroup coreheaders * Declarations of the configuration variables go here, within the RConfig * namespace. * \author Trent Apted * $Revision$ * $Date$ */ #include #include #include /** The readable configuration parser handle */ class RCParser { int argc; ///< main()'s argc char **argv; ///< main()'s argv char **envv; ///< main()'s envv, if present public: /** Construct the RCParser, with arguments from main() */ RCParser(int argc, char** argv, char** envv = 0); /** Get the argc, from main() */ int getArgc() const; /** Get argv[], from main() */ char* const * getArgv() const; /** get envv[], from main(), NULL if not present */ char* const * getEnvv() const; }; /** * Configuration variables are kept in the RConfig namespace. */ namespace RConfig { /** * Parse a readable configuration file */ int rcfile_parse(const char* file = "sharepicrc"); /** * Parse a line of configuration */ bool rcfile_parseline(const std::string& line); /** * Get the names of stored variables */ void rcfile_getnames(std::vector & names); /** * Get the string value of a stored variable if stored */ bool rcfile_getvalue(std::string& val, const std::string& name); //@{ /** * Tell the RCFile parser to look for config vars of \a name to store in \a ref */ void rcfile_tell(const char* name, bool &ref, const char* context = 0); void rcfile_tell(const char* name, int &ref, const char* context = 0); void rcfile_tell(const char* name, float &ref, const char* context = 0); void rcfile_tell(const char* name, double &ref, const char* context = 0); void rcfile_tell(const char* name, unsigned &ref, const char* context = 0); void rcfile_tell(const char* name, std::string &ref, const char* context = 0); void rcfile_tellstr(const char* name, std::string &ref, const char* defval = 0, const char* context = 0); //void rcfile_tell(const char* name, std::vector &ref); void rcfile_tell(const char* name, std::vector &ref, const char* context = 0); void rcfile_tell(const char* name, std::vector &ref, const char* context = 0); void rcfile_tell(const char* name, std::vector &ref, const char* context = 0); void rcfile_tell(const char* name, std::vector &ref, const char* context = 0); void rcfile_tell(const char* name, std::vector &ref, const char* context = 0); //@} template T rcfile_initwrap(const char* name, T& ref, const V& initval, const char* context = 0) { ref = initval; //this only works for primitive types rcfile_tell(name, ref, context); return initval; } template std::string rcfile_initwrap(const char* name, std::string& ref, const V& initval, const char* context = 0) { rcfile_tellstr(name, ref, initval, context); return initval; } /**\internal RConfig Initialiser */ struct Init {static int count; Init(); ~Init();}; } namespace { /**\internal Guarantee initialisation regardless of linking order */ RConfig::Init rconfig_init__; } /** If the variable has the same name as the config parameter, you can use this macro */ #define RCFILE_TELLMACRO(_var) RConfig::rcfile_tell( #_var, _var, __FILE__ ) #define RCFILE_CONFIGVAR(_var, _default) _var = RConfig::rcfile_initwrap(#_var, _var, _default, __FILE__) #endif