#define CONFIG_FIELDS_UNION_HPP
#include "config/fields.hpp"
+#include "config/exception.hpp"
+
#include <utility>
#include <boost/any.hpp>
#include <cassert>
template<typename Visitor> \
void visitOption(Visitor& v, const std::string& name) { \
GENERATE_CODE(GENERATE_UNION_VISIT__, __VA_ARGS__) \
+ throw config::ConfigException("Union type error. Unsupported type"); \
} \
template<typename Visitor> \
void visitOption(Visitor& v, const std::string& name) const { \
GENERATE_CODE(GENERATE_UNION_VISIT_CONST__, __VA_ARGS__) \
+ throw config::ConfigException("Union type error. Unsupported type"); \
} \
std::string getOptionName() const { \
GENERATE_CODE(GENERATE_UNION_NAME__, __VA_ARGS__) \
template<typename Visitor> \
void accept(Visitor v) const { \
const std::string name = getOptionName(); \
- if (!name.empty()) { \
- v.visit("type", name); \
- visitOption(v, name); \
- } else { \
- /* Unsupported type */ \
- } \
+ assert(!name.empty() && "Type is not set"); \
+ v.visit("type", name); \
+ visitOption(v, name); \
} \
\
template<typename Type> \
template<typename Type> \
Type& set(const Type& src) { \
getHolder() = std::forward<const Type>(src); \
+ assert(!getOptionName().empty() && "Unsupported type"); \
return as<Type>(); \
} \
#define GENERATE_UNION_VISIT__(r, _, TYPE_) \
if (#TYPE_ == name) { \
v.visit("value", set(std::move(TYPE_()))); \
+ return; \
}
#define GENERATE_UNION_VISIT_CONST__(r, _, TYPE_) \
if (#TYPE_ == name) { \
v.visit("value", as<const TYPE_>()); \
+ return; \
}
#define GENERATE_UNION_NAME__(r, _, TYPE_) \