MemberValue.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_MEMBER_VALUE_H_INCLUDED
24 #define ICL_CORE_CONFIG_MEMBER_VALUE_H_INCLUDED
25 
31 #include "icl_core_config/Util.h"
32 
33 #include <string>
34 #include <boost/function.hpp>
35 #include <boost/lambda/bind.hpp>
36 
37 #define MEMBER_VALUE_1(suffix, cls, member1) \
38  (new icl_core::config::MemberValue< \
39  icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF(&cls::member1)>::Type, cls>( \
40  suffix, \
41  boost::lambda::bind(&cls::member1, boost::lambda::_1)))
42 
43 #define MEMBER_VALUE_2(suffix, cls, member1, member2) \
44  (new icl_core::config::MemberValue< \
45  icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
46  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
47  &cls::member1)>::Type::member2)>::Type, cls>( \
48  suffix, \
49  boost::lambda::bind( \
50  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF(&cls::member1)>::Type::member2, \
51  boost::lambda::bind(&cls::member1, boost::lambda::_1))))
52 
53 #define MEMBER_VALUE_3(suffix, cls, member1, member2, member3) \
54  (new icl_core::config::MemberValue< \
55  icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
56  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
57  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
58  &cls::member1)>::Type::member2)>::Type::member3)>::Type, cls>( \
59  suffix, \
60  boost::lambda::bind( \
61  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
62  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF( \
63  &cls::member1)>::Type::member2)>::Type::member3, \
64  boost::lambda::bind( \
65  &icl_core::RemoveMemberPointer<ICL_CORE_CONFIG_TYPEOF(&cls::member1)>::Type::member2, \
66  boost::lambda::bind(&cls::member1, boost::lambda::_1)))))
67 
68 namespace icl_core {
69 namespace config {
70 
71 template<typename T, typename Q>
73 {
74 public:
75  MemberValue(std::string const & config_suffix,
76  boost::function<T&(Q&)> accessor)
77  : m_config_suffix(config_suffix),
78  m_accessor(accessor)
79  {
80  }
81  virtual ~MemberValue() {}
82 
83  virtual bool get(std::string const & key,
84  typename icl_core::ConvertToRef<Q>::ToRef value) const
85  {
86  bool result = false;
88  {
89  try
90  {
92  result = true;
93  }
94  catch (...)
95  {
96  result = false;
97  }
98  }
99  else
100  {
101  result = false;
102  }
103  return result;
104  }
105 
106  virtual std::string getSuffix() const { return m_config_suffix; }
107  virtual std::string getStringValue() const { return m_str_value; }
108 
109 private:
110  std::string m_config_suffix;
111  boost::function<T&(Q&)> m_accessor;
112  mutable std::string m_str_value;
113 };
114 
116 template<typename Q>
117 class MemberValue<bool, Q> : public impl::MemberValueIface<Q>
118 {
119 public:
120  MemberValue(std::string const & config_suffix,
121  boost::function<bool&(Q&)> accessor)
122  : m_config_suffix(config_suffix),
123  m_accessor(accessor)
124  {
125  }
126  virtual ~MemberValue() {}
127 
128  virtual bool get(std::string const & key,
129  typename icl_core::ConvertToRef<Q>::ToRef value) const
130  {
131  bool result = false;
133  {
134  try
135  {
137  result = true;
138  }
139  catch (...)
140  {
141  result = false;
142  }
143  }
144  else
145  {
146  result = false;
147  }
148  return result;
149  }
150 
151  virtual std::string getSuffix() const { return m_config_suffix; }
152  virtual std::string getStringValue() const { return m_str_value; }
153 
154 private:
155  std::string m_config_suffix;
156  boost::function<bool&(Q&)> m_accessor;
157  mutable std::string m_str_value;
158 };
159 
160 }}
161 
162 #endif
Helper definitions for template programming.
MemberValue(std::string const &config_suffix, boost::function< T &(Q &)> accessor)
Definition: MemberValue.h:75
static ConfigManager & instance()
virtual std::string getSuffix() const
Definition: MemberValue.h:106
boost::function< bool &(Q &)> m_accessor
Definition: MemberValue.h:156
virtual std::string getStringValue() const
Definition: MemberValue.h:152
virtual std::string getSuffix() const
Definition: MemberValue.h:151
virtual std::string getStringValue() const
Definition: MemberValue.h:107
T hexical_cast(U input)
Definition: Util.h:43
MemberValue(std::string const &config_suffix, boost::function< bool &(Q &)> accessor)
Definition: MemberValue.h:120
bool strict_bool_cast(U input)
Definition: Util.h:87
boost::function< T &(Q &)> m_accessor
Definition: MemberValue.h:111
bool get(const String &key, typename ConvertToRef< T >::ToRef value) const
Utility functions for the configuration framework.
Contains ConfigManager.


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