Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef ZORBA_PROPERTIES_BASE_H
00017 #define ZORBA_PROPERTIES_BASE_H
00018
00019 #include <string>
00020 #include <sstream>
00021 #include <iostream>
00022 #include <vector>
00023 #include <cctype>
00024 #include <zorba/config.h>
00025
00026 namespace zorba {
00027
00028
00029
00030
00031 class ZORBA_DLL_PUBLIC PropertiesBase
00032 {
00033 protected:
00034 std::vector<std::string> thePositionalArgs;
00035
00036 public:
00037 virtual ~PropertiesBase() {}
00038
00039 std::string load_all(
00040 const char* cfgFilename,
00041 const std::string& env_pfx,
00042 int argc,
00043 const char **argv)
00044 {
00045 std::string result;
00046
00047 if (! (result = load_env(env_pfx)).empty())
00048 return result;
00049
00050 if (! (result = load_file(cfgFilename)).empty())
00051 return result;
00052
00053 return load_argv(argc, argv);
00054 }
00055
00056 std::string load_env(const std::string& env_pfx)
00057 {
00058 return load_env(env_pfx, get_all_options());
00059 }
00060
00061 std::string load_env(const std::string& env_pfx, const char** options);
00062
00063 std::string load_file(const char* fname);
00064
00065 virtual std::string load_argv(int argc, const char **argv) = 0;
00066
00067 virtual const char** get_all_options() const = 0;
00068
00069 virtual std::string check_args() { return ""; }
00070
00071 const std::vector<std::string>& getPositionalArgs() const
00072 {
00073 return thePositionalArgs;
00074 }
00075
00076 void copy_args (const char** argv)
00077 {
00078 for (; *argv != NULL; ++argv)
00079 {
00080 thePositionalArgs.push_back(*argv);
00081 }
00082 }
00083
00084 template<class T> void init_val(const char* str, T& val, unsigned delta = 0)
00085 {
00086 std::istringstream is(str + delta);
00087 is >> val;
00088 }
00089
00090 };
00091
00092
00093 template<> ZORBA_DLL_PUBLIC void PropertiesBase::init_val(
00094 const char* str,
00095 std::string& val,
00096 unsigned delta);
00097
00098
00099 template<> ZORBA_DLL_PUBLIC void PropertiesBase::init_val(
00100 const char* str,
00101 std::vector<std::string>& val,
00102 unsigned delta);
00103
00104 }
00105
00106 #endif // ZORBA_PROPERTIES_BASE_H
00107
00108
00109
00110
00111
00112