From 595b6167c055f4117c080ed97f50aaaede58f10e Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Wed, 5 Dec 2018 00:45:01 +0000 Subject: [PATCH] pclass: Fix CI build errors --- include/ki/pclass/Value.h | 14 ++++++------- include/ki/pclass/types/PrimitiveType.h | 26 +++++++++++++++++++------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/ki/pclass/Value.h b/include/ki/pclass/Value.h index 8514f1c..b7e258a 100644 --- a/include/ki/pclass/Value.h +++ b/include/ki/pclass/Value.h @@ -21,14 +21,14 @@ namespace pclass struct value_caster_base { virtual ~value_caster_base() {} - virtual Value cast(const type_info &dst_type, Value &v) const = 0; + virtual Value cast(const std::type_info &dst_type, Value &v) const = 0; protected: /** * Provides a nice way for specialized casters to throw with a * consistent error when casting is not possible. */ - Value bad_cast(const type_info &src_type, const type_info &dst_type) const; + Value bad_cast(const std::type_info &src_type, const std::type_info &dst_type) const; }; /** @@ -45,7 +45,7 @@ namespace pclass * @returns A Value with a reference that has been casted to the destination type. */ template - Value cast(Value &value) const; + Value cast(const Value &value) const; private: value_caster_base *m_caster; @@ -137,7 +137,7 @@ namespace pclass namespace detail { inline Value value_caster_base::bad_cast( - const type_info& src_type, const type_info& dst_type) const + const std::type_info& src_type, const std::type_info& dst_type) const { std::ostringstream oss; oss << "Cannot cast Value from " << src_type.name() @@ -146,9 +146,9 @@ namespace pclass } template - Value value_caster::cast(Value& value) const + Value value_caster::cast(const Value &value) const { - return m_caster->cast(typeid(DstT), value); + return m_caster->cast(typeid(DstT), const_cast(value)); } /** @@ -157,7 +157,7 @@ namespace pclass template struct value_caster_helper : value_caster_base { - Value cast(const type_info &dst_type, Value& value) const override + Value cast(const std::type_info &dst_type, Value& value) const override { return bad_cast(typeid(SrcT), dst_type); } diff --git a/include/ki/pclass/types/PrimitiveType.h b/include/ki/pclass/types/PrimitiveType.h index 55d3b88..a27280e 100644 --- a/include/ki/pclass/types/PrimitiveType.h +++ b/include/ki/pclass/types/PrimitiveType.h @@ -52,16 +52,30 @@ namespace pclass void write_to(BitStream &stream, const Value &value) const override { - if (!value.is()) - throw std::runtime_error("Invalid call to Type::write_to -- value type does not match ValueT."); - PrimitiveTypeWriter::write_to(stream, value.get()); + try + { + PrimitiveTypeWriter::write_to(stream, value.get()); + } + catch (runtime_error &e) + { + std::ostringstream oss; + oss << "Invalid call to Type::write_to -- " << e.what(); + throw runtime_error(oss.str()); + } } void read_from(BitStream &stream, Value &value) const override { - if (!value.is()) - throw std::runtime_error("Invalid call to Type::read_from -- value type does not match ValueT."); - PrimitiveTypeReader::read_from(stream, value.get()); + try + { + PrimitiveTypeReader::read_from(stream, value.get()); + } + catch (runtime_error &e) + { + std::ostringstream oss; + oss << "Invalid call to Type::read_from -- " << e.what(); + throw runtime_error(oss.str()); + } } }; }