ConfigEnumDefault.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 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #ifndef ICL_CORE_CONFIG_CONFIG_ENUM_DEFAULT_H_INCLUDED
00024 #define ICL_CORE_CONFIG_CONFIG_ENUM_DEFAULT_H_INCLUDED
00025 
00026 #include <icl_core/BaseTypes.h>
00027 #include <icl_core/TemplateHelper.h>
00028 
00029 #include "icl_core_config/ConfigHelper.h"
00030 #include "icl_core_config/ConfigEnum.h"
00031 #include "icl_core_config/Util.h"
00032 
00033 #define CONFIG_ENUM_DEFAULT(key, value, default_value, descriptions)                            \
00034   (new icl_core::config::ConfigEnumDefault<ICL_CORE_CONFIG_TYPEOF(value)>(key, value, default_value, descriptions))
00035 
00036 namespace icl_core {
00037 namespace config {
00038 
00042 template <typename T>
00043 class ConfigEnumDefault : public ConfigEnum<T>
00044 {
00045 public:
00049   ConfigEnumDefault(const icl_core::String& key,
00050                     typename icl_core::ConvertToRef<T>::ToRef value,
00051                     typename icl_core::ConvertToRef<T>::ToConstRef default_value,
00052                     const char * const * descriptions,
00053                     const char * end_marker = NULL)
00054     : ConfigEnum<T>(key, value, descriptions, end_marker),
00055       m_default_value(default_value)
00056   { }
00057 
00060   virtual ~ConfigEnumDefault() {}
00061 
00064   virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
00065   {
00066     if (!ConfigEnum<T>::get(prefix, log_stream))
00067     {
00068       this->m_value = m_default_value;
00069       this->m_str_value = impl::hexical_cast<icl_core::String>(this->m_value);
00070     }
00071     return true;
00072   }
00073 
00074 private:
00075   typename icl_core::ConvertToRef<T>::ToConstRef m_default_value;
00076 };
00077 
00078 }}
00079 
00080 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03