ConfigEnum.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00021 //----------------------------------------------------------------------
00022 #ifndef ICL_CORE_CONFIG_CONFIG_ENUM_H_INCLUDED
00023 #define ICL_CORE_CONFIG_CONFIG_ENUM_H_INCLUDED
00024 
00025 #include <icl_core/BaseTypes.h>
00026 #include <icl_core/EnumHelper.h>
00027 #include <icl_core/TemplateHelper.h>
00028 
00029 #include "icl_core_config/ConfigHelper.h"
00030 #include "icl_core_config/ConfigManager.h"
00031 #include "icl_core_config/ConfigValueIface.h"
00032 
00033 #define CONFIG_ENUM(key, value, descriptions)                           \
00034   (new icl_core::config::ConfigEnum<ICL_CORE_CONFIG_TYPEOF(value)>(key, value, descriptions))
00035 
00036 namespace icl_core {
00037 namespace config {
00038 
00041 template <typename T>
00042 class ConfigEnum : public impl::ConfigValueIface
00043 {
00044 public:
00048   ConfigEnum(const icl_core::String& key,
00049              typename icl_core::ConvertToRef<T>::ToRef value,
00050              const char * const *descriptions,
00051              const char *end_marker = NULL)
00052     : m_key(key),
00053       m_value(value),
00054       m_descriptions(descriptions),
00055       m_end_marker(end_marker)
00056   { }
00057 
00060   virtual ~ConfigEnum() {}
00061 
00064   virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
00065   {
00066     if (ConfigManager::instance().get(prefix + m_key, m_str_value))
00067     {
00068       int32_t raw_value;
00069       if (icl_core::string2Enum(m_str_value, raw_value, m_descriptions, m_end_marker))
00070       {
00071         m_value = T(raw_value);
00072         return true;
00073       }
00074       else
00075       {
00076         return false;
00077       }
00078     }
00079     else
00080     {
00081       return false;
00082     }
00083   }
00084 
00087   virtual icl_core::String key() const
00088   {
00089     return m_key;
00090   }
00091 
00094   virtual icl_core::String stringValue() const
00095   {
00096     return m_str_value;
00097   }
00098 
00099 protected:
00100   icl_core::String m_key;
00101   mutable icl_core::String m_str_value;
00102   typename icl_core::ConvertToRef<T>::ToRef m_value;
00103   const char * const *m_descriptions;
00104   const char *m_end_marker;
00105 };
00106 
00107 }}
00108 
00109 #endif


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:18