#include <utility>
#include <boost/any.hpp>
-#include <cassert>
/**
* Use this macro to declare and register config fields
template<typename Visitor> \
void accept(Visitor v) const { \
const std::string name = getOptionName(); \
- assert(!name.empty() && "Type is not set"); \
+ if (name.empty()) { \
+ throw config::ConfigException("Type is not set"); \
+ } \
v.visit("type", name); \
visitOption(v, name); \
} \
} \
template<typename Type> \
typename std::enable_if<!std::is_const<Type>::value, Type>::type& as() { \
- assert(!getHolder().empty()); \
+ if (getHolder().empty()) { \
+ throw config::ConfigException("Type is not set"); \
+ } \
return boost::any_cast<Type&>(getHolder()); \
} \
template<typename Type> \
const Type& as() const { \
- assert(!getHolder().empty()); \
+ if (getHolder().empty()) { \
+ throw config::ConfigException("Type is not set"); \
+ } \
return boost::any_cast<const Type&>(getHolder()); \
} \
bool isSet() { \
template<typename Type> \
Type& set(const Type& src) { \
getHolder() = std::forward<const Type>(src); \
- assert(!getOptionName().empty() && "Unsupported type"); \
+ if (getOptionName().empty()) { \
+ throw config::ConfigException("Unsupported type"); \
+ } \
return as<Type>(); \
} \