Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #ifndef ICL_CORE_CONFIG_CONFIG_LIST_H_INCLUDED
00024 #define ICL_CORE_CONFIG_CONFIG_LIST_H_INCLUDED
00025
00026 #include "icl_core_config/ConfigHelper.h"
00027 #include "icl_core_config/ConfigValues.h"
00028 #include "icl_core_config/MemberEnum.h"
00029 #include "icl_core_config/MemberValue.h"
00030
00031 #include <iterator>
00032 #include <list>
00033 #include <boost/assign/list_of.hpp>
00034 #include <boost/regex.hpp>
00035
00036 #define CONFIG_LIST(cls, prefix, members, result) \
00037 (new icl_core::config::ConfigList<cls, ICL_CORE_CONFIG_TYPEOF(result)>(prefix, members, result))
00038
00039 #define MEMBER_MAPPING(cls, arg) boost::assign::list_of<icl_core::config::impl::MemberValueIface<cls>*> arg
00040
00041
00042 namespace icl_core {
00043 namespace config {
00044
00055 template<typename T, class OutputIterator = std::back_insert_iterator<std::list<T> > >
00056 class ConfigList : public impl::ConfigValueIface
00057 {
00058 public:
00059 ConfigList(std::string config_prefix,
00060 std::list<impl::MemberValueIface<T>*> members,
00061 OutputIterator result)
00062 : m_config_prefix(config_prefix),
00063 m_members(members),
00064 m_result(result)
00065 {
00066 }
00067 virtual ~ConfigList() {}
00068
00069 virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
00070 {
00071 bool result = false;
00072 bool error = false;
00073 ConfigIterator cIter = ConfigManager::instance().find(
00074 boost::regex_replace(prefix + m_config_prefix, boost::regex("\\/"), "\\\\\\/") + "\\/(.+?)(\\/(.+))?");
00075 while(cIter.next())
00076 {
00077 bool found = false;
00078 std::string element = cIter.matchGroup(1);
00079 std::string suffix = cIter.matchGroup(3);
00080 for (typename std::list<impl::MemberValueIface<T>*>::const_iterator it = m_members.begin();
00081 !found && it != m_members.end(); ++it)
00082 {
00083 if (suffix == (*it)->getSuffix())
00084 {
00085 found = true;
00086 if ((*it)->get(cIter.matchGroup(0), m_element_map[element]))
00087 {
00088 m_string_value_map[element] += " " + suffix + "=" + (*it)->getStringValue();
00089
00090 SLOGGING_TRACE_C(log_stream, ConfigList,
00091 "Read parameter " << cIter.matchGroup(0) << " = "
00092 << (*it)->getStringValue() << icl_core::logging::endl);
00093 result = true;
00094 }
00095 else
00096 {
00097 SLOGGING_ERROR_C(log_stream, ConfigList,
00098 "Error reading configuration parameter \"" << cIter.matchGroup(0) << " = "
00099 << (*it)->getStringValue() << icl_core::logging::endl);
00100 error = true;
00101 }
00102 }
00103 }
00104 }
00105
00106 if (error)
00107 {
00108 result = false;
00109 }
00110
00111 if (result == true)
00112 {
00113 for (typename std::map<std::string, T>::const_iterator it = m_element_map.begin();
00114 it != m_element_map.end(); ++it)
00115 {
00116 *m_result = it->second;
00117 ++m_result;
00118 }
00119
00120 m_string_value = m_config_prefix + " = [";
00121 for (std::map<std::string, std::string>::const_iterator it = m_string_value_map.begin();
00122 it != m_string_value_map.end(); ++it)
00123 {
00124 m_string_value += " " + it->first + ": (" + it->second + ")";
00125 }
00126 m_string_value += " ]";
00127 }
00128
00129 return result;
00130 }
00131
00132 virtual icl_core::String key() const { return m_config_prefix; }
00133 virtual icl_core::String stringValue() const { return m_string_value; }
00134
00135 private:
00136 std::string m_config_prefix;
00137 std::list<impl::MemberValueIface<T>*> m_members;
00138 mutable std::map<std::string, T> m_element_map;
00139 mutable std::map<std::string, std::string> m_string_value_map;
00140 mutable OutputIterator m_result;
00141 mutable std::string m_string_value;
00142 };
00143
00144 }}
00145
00146 #endif