BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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
fc::ifstream::open
void open(const fc::path &file, int m)
Definition: fstream.cpp:64
fc::ifstream::cur
@ cur
Definition: fstream.hpp:30
fc
Definition: api.hpp:15
fc::ifstream::~ifstream
~ifstream()
Definition: fstream.cpp:62
fc::ifstream::beg
@ beg
Definition: fstream.hpp:30
fc::ifstream::binary
@ binary
Definition: fstream.hpp:29
fc::ofstream::put
void put(char c)
Definition: fstream.cpp:45
filesystem.hpp
fc::ofstream::writesome
size_t writesome(const char *buf, size_t len)
Definition: fstream.cpp:36
fc::ofstream::open
void open(const fc::path &file, std::ios_base::openmode m=std::ios_base::out|std::ios_base::binary)
Definition: fstream.cpp:32
fc::ifstream::end
@ end
Definition: fstream.hpp:30
fc::ifstream
Definition: fstream.hpp:27
fc::istream::get
virtual char get()
Definition: iostream.cpp:267
fc::ifstream::get
void get(char &c)
Definition: fstream.hpp:42
iostream.hpp
fc::ofstream::close
void close()
Definition: fstream.cpp:48
fc::path
wraps boost::filesystem::path to provide platform independent path manipulation.
Definition: filesystem.hpp:28
fc::ifstream::mode
mode
Definition: fstream.hpp:29
fc::ifstream::read
ifstream & read(char *buf, size_t len)
Definition: fstream.cpp:87
fc::ifstream::ifstream
ifstream()
Definition: fstream.cpp:55
fc::ostream
Definition: iostream.hpp:41
fc::ifstream::in
@ in
Definition: fstream.hpp:29
fc::istream
Definition: iostream.hpp:11
fc::ofstream
Definition: fstream.hpp:9
fc::ifstream::eof
bool eof() const
Definition: fstream.cpp:105
fc::read_file_contents
void read_file_contents(const fc::path &filename, std::string &result)
Definition: fstream.cpp:107
fc::ifstream::readsome
size_t readsome(char *buf, size_t len)
Definition: fstream.cpp:69
fc::ifstream::close
void close()
Definition: fstream.cpp:103
fc::ofstream::flush
void flush()
Definition: fstream.cpp:51
fc::ifstream::seekg
ifstream & seekg(size_t p, seekdir d=beg)
Definition: fstream.cpp:95
fc::ofstream::impl
Definition: fstream.cpp:16
fc::ofstream::~ofstream
~ofstream()
Definition: fstream.cpp:30
fc::ifstream::seekdir
seekdir
Definition: fstream.hpp:30
fc::ofstream::ofstream
ofstream()
Definition: fstream.cpp:25