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,6 +25,8 @@ namespace fc {
class ifstream : virtual public istream { class ifstream : virtual public istream {
public: public:
enum mode { in, binary }; enum mode { in, binary };
enum seekdir { beg, cur, end };
ifstream(); ifstream();
ifstream( const fc::path& file, int m ); ifstream( const fc::path& file, int m );
~ifstream(); ~ifstream();
@ -32,6 +34,8 @@ namespace fc {
void open( const fc::path& file, int m ); void open( const fc::path& file, int m );
size_t readsome( char* buf, size_t len ); size_t readsome( char* buf, size_t len );
ifstream& read( char* buf, size_t len ); ifstream& read( char* buf, size_t len );
ifstream& seekg( size_t p, seekdir d = beg );
void get( char& c ) { read( &c, 1 ); }
void close(); void close();
bool eof()const; bool eof()const;
private: private:

View file

@ -61,6 +61,9 @@ namespace fc {
uint32_t _hash[5]; 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); my->ifs.read(buf,len);
return *this; 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(); } void ifstream::close() { return my->ifs.close(); }
bool ifstream::eof()const { return my->ifs.eof(); } bool ifstream::eof()const { return my->ifs.eof(); }

View file

@ -5,6 +5,8 @@
#include <string.h> #include <string.h>
#include <fc/filesystem.hpp> #include <fc/filesystem.hpp>
#include <fc/interprocess/file_mapping.hpp> #include <fc/interprocess/file_mapping.hpp>
#include <fc/value.hpp>
#include <fc/value_cast.hpp>
namespace fc { namespace fc {
@ -93,5 +95,12 @@ namespace fc {
return memcmp( h1._hash, h2._hash, sizeof(h1._hash) ) == 0; 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 } // namespace fc