summaryrefslogtreecommitdiff
path: root/ACE/protocols/ace/INet/BufferedStreamBuffer.h
blob: 56bae21bb221e68735dce27b2414c5397862eaaa (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
/**
 * @file BufferedStreamBuffer.h
 *
 * @author Martin Corino <mcorino@remedy.nl>
 */

#ifndef ACE_IOS_BUFFERED_STREAM_BUFFER_H
#define ACE_IOS_BUFFERED_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_BasicBufferedStreamBuffer
        *
        * @brief Encapsulates unidirectional streambuffer attached
        * to an input OR output stream.
        *
        * Implements a base class for a C++ standard unidirectional
        * streambuffer using any data source/destination that can be
        * driven by overloading the <write_to_stream> or <read_from_stream>
        * methods.
        */
        template <class ACE_CHAR_T, class TR = std::char_traits<ACE_CHAR_T> >
        class BasicBufferedStreamBuffer
          : public std::basic_streambuf<ACE_CHAR_T, TR>
          {
            public:
              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::seekdir seekdir;
              typedef typename ios_type::openmode openmode;
              typedef StreamInterceptorBase<char_type, char_traits> interceptor_type;

              BasicBufferedStreamBuffer (std::streamsize bufsz,
                                         typename std::basic_ios<ACE_CHAR_T, TR>::openmode mode);

              virtual ~BasicBufferedStreamBuffer ();

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

              void set_interceptor (interceptor_type& interceptor);

            protected:
              void set_mode (typename std::basic_ios<ACE_CHAR_T, TR>::openmode mode);

              typename std::basic_ios<ACE_CHAR_T, TR>::openmode get_mode () const;

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

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

              void reset_buffers ();

            private:
              int flush_buffer ();

              std::streamsize bufsize_;
              ACE_Auto_Array_Ptr<char_type> buffer_;
              typename std::basic_ios<ACE_CHAR_T, TR>::openmode mode_;
              interceptor_type* interceptor_;

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

        /// char specialization
        typedef BasicBufferedStreamBuffer<char, std::char_traits<char> > BufferedStreamBuffer;
      }
  }

ACE_END_VERSIONED_NAMESPACE_DECL

#include "ace/INet/BufferedStreamBuffer.cpp"

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