Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / ACE / protocols / ace / INet / BidirStreamBuffer.h
blob424ee6aa0983b3e374380939c9628b57a3f31d11
1 /**
2 * @file BidirStreamBuffer.h
4 * @author Martin Corino <mcorino@remedy.nl>
5 */
7 #ifndef ACE_IOS_BIDIR_STREAM_BUFFER_H
8 #define ACE_IOS_BIDIR_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 <memory>
19 #include "ace/INet/StreamInterceptor.h"
20 #include <streambuf>
21 #include <iosfwd>
22 #include <ios>
24 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 namespace ACE
28 namespace IOS
30 /**
31 * @class ACE_IOS_BasicBidirStreamBuffer
33 * @brief Encapsulates bidirectional streambuffer attached
34 * to a StreamHandler implementation.
36 * Implements a C++ standard bidirectional streambuffer using
37 * a streamed connection handler as data source/destination.
38 * Used as a base for implementing C++ standard streams capable
39 * of performing C++ standard formatted input and output on
40 * any streamed connection that can be represented by a stream
41 * handler.
43 template <class ACE_CHAR_T, class STREAM_HANDLER, class TR = std::char_traits<ACE_CHAR_T> >
44 class BasicBidirStreamBuffer
45 : public std::basic_streambuf<ACE_CHAR_T, TR>
47 public:
48 // useful traits
49 typedef std::basic_streambuf<ACE_CHAR_T, TR> base_type;
50 typedef std::basic_ios<ACE_CHAR_T, TR> ios_type;
51 typedef ACE_CHAR_T char_type;
52 typedef TR char_traits;
53 typedef typename base_type::int_type int_type;
54 typedef typename base_type::pos_type pos_type;
55 typedef typename base_type::off_type off_type;
56 typedef typename ios_type::openmode openmode;
57 typedef StreamInterceptorBase<char_type, char_traits> interceptor_type;
59 /// Constructor
60 BasicBidirStreamBuffer (STREAM_HANDLER* sh, std::streamsize bufsz, openmode mode);
62 /// Destructor
63 virtual ~BasicBidirStreamBuffer ();
65 virtual int_type overflow (int_type c);
66 virtual int_type underflow ();
67 virtual int sync ();
69 const STREAM_HANDLER& stream () const;
71 void close_stream ();
73 void set_interceptor (interceptor_type& interceptor);
75 protected:
76 void set_mode (openmode mode);
78 openmode get_mode () const;
80 void reset_buffers();
82 private:
83 virtual int read_from_stream (char_type* buffer, std::streamsize length);
85 virtual int write_to_stream (const char_type* buffer, std::streamsize length);
87 int flush_buffer ();
89 std::streamsize bufsize_;
90 std::unique_ptr<char_type[]> read_buffer_;
91 std::unique_ptr<char_type[]> write_buffer_;
92 openmode mode_;
93 STREAM_HANDLER *stream_;
94 interceptor_type* interceptor_;
96 BasicBidirStreamBuffer(const BasicBidirStreamBuffer&);
97 BasicBidirStreamBuffer& operator = (const BasicBidirStreamBuffer&);
101 * @class ACE_IOS_BidirStreamBuffer
103 * @brief Encapsulates bidirectional character streambuffer attached
104 * to a StreamHandler implementation.
107 template <class STREAM_HANDLER>
108 class BidirStreamBuffer
109 : public BasicBidirStreamBuffer<char, STREAM_HANDLER>
111 public:
112 typedef BasicBidirStreamBuffer< char, STREAM_HANDLER> super;
113 typedef typename super::openmode openmode;
115 BidirStreamBuffer (STREAM_HANDLER* sh, std::streamsize bufsz, openmode mode);
116 virtual ~BidirStreamBuffer ();
118 private:
119 BidirStreamBuffer(const BidirStreamBuffer&);
120 BidirStreamBuffer& operator = (const BidirStreamBuffer&);
125 ACE_END_VERSIONED_NAMESPACE_DECL
127 #include "ace/INet/BidirStreamBuffer.cpp"
129 #include /**/ "ace/post.h"
130 #endif /* ACE_IOS_BIDIR_STREAM_BUFFER_H */