diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index b7e5235..551dc42 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -64,6 +64,8 @@ namespace fc { void create_directories( const path& p ); path canonical( const path& p ); uint64_t file_size( const path& p ); + bool remove( const path& p ); + void copy( const path& from, const path& to ); } #endif // _FC_FILESYSTEM_HPP_ diff --git a/include/fc/fstream.hpp b/include/fc/fstream.hpp index 349d6f9..890d637 100644 --- a/include/fc/fstream.hpp +++ b/include/fc/fstream.hpp @@ -1,16 +1,17 @@ #pragma once #include +#include namespace fc { - - class ofstream //: virtual public ostream { + class path; + class ofstream : virtual public ostream { public: enum mode { out, binary }; ofstream(); - ofstream( const fc::string& file, int m ); + ofstream( const fc::path& file, int m = binary ); ~ofstream(); - void open( const fc::string& file, int m ); + void open( const fc::path& file, int m = binary ); ofstream& write( const char* buf, size_t len ); void put( char c ); void close(); @@ -21,14 +22,14 @@ namespace fc { fwd my; }; - class ifstream //: virtual public istream { + class ifstream : virtual public istream { public: enum mode { in, binary }; ifstream(); - ifstream( const fc::string& file, int m ); + ifstream( const fc::path& file, int m ); ~ifstream(); - void open( const fc::string& file, int m ); + void open( const fc::path& file, int m ); ifstream& read( char* buf, size_t len ); void close(); void flush(); diff --git a/include/fc/json_rpc_error_object.hpp b/include/fc/json_rpc_error_object.hpp index 656c150..6c6e999 100644 --- a/include/fc/json_rpc_error_object.hpp +++ b/include/fc/json_rpc_error_object.hpp @@ -1,4 +1,7 @@ #pragma once +#include +#include +#include namespace fc { namespace json { diff --git a/include/fc/sha1.hpp b/include/fc/sha1.hpp index cef850f..7d95e5b 100644 --- a/include/fc/sha1.hpp +++ b/include/fc/sha1.hpp @@ -4,6 +4,7 @@ #include namespace fc { + class path; class sha1 { public: @@ -18,6 +19,7 @@ namespace fc { static sha1 hash( const char* d, uint32_t dlen ); static sha1 hash( const fc::string& ); + static sha1 hash( const fc::path& ); template static sha1 hash( const T& t ) { sha1::encoder e; e << t; return e.result(); } diff --git a/include/fc/value.hpp b/include/fc/value.hpp index 11d1354..120d9f8 100644 --- a/include/fc/value.hpp +++ b/include/fc/value.hpp @@ -127,6 +127,14 @@ namespace fc { bool is_null()const; void visit( const_visitor&& v )const; + + /* sets the subkey key with v and return *this */ + value& set( const char* key, fc::value v ); + value& set( const fc::string& key, fc::value v ); + + template + value& set( S&& key, T&& v ) { return set( fc::forward(key), fc::value( fc::forward(v) ) ); } + private: /** throws exceptions on errors * diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 10236b8..cbd9983 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -75,4 +75,6 @@ namespace fc { bool is_directory( const path& p ) { return boost::filesystem::is_directory(p); } bool is_regular_file( const path& p ) { return boost::filesystem::is_regular_file(p); } uint64_t file_size( const path& p ) { return boost::filesystem::file_size(p); } + void copy( const path& f, const path& t ) { boost::filesystem::copy( f, t ); } + void remove( const path& f ) { boost::filesystem::remove( f, t ); } } diff --git a/src/json_rpc_error_object.cpp b/src/json_rpc_error_object.cpp index 3fc186d..944d5f1 100644 --- a/src/json_rpc_error_object.cpp +++ b/src/json_rpc_error_object.cpp @@ -1,6 +1,6 @@ #include namespace fc { namespace json { - error_object::error_object( const fc::string& msg, fc::value v, int c ) + error_object::error_object( const fc::string& m, fc::value v, int64_t c ) :code(c),message(m),data(fc::move(v)){} }} diff --git a/src/value.cpp b/src/value.cpp index a1c8a18..892ca12 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -48,6 +48,7 @@ namespace fc { struct value_holder_impl : value_holder { value_holder_impl(){}; // typedef void_t T; + /* virtual const char* type()const { return "void"; } virtual void visit( value::const_visitor&& v )const{ v(); } virtual void visit( value_visitor&& v ) { v(); } @@ -56,6 +57,7 @@ namespace fc { virtual value_holder* move_helper( char* c ){ return new(c) value_holder_impl(); } virtual value_holder* copy_helper( char* c )const{ return new(c) value_holder_impl();} + */ }; @@ -121,7 +123,10 @@ namespace fc { }; value_holder::~value_holder(){} - const char* value_holder::type()const { return "null"; } + const char* value_holder::type()const { return "void"; } + value_holder* value_holder::move_helper( char* c ) { return new(c) value_holder(); } + value_holder* value_holder::copy_helper( char* c )const { return new(c) value_holder(); } + void value_holder::visit( value::const_visitor&& v )const { v(); } void value_holder::visit( value_visitor&& v ) { v(); } @@ -133,8 +138,8 @@ namespace fc { const value& value_holder::at( size_t )const { FC_THROW_MSG("value type '%s' not an array", type()); return *((const value*)0); } void value_holder::push_back( value&& v ) { FC_THROW_MSG("value type '%s' not an array", type()); } - value_holder* value_holder::move_helper( char* c ) { return new(c) value_holder(); } - value_holder* value_holder::copy_helper( char* c )const{ return new(c) value_holder(); } + // value_holder* value_holder::move_helper( char* c ) = 0; + // value_holder* value_holder::copy_helper( char* c )const = 0; void value_holder_impl::resize( size_t s ) { val.fields.resize(s); } void value_holder_impl::reserve( size_t s ) { val.fields.reserve(s); } @@ -168,7 +173,7 @@ static const detail::value_holder* gh( const aligned<24>& h ) { } value::value() { - new (holder) detail::value_holder(); + new (holder) detail::value_holder_impl(); } value::value( value&& m ) { gh(m.holder)->move_helper(holder._store._data); @@ -180,7 +185,7 @@ value::value( char* c ) { new (holder) detail::value_holder_impl( c ); } value::~value() { - gh(holder)->~value_holder(); + gh(holder)->~value_holder_impl(); } value::value( int8_t v){ static_assert( sizeof(holder) >= sizeof( detail::value_holder_impl ), "size check" ); @@ -271,7 +276,7 @@ value& value::operator=( const value& v ){ return *this; } bool value::is_null()const { - return strcmp(gh(holder)->type(), "null") == 0; + return strcmp(gh(holder)->type(), "void") == 0; } @@ -314,7 +319,7 @@ value& value::operator[]( const char* key ) { } o->val.fields.push_back( key_val(key) ); return o->val.fields.back().val; - } else if (strcmp(gh(holder)->type(), "null" ) == 0 ) { + } else if (strcmp(gh(holder)->type(), "void" ) == 0 ) { new (holder) detail::value_holder_impl(value::object()); return (*this)[key]; }