diff --git a/include/fc/error_report.hpp b/include/fc/error_report.hpp index 2efdb2e..7b088d7 100644 --- a/include/fc/error_report.hpp +++ b/include/fc/error_report.hpp @@ -13,7 +13,7 @@ namespace fc { class error_frame { public: error_frame( const fc::string& file, uint64_t line, const fc::string& method, const fc::string& desc, fc::value m ); - error_frame(){} + error_frame():file("unknown-file"),line(0){} error_frame(const error_frame& ); error_frame(error_frame&& ); @@ -55,6 +55,7 @@ namespace fc { }; fc::string substitute( const fc::string& format, const fc::value& keys ); + fc::value recursive_substitute( const value& in, const fc::value& keys ); } // namespace fc diff --git a/include/fc/value.hpp b/include/fc/value.hpp index 3061778..5403c0f 100644 --- a/include/fc/value.hpp +++ b/include/fc/value.hpp @@ -189,10 +189,8 @@ namespace fc { ~key_val(){ } key_val& operator=( key_val&& k ) { - slog( "swap key"); fc_swap( key, k.key ); - slog( "swap val"); - fc_swap( val, k.val ); + fc_swap( val, k.val ); return *this; } diff --git a/include/fc/value_cast.hpp b/include/fc/value_cast.hpp index ce7afa5..6c4968c 100644 --- a/include/fc/value_cast.hpp +++ b/include/fc/value_cast.hpp @@ -181,8 +181,7 @@ namespace fc { int idx = 0; for( auto i = a.fields.begin(); i != a.fields.end(); ++i ) { try { - m_out.push_back(T()); - unpack( *i, m_out.back() ); + m_out.push_back( value_cast( *i ) ); } catch( fc::error_report& er ) { throw FC_REPORT_PUSH( er, "Error parsing array index ${index} to ${type}", fc::value().set("index", idx).set("type",fc::get_typename::name()) ); @@ -234,9 +233,7 @@ namespace fc { template void operator()( Member& m ) { try { - //m = value_cast(_val[idx]); - unpack( _val[idx], m ); - // m = value_cast(_val[idx]); + m = value_cast(_val[idx]); } catch ( fc::error_report& er ) { throw FC_REPORT_PUSH( er, "Error parsing tuple element ${index}", fc::value().set("index",idx) ); } @@ -332,9 +329,6 @@ namespace fc { } template T value::cast()const { - T tmp; - unpack(*this,tmp); - return tmp; -// return unpackvalue_cast(*this); + return value_cast(*this); } } diff --git a/src/error_report.cpp b/src/error_report.cpp index ec4c588..c66e6d3 100644 --- a/src/error_report.cpp +++ b/src/error_report.cpp @@ -135,6 +135,28 @@ fc::string substitute( const fc::string& format, const fc::value& keys ) { return ss.str(); } +/** + * Performs variable substitution on all strings in keys or values of 'in' with + * values from keys. + */ +fc::value recursive_substitute( const value& in, const fc::value& keys ) { + fc::value out; + if( in.is_string() ) { + return fc::substitute( in.cast(), keys ); + } + else if( in.is_object() ) { + for( auto itr = in.begin(); itr != in.end(); ++itr ) { + out[fc::substitute(itr->key, keys)] = recursive_substitute( itr->val, keys ); + } + return out; + } + else if( in.is_array() ) { + for( size_t i = 0; i < in.size(); ++i ) { + out.push_back( recursive_substitute( in[i], keys ) ); + } + } + return in; +} fc::string error_report::to_string()const { fc::stringstream ss; diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 3cd8e98..48fa7b5 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -138,7 +138,7 @@ namespace fc { void remove_all( const path& p ) { boost::filesystem::remove_all(p); } void copy( const path& f, const path& t ) { try { - boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); + boost::filesystem::copy( boost::filesystem::path(f), boost::filesystem::path(t) ); } catch ( boost::system::system_error& e ) { FC_THROW_REPORT( "Copy from ${srcfile} to ${dstfile} failed because ${reason}", fc::value().set("srcfile",f).set("dstfile",t).set("reason",e.what() ) ); @@ -147,9 +147,29 @@ namespace fc { fc::value().set("srcfile",f).set("dstfile",t).set("inner", fc::except_str() ) ); } } - void create_hard_link( const path& f, const path& t ) { boost::filesystem::create_hard_link( f, t ); } - bool remove( const path& f ) { return boost::filesystem::remove( f ); } - fc::path canonical( const fc::path& p ) { return boost::filesystem::canonical(p); } + void create_hard_link( const path& f, const path& t ) { + try { + boost::filesystem::create_hard_link( f, t ); + } catch ( ... ) { + FC_THROW_REPORT( "Unable to create hard link from '${from}' to '${to}'", + fc::value().set( "from", f ) + .set("to",t).set("exception", fc::except_str() ) ); + } + } + bool remove( const path& f ) { + try { + boost::filesystem::remove( f ); + } catch ( ... ) { + FC_THROW_REPORT( "Unable to remove '${path}'", fc::value().set( "path", f ).set("exception", fc::except_str() ) ); + } + } + fc::path canonical( const fc::path& p ) { + try { + return boost::filesystem::canonical(p); + } catch ( ... ) { + FC_THROW_REPORT( "Unable to resolve path '${path}'", fc::value().set( "path", p ).set("exception", fc::except_str() ) ); + } + } fc::path absolute( const fc::path& p ) { return boost::filesystem::absolute(p); } path unique_path() { return boost::filesystem::unique_path(); } path temp_directory_path() { return boost::filesystem::temp_directory_path(); } diff --git a/src/json_rpc_stream_connection.cpp b/src/json_rpc_stream_connection.cpp index 285c787..1aa7a59 100644 --- a/src/json_rpc_stream_connection.cpp +++ b/src/json_rpc_stream_connection.cpp @@ -39,6 +39,7 @@ namespace fc { namespace json { while( !in.eof() ) { // std::cerr<<"\n**line size: "<