bug fixes

This commit is contained in:
Daniel Larimer 2012-12-02 16:46:28 -05:00
parent 2e6bd7253f
commit 0995ce7e31
4 changed files with 27 additions and 4 deletions

View file

@ -25,15 +25,19 @@ namespace fc {
class ifstream : virtual public istream {
public:
enum mode { in, binary };
enum seekdir { beg, cur, end };
ifstream();
ifstream( const fc::path& file, int m );
~ifstream();
void open( const fc::path& file, int m );
size_t readsome( char* buf, size_t len );
void open( const fc::path& file, int m );
size_t readsome( char* buf, size_t len );
ifstream& read( char* buf, size_t len );
void close();
bool eof()const;
ifstream& seekg( size_t p, seekdir d = beg );
void get( char& c ) { read( &c, 1 ); }
void close();
bool eof()const;
private:
class impl;
fc::shared_ptr<impl> my;

View file

@ -61,6 +61,9 @@ namespace fc {
uint32_t _hash[5];
};
class value;
void pack( fc::value& , const fc::sha1& );
void unpack( const fc::value& , fc::sha1& );
}

View file

@ -55,6 +55,13 @@ namespace fc {
my->ifs.read(buf,len);
return *this;
}
ifstream& ifstream::seekg( size_t p, seekdir d ) {
switch( d ) {
case beg: my->ifs.seekg( p, std::ios_base::beg ); return *this;
case cur: my->ifs.seekg( p, std::ios_base::cur ); return *this;
case end: my->ifs.seekg( p, std::ios_base::end ); return *this;
}
}
void ifstream::close() { return my->ifs.close(); }
bool ifstream::eof()const { return my->ifs.eof(); }

View file

@ -5,6 +5,8 @@
#include <string.h>
#include <fc/filesystem.hpp>
#include <fc/interprocess/file_mapping.hpp>
#include <fc/value.hpp>
#include <fc/value_cast.hpp>
namespace fc {
@ -92,6 +94,13 @@ namespace fc {
bool operator == ( const fc::sha1& h1, const fc::sha1& h2 ) {
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0;
}
void pack( fc::value& v, const fc::sha1& s ) {
v = fc::string(s);
}
void unpack( const fc::value& v, fc::sha1& s ) {
s = sha1(fc::value_cast<fc::string>(v));
}
} // namespace fc