cql3::statements::property_definitions: Use std::variant instead of any

Formalizing what stuff we actually keep in the props. And c++17.
This commit is contained in:
Calle Wilund
2018-01-31 12:10:44 +00:00
parent 0dcf287230
commit 3e8cfbf2a0
2 changed files with 12 additions and 9 deletions

View File

@@ -87,8 +87,8 @@ std::experimental::optional<sstring> property_definitions::get_simple(const sstr
return std::experimental::nullopt;
}
try {
return boost::any_cast<sstring>(it->second);
} catch (const boost::bad_any_cast& e) {
return std::get<sstring>(it->second);
} catch (const std::bad_variant_access& e) {
throw exceptions::syntax_exception(sprint("Invalid value for property '%s'. It should be a string", name));
}
}
@@ -99,8 +99,8 @@ std::experimental::optional<std::map<sstring, sstring>> property_definitions::ge
return std::experimental::nullopt;
}
try {
return boost::any_cast<std::map<sstring, sstring>>(it->second);
} catch (const boost::bad_any_cast& e) {
return std::get<map_type>(it->second);
} catch (const std::bad_variant_access& e) {
throw exceptions::syntax_exception(sprint("Invalid value for property '%s'. It should be a map.", name));
}
}
@@ -188,10 +188,10 @@ void property_definitions::remove_from_map_if_exists(const sstring& name, const
return;
}
try {
auto map = boost::any_cast<std::map<sstring, sstring>>(it->second);
auto map = std::get<map_type>(it->second);
map.erase(key);
_properties[name] = map;
} catch (const boost::bad_any_cast& e) {
} catch (const std::bad_variant_access& e) {
throw exceptions::syntax_exception(sprint("Invalid value for property '%s'. It should be a map.", name));
}
}

View File

@@ -52,19 +52,22 @@
#include <string>
#include <map>
#include <set>
#include <boost/any.hpp>
#include <variant>
namespace cql3 {
namespace statements {
class property_definitions {
public:
using map_type = std::map<sstring, sstring>;
using value_type = std::variant<sstring, map_type>;
protected:
#if 0
protected static final Logger logger = LoggerFactory.getLogger(PropertyDefinitions.class);
#endif
std::unordered_map<sstring, boost::any> _properties;
std::unordered_map<sstring, value_type> _properties;
property_definitions();
public: