serialization and copy support for exceptions
This commit is contained in:
parent
36d657fb62
commit
4385bbe49a
5 changed files with 65 additions and 1 deletions
|
|
@ -110,6 +110,9 @@ namespace fc
|
||||||
|
|
||||||
friend void to_variant( const exception& e, variant& v );
|
friend void to_variant( const exception& e, variant& v );
|
||||||
friend void from_variant( const variant& e, exception& ll );
|
friend void from_variant( const variant& e, exception& ll );
|
||||||
|
|
||||||
|
exception& operator=( const exception& copy );
|
||||||
|
exception& operator=( exception&& copy );
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<detail::exception_impl> my;
|
std::unique_ptr<detail::exception_impl> my;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,42 @@
|
||||||
|
|
||||||
namespace fc {
|
namespace fc {
|
||||||
namespace raw {
|
namespace raw {
|
||||||
|
template<typename Stream>
|
||||||
|
inline void pack( Stream& s, const fc::exception& e )
|
||||||
|
{
|
||||||
|
fc::raw::pack( s, e.code() );
|
||||||
|
fc::raw::pack( s, std::string(e.name()) );
|
||||||
|
fc::raw::pack( s, std::string(e.what()) );
|
||||||
|
fc::raw::pack( s, e.get_log() );
|
||||||
|
}
|
||||||
|
template<typename Stream>
|
||||||
|
inline void unpack( Stream& s, fc::exception& e )
|
||||||
|
{
|
||||||
|
int64_t code;
|
||||||
|
std::string name, what;
|
||||||
|
log_messages msgs;
|
||||||
|
|
||||||
|
fc::raw::unpack( s, code );
|
||||||
|
fc::raw::unpack( s, name );
|
||||||
|
fc::raw::unpack( s, what );
|
||||||
|
fc::raw::unpack( s, msgs );
|
||||||
|
|
||||||
|
e = fc::exception( fc::move(msgs), code, name, what );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
inline void pack( Stream& s, const fc::log_message& msg )
|
||||||
|
{
|
||||||
|
fc::raw::pack( s, variant(msg) );
|
||||||
|
}
|
||||||
|
template<typename Stream>
|
||||||
|
inline void unpack( Stream& s, fc::log_message& msg )
|
||||||
|
{
|
||||||
|
fc::variant vmsg;
|
||||||
|
fc::raw::unpack( s, vmsg );
|
||||||
|
msg = vmsg.as<log_message>();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
inline void pack( Stream& s, const fc::path& tp )
|
inline void pack( Stream& s, const fc::path& tp )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,8 @@ namespace fc
|
||||||
|
|
||||||
} // namespace fc
|
} // namespace fc
|
||||||
|
|
||||||
|
FC_REFLECT_TYPENAME( fc::log_message );
|
||||||
|
|
||||||
#ifndef __func__
|
#ifndef __func__
|
||||||
#define __func__ __FUNCTION__
|
#define __func__ __FUNCTION__
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
namespace fc {
|
namespace fc {
|
||||||
class value;
|
class value;
|
||||||
|
class exception;
|
||||||
template<typename T> class get_typename{};
|
template<typename T> class get_typename{};
|
||||||
template<> struct get_typename<int32_t> { static const char* name() { return "int32_t"; } };
|
template<> struct get_typename<int32_t> { static const char* name() { return "int32_t"; } };
|
||||||
template<> struct get_typename<int64_t> { static const char* name() { return "int64_t"; } };
|
template<> struct get_typename<int64_t> { static const char* name() { return "int64_t"; } };
|
||||||
|
|
@ -18,7 +19,8 @@ namespace fc {
|
||||||
template<> struct get_typename<char> { static const char* name() { return "char"; } };
|
template<> struct get_typename<char> { static const char* name() { return "char"; } };
|
||||||
template<> struct get_typename<void> { static const char* name() { return "char"; } };
|
template<> struct get_typename<void> { static const char* name() { return "char"; } };
|
||||||
template<> struct get_typename<string> { static const char* name() { return "string"; } };
|
template<> struct get_typename<string> { static const char* name() { return "string"; } };
|
||||||
template<> struct get_typename<value> { static const char* name() { return "value"; } };
|
template<> struct get_typename<value> { static const char* name() { return "value"; } };
|
||||||
|
template<> struct get_typename<fc::exception> { static const char* name() { return "fc::exception"; } };
|
||||||
template<> struct get_typename<std::vector<char>> { static const char* name() { return "std::vector<char>"; } };
|
template<> struct get_typename<std::vector<char>> { static const char* name() { return "std::vector<char>"; } };
|
||||||
|
|
||||||
struct signed_int;
|
struct signed_int;
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,16 @@ namespace fc
|
||||||
log_messages _elog;
|
log_messages _elog;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
exception::exception( log_messages&& msgs, int64_t code,
|
||||||
|
const std::string& name_value,
|
||||||
|
const std::string& what_value )
|
||||||
|
:my( new detail::exception_impl() )
|
||||||
|
{
|
||||||
|
my->_code = code;
|
||||||
|
my->_what = what_value;
|
||||||
|
my->_name = name_value;
|
||||||
|
my->_elog = fc::move(msgs);
|
||||||
|
}
|
||||||
|
|
||||||
unhandled_exception::unhandled_exception( log_message&& m, std::exception_ptr e )
|
unhandled_exception::unhandled_exception( log_message&& m, std::exception_ptr e )
|
||||||
:exception( fc::move(m) )
|
:exception( fc::move(m) )
|
||||||
|
|
@ -202,5 +212,16 @@ namespace fc
|
||||||
throw null_optional();
|
throw null_optional();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
exception& exception::operator=( const exception& copy )
|
||||||
|
{
|
||||||
|
*my = *copy.my;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
exception& exception::operator=( exception&& copy )
|
||||||
|
{
|
||||||
|
my = std::move(copy.my);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
} // fc
|
} // fc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue