ConfigValue.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_VALUE_H_INCLUDED
24 #define ICL_CORE_CONFIG_CONFIG_VALUE_H_INCLUDED
25 
26 #include <icl_core/BaseTypes.h>
28 
32 #include "icl_core_config/Util.h"
33 
34 #ifdef _IC_BUILDER_OPENSPLICEDDS_
35 # include "dds_dcps.h"
36 # include "mapping/String.h"
37 #endif
38 
39 # define CONFIG_VALUE(key, value) \
40  (new icl_core::config::ConfigValue<ICL_CORE_CONFIG_TYPEOF(value)>(key, value))
41 
42 
43 namespace icl_core {
44 namespace config {
45 
49 template <typename T>
51 {
52 public:
57  typename icl_core::ConvertToRef<T>::ToRef value)
58  : m_key(key),
59  m_value(value)
60  { }
61 
64  virtual ~ConfigValue() { }
65 
68  virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
69  {
71  {
72  try
73  {
75  return true;
76  }
77  catch (...)
78  {
79  return false;
80  }
81  }
82  else
83  {
84  return false;
85  }
86  }
87 
90  virtual icl_core::String key() const
91  {
92  return m_key;
93  }
94 
97  virtual icl_core::String stringValue() const
98  {
99  return m_str_value;
100  }
101 
102 protected:
106 };
107 
108 template<>
109 inline
110 bool ConfigValue<bool>::get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
111 {
112  bool result = false;
113  if (ConfigManager::instance().get(prefix + m_key, m_str_value))
114  {
115  try
116  {
118  result = true;
119  }
120  catch (...)
121  {
122  result = false;
123  }
124  }
125  else
126  {
127  result = false;
128  }
129  return result;
130 }
131 
132 #ifdef _IC_BUILDER_OPENSPLICEDDS_
133 template<>
134 inline
135 bool ConfigValue<DDS::String>::get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
136 {
137  bool result = false;
138  if (ConfigManager::instance().get(prefix + m_key, m_str_value))
139  {
140  m_value = DDS::string_dup(m_str_value.c_str());
141  result = true;
142  }
143  else
144  {
145  result = false;
146  }
147  return result;
148 }
149 template<>
150 inline
151 bool ConfigValue<DDS::String_mgr>::get(std::string const & prefix,
152  icl_core::logging::LogStream& log_stream) const
153 {
154  bool result = false;
155  if (ConfigManager::instance().get(prefix + m_key, m_str_value))
156  {
157  m_value = DDS::string_dup(m_str_value.c_str());
158  result = true;
159  }
160  else
161  {
162  result = false;
163  }
164  return result;
165 }
166 #endif
167 
168 }}
169 
170 #endif
ConfigValue(const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToRef value)
Definition: ConfigValue.h:56
Helper definitions for template programming.
static ConfigManager & instance()
icl_core::String m_str_value
Definition: ConfigValue.h:104
T hexical_cast(U input)
Definition: Util.h:43
virtual icl_core::String stringValue() const
Definition: ConfigValue.h:97
virtual bool get(std::string const &prefix, icl_core::logging::LogStream &log_stream) const
Definition: ConfigValue.h:68
Implements a thread-safe logging framework.
Definition: LogStream.h:54
virtual icl_core::String key() const
Definition: ConfigValue.h:90
bool strict_bool_cast(U input)
Definition: Util.h:87
bool get(const String &key, typename ConvertToRef< T >::ToRef value) const
Utility functions for the configuration framework.
std::string String
Definition: BaseTypes.h:43
Contains ConfigManager.
Contains Interface base classes and base types.
icl_core::ConvertToRef< T >::ToRef m_value
Definition: ConfigValue.h:105


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