ConfigEnum.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 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
22 #ifndef ICL_CORE_CONFIG_CONFIG_ENUM_H_INCLUDED
23 #define ICL_CORE_CONFIG_CONFIG_ENUM_H_INCLUDED
24 
25 #include <icl_core/BaseTypes.h>
26 #include <icl_core/EnumHelper.h>
28 
32 
33 #define CONFIG_ENUM(key, value, descriptions) \
34  (new icl_core::config::ConfigEnum<ICL_CORE_CONFIG_TYPEOF(value)>(key, value, descriptions))
35 
36 namespace icl_core {
37 namespace config {
38 
41 template <typename T>
43 {
44 public:
49  typename icl_core::ConvertToRef<T>::ToRef value,
50  const char * const *descriptions,
51  const char *end_marker = NULL)
52  : m_key(key),
53  m_value(value),
54  m_descriptions(descriptions),
55  m_end_marker(end_marker)
56  { }
57 
60  virtual ~ConfigEnum() {}
61 
64  virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
65  {
67  {
68  int32_t raw_value;
70  {
71  m_value = T(raw_value);
72  return true;
73  }
74  else
75  {
76  return false;
77  }
78  }
79  else
80  {
81  return false;
82  }
83  }
84 
87  virtual icl_core::String key() const
88  {
89  return m_key;
90  }
91 
94  virtual icl_core::String stringValue() const
95  {
96  return m_str_value;
97  }
98 
99 protected:
103  const char * const *m_descriptions;
104  const char *m_end_marker;
105 };
106 
107 }}
108 
109 #endif
Helper definitions for template programming.
signed int int32_t
Definition: msvc_stdint.h:90
static ConfigManager & instance()
icl_core::String m_key
Definition: ConfigEnum.h:100
bool string2Enum(const String &str, int32_t &value, const char *const *descriptions, const char *end_marker)
Definition: EnumHelper.cpp:28
icl_core::ConvertToRef< T >::ToRef m_value
Definition: ConfigEnum.h:102
Implements a thread-safe logging framework.
Definition: LogStream.h:54
bool get(const String &key, typename ConvertToRef< T >::ToRef value) const
virtual icl_core::String key() const
Definition: ConfigEnum.h:87
std::string String
Definition: BaseTypes.h:43
Contains ConfigManager.
Contains Interface base classes and base types.
virtual icl_core::String stringValue() const
Definition: ConfigEnum.h:94
Contains helper functions to handle enums with textual descriptions.
icl_core::String m_str_value
Definition: ConfigEnum.h:101
const char *const * m_descriptions
Definition: ConfigEnum.h:103
ConfigEnum(const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToRef value, const char *const *descriptions, const char *end_marker=NULL)
Definition: ConfigEnum.h:48


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