mirror of https://github.com/SeanOMik/libki.git
pclass: Fix CI build errors
This commit is contained in:
parent
38f69d722c
commit
595b6167c0
|
@ -21,14 +21,14 @@ namespace pclass
|
||||||
struct value_caster_base
|
struct value_caster_base
|
||||||
{
|
{
|
||||||
virtual ~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:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Provides a nice way for specialized casters to throw with a
|
* Provides a nice way for specialized casters to throw with a
|
||||||
* consistent error when casting is not possible.
|
* 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.
|
* @returns A Value with a reference that has been casted to the destination type.
|
||||||
*/
|
*/
|
||||||
template <typename DstT>
|
template <typename DstT>
|
||||||
Value cast(Value &value) const;
|
Value cast(const Value &value) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
value_caster_base *m_caster;
|
value_caster_base *m_caster;
|
||||||
|
@ -137,7 +137,7 @@ namespace pclass
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
inline Value value_caster_base::bad_cast(
|
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;
|
std::ostringstream oss;
|
||||||
oss << "Cannot cast Value from " << src_type.name()
|
oss << "Cannot cast Value from " << src_type.name()
|
||||||
|
@ -146,9 +146,9 @@ namespace pclass
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename DstT>
|
template <typename DstT>
|
||||||
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 &>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,7 +157,7 @@ namespace pclass
|
||||||
template <typename SrcT>
|
template <typename SrcT>
|
||||||
struct value_caster_helper : value_caster_base
|
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);
|
return bad_cast(typeid(SrcT), dst_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,16 +52,30 @@ namespace pclass
|
||||||
|
|
||||||
void write_to(BitStream &stream, const Value &value) const override
|
void write_to(BitStream &stream, const Value &value) const override
|
||||||
{
|
{
|
||||||
if (!value.is<ValueT>())
|
try
|
||||||
throw std::runtime_error("Invalid call to Type::write_to -- value type does not match ValueT.");
|
{
|
||||||
PrimitiveTypeWriter<ValueT>::write_to(stream, value.get<ValueT>());
|
PrimitiveTypeWriter<ValueT>::write_to(stream, value.get<ValueT>());
|
||||||
|
}
|
||||||
|
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
|
void read_from(BitStream &stream, Value &value) const override
|
||||||
{
|
{
|
||||||
if (!value.is<ValueT>())
|
try
|
||||||
throw std::runtime_error("Invalid call to Type::read_from -- value type does not match ValueT.");
|
{
|
||||||
PrimitiveTypeReader<ValueT>::read_from(stream, value.get<ValueT>());
|
PrimitiveTypeReader<ValueT>::read_from(stream, value.get<ValueT>());
|
||||||
|
}
|
||||||
|
catch (runtime_error &e)
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Invalid call to Type::read_from -- " << e.what();
|
||||||
|
throw runtime_error(oss.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue