00001
00002
00003
00004
00005
00006
00007
00008 #ifndef CAJUN_CONF_H
00009 #define CAJUN_CONF_H
00010
00011
00012 #include <map>
00013
00014 #include <iostream>
00015
00016 namespace cajun
00017 {
00018 typedef std::string conf_entry_t;
00019 };
00020
00021
00022 template <typename T>
00023 bool conf_value (cajun::conf_entry_t &entry, T &value);
00024
00025
00026 namespace cajun
00027 {
00028 std::string make_bot_config_filename (std::string const &name);
00029 std::string make_config_filename (std::string const &name);
00030 std::string make_bin_filename (std::string const &name);
00031 std::string make_docs_filename (std::string const &name);
00032 std::string make_support_filename (std::string const &name);
00033
00034 class conf_t
00035 {
00036 protected:
00037 std::string m_file_name;
00038 std::map<std::string, conf_entry_t> m_params;
00039
00040 bool find (std::string const &name,
00041 cajun::conf_entry_t &entry) const;
00042 bool remove_quotes(std::string const &in_string,
00043 std::string &out_string) const;
00044
00045 void notify_missing (std::string const &name) const;
00046 void notify_invalid (std::string const &name) const;
00047
00048 public:
00049
00050 conf_t();
00051
00052 bool read (std::string const &filename);
00053
00054 template <typename T>
00055 bool get (std::string const &name, T &value) const
00056 {
00057 cajun::conf_entry_t entry;
00058
00059 return (find (name, entry) &&
00060 conf_value (entry, value));
00061 }
00062
00063 template <typename T>
00064 bool require (std::string const &name, T &value) const
00065 {
00066 cajun::conf_entry_t entry;
00067
00068 if (! find (name, entry))
00069 { notify_missing (name); return false; }
00070 if (! conf_value (entry, value))
00071 { notify_invalid (name); return false; }
00072 return true;
00073 }
00074 };
00075 };
00076
00077
00078
00079 template <>
00080 bool conf_value (cajun::conf_entry_t &entry, bool &value);
00081 template <>
00082 bool conf_value (cajun::conf_entry_t &entry, int &value);
00083 template <>
00084 bool conf_value (cajun::conf_entry_t &entry, unsigned &value);
00085 template <>
00086 bool conf_value (cajun::conf_entry_t &entry, float &value);
00087 template <>
00088 bool conf_value (cajun::conf_entry_t &entry, double &value);
00089 template <>
00090 bool conf_value (cajun::conf_entry_t &entry, std::string &value);
00091
00092
00093 #endif