RCFProto
 All Classes Functions Typedefs
MemStream.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_MEMSTREAM_HPP
20 #define INCLUDE_RCF_MEMSTREAM_HPP
21 
22 #include <istream>
23 #include <streambuf>
24 
25 // std::size_t for vc6
26 #include <boost/cstdint.hpp>
27 
28 #include <boost/noncopyable.hpp>
29 
30 #include <RCF/Config.hpp>
31 #include <RCF/ByteBuffer.hpp>
32 
33 namespace RCF {
34 
35  // mem_istreambuf
36 
37  class MemIstreamBuf :
38  public std::streambuf,
39  boost::noncopyable
40  {
41  public:
42  MemIstreamBuf(char * buffer = NULL, std::size_t bufferLen = 0);
43  ~MemIstreamBuf();
44  void reset(char * buffer, std::size_t bufferLen);
45 
46  private:
47  std::streambuf::int_type underflow();
48 
49  pos_type seekoff(
50  off_type off,
51  std::ios_base::seekdir dir,
52  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
53 
54  char * mBuffer;
55  std::size_t mBufferLen;
56  };
57 
58  // mem_istream - a replacement for std::istrstream.
59 
60  class MemIstream :
61  public std::basic_istream<char>
62  {
63  public:
64  MemIstream(const char * buffer = NULL, std::size_t bufferLen = 0);
65  ~MemIstream();
66  void reset(const char * buffer, std::size_t bufferLen);
67 
68  private:
69 
70  MemIstreamBuf * mpBuf;
71  };
72 
73  // mem_ostreambuf
74 
75  class MemOstreamBuf :
76  public std::streambuf,
77  boost::noncopyable
78  {
79  public:
80  MemOstreamBuf();
81  ~MemOstreamBuf();
82 
83  private:
84  std::streambuf::int_type overflow(std::streambuf::int_type ch);
85 
86  pos_type seekoff(
87  off_type off,
88  std::ios_base::seekdir dir,
89  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
90 
91  friend class MemOstream;
92  ReallocBuffer mWriteBuffer;
93  };
94 
95  // mem_ostream - a replacement for std::ostrstream.
96 
97  class RCF_EXPORT MemOstream :
98  public std::basic_ostream<char>
99  {
100  public:
101  MemOstream();
102  ~MemOstream();
103 
104  char * str();
105 
106  std::size_t capacity();
107 
108  private:
109 
110  MemOstreamBuf * mpBuf;
111  };
112 
113  typedef boost::shared_ptr<MemOstream> MemOstreamPtr;
114 
115 
116 } // namespace RCF
117 
118 #endif