Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / BufferedStreamBuffer.h
blob4c0bc48429b86a1814e2eec6a6326c5bb5aebf23
1 /**
2 * @file BufferedStreamBuffer.h
4 * @author Martin Corino <mcorino@remedy.nl>
5 */
7 #ifndef ACE_IOS_BUFFERED_STREAM_BUFFER_H
8 #define ACE_IOS_BUFFERED_STREAM_BUFFER_H
10 #include /**/ "ace/pre.h"
12 #include /**/ "ace/config-all.h"
14 #if !defined (ACE_LACKS_PRAGMA_ONCE)
15 # pragma once
16 #endif /* ACE_LACKS_PRAGMA_ONCE */
18 #include "ace/INet/StreamInterceptor.h"
19 #include <streambuf>
20 #include <iosfwd>
21 #include <ios>
22 #include <memory>
24 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 namespace ACE
28 namespace IOS
30 /**
31 * @class ACE_IOS_BasicBufferedStreamBuffer
33 * @brief Encapsulates unidirectional streambuffer attached
34 * to an input OR output stream.
36 * Implements a base class for a C++ standard unidirectional
37 * streambuffer using any data source/destination that can be
38 * driven by overloading the <write_to_stream> or <read_from_stream>
39 * methods.
41 template <class ACE_CHAR_T, class TR = std::char_traits<ACE_CHAR_T> >
42 class BasicBufferedStreamBuffer
43 : public std::basic_streambuf<ACE_CHAR_T, TR>
45 public:
46 typedef std::basic_streambuf<ACE_CHAR_T, TR> base_type;
47 typedef std::basic_ios<ACE_CHAR_T, TR> ios_type;
48 typedef ACE_CHAR_T char_type;
49 typedef TR char_traits;
50 typedef typename base_type::int_type int_type;
51 typedef typename base_type::pos_type pos_type;
52 typedef typename base_type::off_type off_type;
53 typedef typename ios_type::seekdir seekdir;
54 typedef typename ios_type::openmode openmode;
55 typedef StreamInterceptorBase<char_type, char_traits> interceptor_type;
57 BasicBufferedStreamBuffer (std::streamsize bufsz,
58 typename std::basic_ios<ACE_CHAR_T, TR>::openmode mode);
60 virtual ~BasicBufferedStreamBuffer ();
62 virtual int_type overflow (int_type c);
63 virtual int_type underflow ();
64 virtual int sync ();
66 void set_interceptor (interceptor_type& interceptor);
68 protected:
69 void set_mode (typename std::basic_ios<ACE_CHAR_T, TR>::openmode mode);
71 typename std::basic_ios<ACE_CHAR_T, TR>::openmode get_mode () const;
73 virtual int read_from_stream (char_type* buffer, std::streamsize length);
75 virtual int write_to_stream (const char_type* buffer, std::streamsize length);
77 void reset_buffers ();
79 private:
80 int flush_buffer ();
82 std::streamsize bufsize_;
83 std::unique_ptr<char_type[]> buffer_;
84 typename std::basic_ios<ACE_CHAR_T, TR>::openmode mode_;
85 interceptor_type* interceptor_;
87 BasicBufferedStreamBuffer(const BasicBufferedStreamBuffer&);
88 BasicBufferedStreamBuffer& operator = (const BasicBufferedStreamBuffer&);
91 /// char specialization
92 typedef BasicBufferedStreamBuffer<char, std::char_traits<char> > BufferedStreamBuffer;
96 ACE_END_VERSIONED_NAMESPACE_DECL
98 #include "ace/INet/BufferedStreamBuffer.cpp"
100 #include /**/ "ace/post.h"
101 #endif /* ACE_IOS_BUFFERED_STREAM_BUFFER_H */