BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
sstream.cpp
Go to the documentation of this file.
1 #include <fc/io/sstream.hpp>
2 #include <fc/fwd_impl.hpp>
4 #include <fc/log/logger.hpp>
5 #include <sstream>
6 
7 namespace fc {
9  public:
10  impl( std::string&s )
11  :ss( s )
12  { ss.exceptions( std::stringstream::badbit ); }
13 
14  impl( const std::string&s )
15  :ss( s )
16  { ss.exceptions( std::stringstream::badbit ); }
17 
18  impl(){ss.exceptions( std::stringstream::badbit ); }
19 
20  std::stringstream ss;
21  };
22 
23  stringstream::stringstream( std::string& s )
24  :my(s) {
25  }
26  stringstream::stringstream( const std::string& s )
27  :my(s) {
28  }
31 
32 
33  std::string stringstream::str(){
34  return my->ss.str();//.c_str();//*reinterpret_cast<std::string*>(&st);
35  }
36 
37  void stringstream::str(const std::string& s) {
38  my->ss.str(s);
39  }
40 
42  my->ss.clear();
43  }
44 
45 
46  bool stringstream::eof()const {
47  return my->ss.eof();
48  }
49  size_t stringstream::writesome( const char* buf, size_t len ) {
50  my->ss.write(buf,len);
51  if( my->ss.eof() )
52  {
53  FC_THROW_EXCEPTION( eof_exception, "stringstream" );
54  }
55  return len;
56  }
57  size_t stringstream::writesome( const std::shared_ptr<const char>& buf, size_t len, size_t offset )
58  {
59  return writesome(buf.get() + offset, len);
60  }
61 
62  size_t stringstream::readsome( char* buf, size_t len ) {
63  size_t r = static_cast<size_t>(my->ss.readsome(buf,len));
64  if( my->ss.eof() || r == 0 )
65  {
66  FC_THROW_EXCEPTION( eof_exception, "stringstream" );
67  }
68  return r;
69  }
70  size_t stringstream::readsome( const std::shared_ptr<char>& buf, size_t len, size_t offset )
71  {
72  return readsome(buf.get() + offset, len);
73  }
74 
75 
76  void stringstream::close(){ my->ss.flush(); };
77  void stringstream::flush(){ my->ss.flush(); };
78 
80  {
81  char c = my->ss.peek();
82  if( my->ss.eof() )
83  {
84  FC_THROW_EXCEPTION( eof_exception, "stringstream" );
85  }
86  return c;
87  }
88 }
89 
90 
impl(std::string &s)
Definition: sstream.cpp:10
std::stringstream ss
Definition: sstream.cpp:20
impl(const std::string &s)
Definition: sstream.cpp:14
std::string str()
Definition: sstream.cpp:33
virtual bool eof() const
Definition: sstream.cpp:46
virtual void flush()
Definition: sstream.cpp:77
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Definition: exception.hpp:378
virtual void close()
Definition: sstream.cpp:76
Defines exception&#39;s used by fc.
virtual size_t readsome(char *buf, size_t len)
Definition: sstream.cpp:62
Definition: api.hpp:15
virtual size_t writesome(const char *buf, size_t len)
Definition: sstream.cpp:49