BitShares-Core  6.1.0
BitShares blockchain implementation and command-line interface software
fstream.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <fc/filesystem.hpp>
3 #include <fc/io/iostream.hpp>
4 #include <fstream>
5 #include <memory>
6 
7 namespace fc {
8  class path;
9  class ofstream : virtual public ostream {
10  public:
11  ofstream();
12  ofstream( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
13  ~ofstream();
14 
15  void open( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
16  size_t writesome( const char* buf, size_t len );
17  size_t writesome(const std::shared_ptr<const char>& buffer, size_t len, size_t offset);
18  void put( char c );
19  void close();
20  void flush();
21 
22  private:
23  class impl;
24  std::shared_ptr<impl> my;
25  };
26 
27  class ifstream : virtual public istream {
28  public:
29  enum mode { in, binary };
30  enum seekdir { beg, cur, end };
31 
32  ifstream();
33  ifstream( const fc::path& file, int m = binary);
34  ~ifstream();
35 
36  void open( const fc::path& file, int m );
37  size_t readsome( char* buf, size_t len );
38  size_t readsome(const std::shared_ptr<char>& buffer, size_t max, size_t offset);
39  ifstream& read( char* buf, size_t len );
40  ifstream& seekg( size_t p, seekdir d = beg );
41  using istream::get;
42  void get( char& c ) { read( &c, 1 ); }
43  void close();
44  bool eof()const;
45  private:
46  class impl;
47  std::shared_ptr<impl> my;
48  };
49 
55  void read_file_contents( const fc::path& filename, std::string& result );
56 
57 } // namespace fc
size_t writesome(const char *buf, size_t len)
Definition: fstream.cpp:36
void flush()
Definition: fstream.cpp:51
size_t read(AsyncReadStream &s, const MutableBufferSequence &buf)
wraps boost::asio::async_read
Definition: asio.hpp:103
void read_file_contents(const fc::path &filename, std::string &result)
Definition: fstream.cpp:107
virtual char get()
Definition: iostream.cpp:267
void open(const fc::path &file, std::ios_base::openmode m=std::ios_base::out|std::ios_base::binary)
Definition: fstream.cpp:32
Definition: api.hpp:15
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
void put(char c)
Definition: fstream.cpp:45
void close()
Definition: fstream.cpp:48