summaryrefslogtreecommitdiff
path: root/ACE/protocols/ace/INet/BidirStreamBuffer.h
blob: 1b5f0e4a76bf2febf1c2bfe95657d4055d4ca493 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
 * @file BidirStreamBuffer.h
 *
 * @author Martin Corino <mcorino@remedy.nl>
 */

#ifndef ACE_IOS_BIDIR_STREAM_BUFFER_H
#define ACE_IOS_BIDIR_STREAM_BUFFER_H

#include /**/ "ace/pre.h"

#include /**/ "ace/config-all.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Auto_Ptr.h"
#include "ace/INet/StreamInterceptor.h"
#include <streambuf>
#include <iosfwd>
#include <ios>

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

namespace ACE
  {
    namespace IOS
      {
        /**
        * @class ACE_IOS_BasicBidirStreamBuffer
        *
        * @brief Encapsulates bidirectional streambuffer attached
        * to a StreamHandler implementation.
        *
        * Implements a C++ standard bidirectional streambuffer using
        * a streamed connection handler as data source/destination.
        * Used as a base for implementing C++ standard streams capable
        * of performing C++ standard formatted input and output on
        * any streamed connection that can be represented by a stream
        * handler.
        */
        template <class ACE_CHAR_T, class STREAM_HANDLER, class TR = std::char_traits<ACE_CHAR_T> >
        class BasicBidirStreamBuffer
          : public std::basic_streambuf<ACE_CHAR_T, TR>
          {
            public:
              // useful traits
              typedef std::basic_streambuf<ACE_CHAR_T, TR> base_type;
              typedef std::basic_ios<ACE_CHAR_T, TR> ios_type;
              typedef ACE_CHAR_T char_type;
              typedef TR char_traits;
              typedef typename base_type::int_type int_type;
              typedef typename base_type::pos_type pos_type;
              typedef typename base_type::off_type off_type;
              typedef typename ios_type::openmode openmode;
              typedef StreamInterceptorBase<char_type, char_traits> interceptor_type;

              /// Constructor
              BasicBidirStreamBuffer (STREAM_HANDLER* sh, std::streamsize bufsz, openmode mode);

              /// Destructor
              virtual ~BasicBidirStreamBuffer ();

              virtual int_type overflow (int_type c);
              virtual int_type underflow ();
              virtual int sync ();

              const STREAM_HANDLER& stream () const;

              void close_stream ();

              void set_interceptor (interceptor_type& interceptor);

            protected:
              void set_mode (openmode mode);

              openmode get_mode () const;

              void reset_buffers();

            private:
              virtual int read_from_stream (char_type* buffer, std::streamsize length);

              virtual int write_to_stream (const char_type* buffer, std::streamsize length);

              int flush_buffer ();

              std::streamsize bufsize_;
              ACE_Auto_Array_Ptr<char_type> read_buffer_;
              ACE_Auto_Array_Ptr<char_type> write_buffer_;
              openmode        mode_;
              STREAM_HANDLER *stream_;
              interceptor_type* interceptor_;

              BasicBidirStreamBuffer(const BasicBidirStreamBuffer&);
              BasicBidirStreamBuffer& operator = (const BasicBidirStreamBuffer&);
          };

        /**
        * @class ACE_IOS_BidirStreamBuffer
        *
        * @brief Encapsulates bidirectional character streambuffer attached
        * to a StreamHandler implementation.
        *
        */
        template <class STREAM_HANDLER>
        class BidirStreamBuffer
          : public BasicBidirStreamBuffer<char, STREAM_HANDLER>
          {
            public:
              typedef BasicBidirStreamBuffer< char, STREAM_HANDLER> super;
              typedef typename super::openmode openmode;

              BidirStreamBuffer (STREAM_HANDLER* sh, std::streamsize bufsz, openmode mode);
              virtual ~BidirStreamBuffer ();

            private:
              BidirStreamBuffer(const BidirStreamBuffer&);
              BidirStreamBuffer& operator = (const BidirStreamBuffer&);
          };
      }
  }

ACE_END_VERSIONED_NAMESPACE_DECL

#include "ace/INet/BidirStreamBuffer.cpp"

#include /**/ "ace/post.h"
#endif /* ACE_IOS_BIDIR_STREAM_BUFFER_H */