ConfigValueDefault.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 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #ifndef ICL_CORE_CONFIG_CONFIG_VALUE_DEFAULT_H_INCLUDED
00024 #define ICL_CORE_CONFIG_CONFIG_VALUE_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/ConfigValue.h"
00031 #include "icl_core_config/Util.h"
00032 
00033 #define CONFIG_VALUE_DEFAULT(key, value, default_value)                 \
00034   (new icl_core::config::ConfigValueDefault<ICL_CORE_CONFIG_TYPEOF(value)>(key, value, default_value))
00035 
00036 namespace icl_core {
00037 namespace config {
00038 
00042 template <typename T>
00043 class ConfigValueDefault : public ConfigValue<T>
00044 {
00045 public:
00049   ConfigValueDefault(const icl_core::String& key,
00050                      typename icl_core::ConvertToRef<T>::ToRef value,
00051                      typename icl_core::ConvertToRef<T>::ToConstRef default_value)
00052     : ConfigValue<T>(key, value),
00053       m_default_value(default_value)
00054   { }
00055 
00058   virtual ~ConfigValueDefault() {}
00059 
00062   virtual bool get(std::string const & prefix, icl_core::logging::LogStream& log_stream) const
00063   {
00064     if (!ConfigValue<T>::get(prefix, log_stream))
00065     {
00066       this->m_value = m_default_value;
00067       this->m_str_value = impl::hexical_cast<icl_core::String>(this->m_value);
00068     }
00069     return true;
00070   }
00071 
00072 private:
00073   typename icl_core::ConvertToRef<T>::ToConstRef m_default_value;
00074 };
00075 
00076 }}
00077 
00078 #endif


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