adding fstream, fix bugs
This commit is contained in:
parent
53bb959c5d
commit
ba4eb96d88
6 changed files with 76 additions and 7 deletions
|
|
@ -67,6 +67,7 @@ set( sources
|
|||
src/log.cpp
|
||||
src/time.cpp
|
||||
src/iostream.cpp
|
||||
src/fstream.cpp
|
||||
src/sstream.cpp
|
||||
src/exception.cpp
|
||||
src/thread.cpp
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/shared_ptr.hpp>
|
||||
#include <fc/iostream.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
|
@ -19,7 +19,7 @@ namespace fc {
|
|||
|
||||
private:
|
||||
class impl;
|
||||
fwd<impl,896> my;
|
||||
fc::shared_ptr<impl> my;
|
||||
};
|
||||
|
||||
class ifstream : virtual public istream {
|
||||
|
|
@ -32,13 +32,10 @@ namespace fc {
|
|||
void open( const fc::path& file, int m );
|
||||
ifstream& read( char* buf, size_t len );
|
||||
void close();
|
||||
void flush();
|
||||
|
||||
bool eof()const;
|
||||
|
||||
private:
|
||||
class impl;
|
||||
fwd<impl,904> my;
|
||||
fc::shared_ptr<impl> my;
|
||||
};
|
||||
|
||||
} // namespace fc
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ namespace fc { namespace json {
|
|||
|
||||
template<typename InterfaceType>
|
||||
void add_interface( const fc::ptr<InterfaceType>& it ) {
|
||||
it->template visit<InterfaceType>( detail::add_method_visitor<InterfaceType>( it, *this ) );
|
||||
it->template visit( detail::add_method_visitor<InterfaceType>( it, *this ) );
|
||||
}
|
||||
|
||||
void add_method( const fc::string& name, const fc::json::rpc_server_method::ptr& func );
|
||||
|
|
|
|||
|
|
@ -77,4 +77,5 @@ namespace fc {
|
|||
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 ); }
|
||||
bool remove( const path& f ) { return boost::filesystem::remove( f ); }
|
||||
fc::path canonical( const fc::path& p ) { return boost::filesystem::canonical(p); }
|
||||
}
|
||||
|
|
|
|||
60
src/fstream.cpp
Normal file
60
src/fstream.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include <fc/fstream.hpp>
|
||||
#include <fc/filesystem.hpp>
|
||||
#include <fstream>
|
||||
|
||||
namespace fc {
|
||||
class ofstream::impl : public fc::retainable {
|
||||
public:
|
||||
std::ofstream ofs;
|
||||
};
|
||||
class ifstream::impl : public fc::retainable {
|
||||
public:
|
||||
std::ifstream ifs;
|
||||
};
|
||||
|
||||
ofstream::ofstream()
|
||||
:my( new impl() ){}
|
||||
|
||||
ofstream::ofstream( const fc::path& file, int m )
|
||||
:my( new impl() ) { this->open( file, m ); }
|
||||
ofstream::~ofstream(){}
|
||||
|
||||
void ofstream::open( const fc::path& file, int m ) {
|
||||
my->ofs.open( file.string().c_str(), std::ios::binary );
|
||||
}
|
||||
ofstream& ofstream::write( const char* buf, size_t len ) {
|
||||
my->ofs.write(buf,len);
|
||||
return *this;
|
||||
}
|
||||
void ofstream::put( char c ) {
|
||||
my->ofs.put(c);
|
||||
}
|
||||
void ofstream::close() {
|
||||
my->ofs.close();
|
||||
}
|
||||
void ofstream::flush() {
|
||||
my->ofs.flush();
|
||||
}
|
||||
|
||||
ifstream::ifstream()
|
||||
:my(new impl()){}
|
||||
ifstream::ifstream( const fc::path& file, int m )
|
||||
:my(new impl())
|
||||
{
|
||||
this->open( file, m );
|
||||
}
|
||||
ifstream::~ifstream(){}
|
||||
|
||||
void ifstream::open( const fc::path& file, int m ) {
|
||||
my->ifs.open( file.string().c_str(), std::ios::binary );
|
||||
}
|
||||
ifstream& ifstream::read( char* buf, size_t len ) {
|
||||
my->ifs.read(buf,len);
|
||||
return *this;
|
||||
}
|
||||
void ifstream::close() { return my->ifs.close(); }
|
||||
|
||||
bool ifstream::eof()const { return my->ifs.eof(); }
|
||||
|
||||
|
||||
} // namespace fc
|
||||
10
src/sha1.cpp
10
src/sha1.cpp
|
|
@ -3,6 +3,8 @@
|
|||
#include <fc/fwd_impl.hpp>
|
||||
#include <openssl/sha.h>
|
||||
#include <string.h>
|
||||
#include <fc/filesystem.hpp>
|
||||
#include <fc/interprocess/file_mapping.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
|
|
@ -36,6 +38,14 @@ namespace fc {
|
|||
sha1 sha1::hash( const fc::string& s ) {
|
||||
return hash( s.c_str(), s.size() );
|
||||
}
|
||||
sha1 sha1::hash( const fc::path& s ) {
|
||||
file_mapping fmap( s.string().c_str(), read_only );
|
||||
size_t fsize = file_size(s);
|
||||
mapped_region mr( fmap, fc::read_only, 0, fsize );
|
||||
|
||||
const char* pos = reinterpret_cast<const char*>(mr.get_address());
|
||||
return hash( pos, fsize );
|
||||
}
|
||||
|
||||
void sha1::encoder::write( const char* d, uint32_t dlen ) {
|
||||
SHA1_Update( &my->ctx, d, dlen);
|
||||
|
|
|
|||
Loading…
Reference in a new issue