19 #ifndef INCLUDE_RCF_MEMSTREAM_HPP
20 #define INCLUDE_RCF_MEMSTREAM_HPP
26 #include <boost/cstdint.hpp>
28 #include <boost/noncopyable.hpp>
30 #include <RCF/Config.hpp>
31 #include <RCF/ByteBuffer.hpp>
32 #include <RCF/ReallocBuffer.hpp>
39 public std::streambuf,
43 MemIstreamBuf(
char * buffer = NULL, std::size_t bufferLen = 0);
45 void reset(
char * buffer, std::size_t bufferLen);
48 std::streambuf::int_type underflow();
52 std::ios_base::seekdir dir,
53 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
56 std::size_t mBufferLen;
61 class RCF_EXPORT MemIstream :
62 public std::basic_istream<char>
65 MemIstream(
const char * buffer = NULL, std::size_t bufferLen = 0);
67 void reset(
const char * buffer, std::size_t bufferLen);
71 MemIstreamBuf * mpBuf;
75 std::istream::pos_type getReadPos();
78 void read(
char *_Str, std::streamsize _Count);
79 std::streamsize readsome(
char *_Str, std::streamsize _Count);
80 std::streamsize gcount();
81 void putback(
char _Ch);
82 std::istream::pos_type moveReadPos(std::istream::pos_type newPos);
86 RCF_EXPORT MemIstream & operator>>(MemIstream & is, std::string & s);
87 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
char & ch);
88 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
signed char & ch);
89 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
unsigned char & ch);
90 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
bool & b);
91 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
short & b);
92 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
unsigned short & b);
93 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
int & n);
94 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
unsigned int & n);
95 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
long & n);
96 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
unsigned long & n);
97 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
float & d);
98 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
double & d);
99 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
long double & d);
102 RCF_EXPORT MemIstream & operator>>(MemIstream & is, __int64 & n);
103 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
unsigned __int64 & n);
105 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
long long & n);
106 RCF_EXPORT MemIstream & operator>>(MemIstream & is,
unsigned long long & n);
111 class MemOstreamBuf :
112 public std::streambuf,
120 std::streambuf::int_type overflow(std::streambuf::int_type ch);
124 std::ios_base::seekdir dir,
125 std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
127 friend class MemOstream;
128 ReallocBuffer mWriteBuffer;
133 class RCF_EXPORT MemOstream :
134 public std::basic_ostream<char>
141 std::size_t length();
142 std::string string();
144 std::size_t capacity();
148 rdbuf()->pubseekoff(0, std::ios::beg, std::ios::out);
154 MemOstreamBuf * mpBuf;
184 typedef boost::shared_ptr<MemOstream> MemOstreamPtr;
189 inline MemOstream & operator<<(MemOstream & os,
const T * pt)
191 static_cast<std::ostream&
>(os) << pt;
196 inline MemOstream & operator<<(MemOstream & os, const boost::shared_ptr<T> & pt)
198 static_cast<std::ostream&
>(os) << pt.get();
202 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
const std::string & s);
203 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
const char * sz);
204 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
char ch);
205 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
signed char ch);
206 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
unsigned char ch);
207 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
bool b);
208 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
short b);
209 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
unsigned short b);
210 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
int n);
211 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
unsigned int n);
212 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
long n);
213 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
unsigned long n);
214 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
float d);
215 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
double d);
216 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
long double d);
219 RCF_EXPORT MemOstream & operator<<(MemOstream & os, __int64 n);
220 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
unsigned __int64 n);
222 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
long long n);
223 RCF_EXPORT MemOstream & operator<<(MemOstream & os,
unsigned long long n);
226 typedef std::ostream& (*Pfn)(std::ostream&);
227 RCF_EXPORT MemOstream & operator<<(MemOstream & os, Pfn pfn);