peerplays-fc/include/fc/io/fstream.hpp

59 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
2012-11-15 17:37:56 +00:00
#include <fc/shared_ptr.hpp>
2013-01-20 20:44:16 +00:00
#include <fc/filesystem.hpp>
#include <fc/io/iostream.hpp>
2019-08-19 06:10:28 +00:00
#include <fstream>
namespace fc {
2012-11-15 16:55:36 +00:00
class path;
class ofstream : virtual public ostream {
public:
enum mode { out, binary };
ofstream();
2019-08-19 06:10:28 +00:00
ofstream( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
~ofstream();
2019-08-19 06:10:28 +00:00
void open( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
size_t writesome( const char* buf, size_t len );
size_t writesome(const std::shared_ptr<const char>& buffer, size_t len, size_t offset);
void put( char c );
void close();
void flush();
private:
class impl;
2012-11-15 17:37:56 +00:00
fc::shared_ptr<impl> my;
};
2012-11-15 16:55:36 +00:00
class ifstream : virtual public istream {
public:
enum mode { in, binary };
2012-12-02 21:46:28 +00:00
enum seekdir { beg, cur, end };
ifstream();
ifstream( const fc::path& file, int m = binary);
~ifstream();
2012-12-02 21:46:28 +00:00
void open( const fc::path& file, int m );
size_t readsome( char* buf, size_t len );
size_t readsome(const std::shared_ptr<char>& buffer, size_t max, size_t offset);
ifstream& read( char* buf, size_t len );
2012-12-02 21:46:28 +00:00
ifstream& seekg( size_t p, seekdir d = beg );
using istream::get;
2012-12-02 21:46:28 +00:00
void get( char& c ) { read( &c, 1 ); }
void close();
bool eof()const;
private:
class impl;
2012-11-15 17:37:56 +00:00
fc::shared_ptr<impl> my;
};
2015-08-04 15:50:56 +00:00
/**
* Grab the full contents of a file into a string object.
* NB reading a full file into memory is a poor choice
* if the file may be very large.
*/
void read_file_contents( const fc::path& filename, std::string& result );
} // namespace fc