BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet 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 
fc::stringstream::impl::ss
std::stringstream ss
Definition: sstream.cpp:20
fc::stringstream::peek
char peek()
Definition: sstream.cpp:79
fc::stringstream::clear
void clear()
Definition: sstream.cpp:41
fc
Definition: api.hpp:15
fc::stringstream::str
std::string str()
Definition: sstream.cpp:33
fc::stringstream::impl
Definition: sstream.cpp:8
fc::stringstream::eof
virtual bool eof() const
Definition: sstream.cpp:46
fc::stringstream::impl::impl
impl()
Definition: sstream.cpp:18
fc::stringstream::impl::impl
impl(const std::string &s)
Definition: sstream.cpp:14
fc::stringstream::~stringstream
~stringstream()
Definition: sstream.cpp:30
sstream.hpp
fc::stringstream::writesome
virtual size_t writesome(const char *buf, size_t len)
Definition: sstream.cpp:49
fc::stringstream::impl::impl
impl(std::string &s)
Definition: sstream.cpp:10
fc::stringstream::stringstream
stringstream()
Definition: sstream.cpp:29
exception.hpp
Defines exception's used by fc.
fc::stringstream::flush
virtual void flush()
Definition: sstream.cpp:77
logger.hpp
fc::stringstream::close
virtual void close()
Definition: sstream.cpp:76
FC_THROW_EXCEPTION
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Definition: exception.hpp:379
fc::stringstream::readsome
virtual size_t readsome(char *buf, size_t len)
Definition: sstream.cpp:62
fwd_impl.hpp