ConfigList.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #ifndef ICL_CORE_CONFIG_CONFIG_LIST_H_INCLUDED
24 #define ICL_CORE_CONFIG_CONFIG_LIST_H_INCLUDED
25 
30 
31 #include <iterator>
32 #include <list>
33 #include <boost/assign/list_of.hpp>
34 #include <boost/regex.hpp>
35 
36 #define CONFIG_LIST(cls, prefix, members, result) \
37  (new icl_core::config::ConfigList<cls, ICL_CORE_CONFIG_TYPEOF(result)>(prefix, members, result))
38 
39 #define MEMBER_MAPPING(cls, arg) boost::assign::list_of<icl_core::config::impl::MemberValueIface<cls>*> arg
40 
41 
42 namespace icl_core {
43 namespace config {
44 
55 template<typename T, class OutputIterator = std::back_insert_iterator<std::list<T> > >
57 {
58 public:
59  ConfigList(std::string config_prefix,
60  std::list<impl::MemberValueIface<T>*> members,
61  OutputIterator result)
62  : m_config_prefix(config_prefix),
63  m_members(members),
64  m_result(result)
65  {
66  }
67  virtual ~ConfigList() {}
68 
69  virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
70  {
71  bool result = false;
72  bool error = false;
74  boost::regex_replace(prefix + m_config_prefix, boost::regex("\\/"), "\\\\\\/") + "\\/(.+?)(\\/(.+))?");
75  while(cIter.next())
76  {
77  bool found = false;
78  std::string element = cIter.matchGroup(1);
79  std::string suffix = cIter.matchGroup(3);
80  for (typename std::list<impl::MemberValueIface<T>*>::const_iterator it = m_members.begin();
81  !found && it != m_members.end(); ++it)
82  {
83  if (suffix == (*it)->getSuffix())
84  {
85  found = true;
86  if ((*it)->get(cIter.matchGroup(0), m_element_map[element]))
87  {
88  m_string_value_map[element] += " " + suffix + "=" + (*it)->getStringValue();
89 
90  SLOGGING_TRACE_C(log_stream, ConfigList,
91  "Read parameter " << cIter.matchGroup(0) << " = "
92  << (*it)->getStringValue() << icl_core::logging::endl);
93  result = true;
94  }
95  else
96  {
97  SLOGGING_ERROR_C(log_stream, ConfigList,
98  "Error reading configuration parameter \"" << cIter.matchGroup(0) << " = "
99  << (*it)->getStringValue() << icl_core::logging::endl);
100  error = true;
101  }
102  }
103  }
104  }
105 
106  if (error)
107  {
108  result = false;
109  }
110 
111  if (result == true)
112  {
113  for (typename std::map<std::string, T>::const_iterator it = m_element_map.begin();
114  it != m_element_map.end(); ++it)
115  {
116  *m_result = it->second;
117  ++m_result;
118  }
119 
120  m_string_value = m_config_prefix + " = [";
121  for (std::map<std::string, std::string>::const_iterator it = m_string_value_map.begin();
122  it != m_string_value_map.end(); ++it)
123  {
124  m_string_value += " " + it->first + ": (" + it->second + ")";
125  }
126  m_string_value += " ]";
127  }
128 
129  return result;
130  }
131 
132  virtual icl_core::String key() const { return m_config_prefix; }
133  virtual icl_core::String stringValue() const { return m_string_value; }
134 
135 private:
136  std::string m_config_prefix;
137  std::list<impl::MemberValueIface<T>*> m_members;
138  mutable std::map<std::string, T> m_element_map;
139  mutable std::map<std::string, std::string> m_string_value_map;
140  mutable OutputIterator m_result;
141  mutable std::string m_string_value;
142 };
143 
144 }}
145 
146 #endif
static ConfigManager & instance()
#define SLOGGING_TRACE_C(stream, classname, arg)
#define SLOGGING_ERROR_C(stream, classname, arg)
std::list< impl::MemberValueIface< T > * > m_members
Definition: ConfigList.h:137
KeyValueDirectoryIterator< T > find(const String &query) const
Implements a thread-safe logging framework.
Definition: LogStream.h:54
ThreadStream & endl(ThreadStream &stream)
Definition: ThreadStream.h:249
virtual icl_core::String key() const
Definition: ConfigList.h:132
Contains tConfigValue.
String matchGroup(size_t index) const
ConfigList(std::string config_prefix, std::list< impl::MemberValueIface< T > * > members, OutputIterator result)
Definition: ConfigList.h:59
std::map< std::string, T > m_element_map
Definition: ConfigList.h:138
std::string String
Definition: BaseTypes.h:43
virtual icl_core::String stringValue() const
Definition: ConfigList.h:133
std::map< std::string, std::string > m_string_value_map
Definition: ConfigList.h:139


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58