Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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