1 #ifndef ACE_IOSTREAM_T_CPP
2 #define ACE_IOSTREAM_T_CPP
4 #include "ace/IOStream_T.h"
5 #include "ace/OS_Memory.h"
7 #if !defined (ACE_LACKS_PRAGMA_ONCE)
9 #endif /* ACE_LACKS_PRAGMA_ONCE */
11 #if !defined (ACE_LACKS_ACE_IOSTREAM)
13 #if !defined (__ACE_INLINE__)
14 #include "ace/IOStream_T.inl"
15 #endif /* !__ACE_INLINE__ */
17 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 // We will be given a STREAM by the iostream object which creates us.
20 // See the ACE_IOStream template for how that works. Like other
21 // streambuf objects, we can be input-only, output-only or both.
23 template <class STREAM
>
24 ACE_Streambuf_T
<STREAM
>::ACE_Streambuf_T (STREAM
*peer
,
27 : ACE_Streambuf (streambuf_size
, io_mode
),
30 // A streambuf allows for unbuffered IO where every character is
31 // read as requested and written as provided. To me, this seems
32 // terribly inefficient for socket-type operations, so I've disabled
33 // it. All of the work would be done by the underflow/overflow
34 // functions anyway and I haven't implemented anything there to
35 // support unbuffered IO.
37 #if !defined (ACE_LACKS_UNBUFFERED_STREAMBUF)
39 #endif /* ! ACE_LACKS_UNBUFFERED_STREAMBUF */
41 // Linebuffered is similar to unbuffered. Again, I don't have any
42 // need for this and I don't see the advantage. I believe this
43 // would have to be supported by underflow/overflow to be effective.
44 #if !defined (ACE_LACKS_LINEBUFFERED_STREAMBUF)
45 this->linebuffered (0);
46 #endif /* ! ACE_LACKS_LINEBUFFERED_STREAMBUF */
49 template <class STREAM
> ssize_t
50 ACE_Streambuf_T
<STREAM
>::send (char *buf
, ssize_t len
)
52 return peer_
->send_n (buf
,len
);
55 template <class STREAM
> ssize_t
56 ACE_Streambuf_T
<STREAM
>::recv (char *buf
,
60 return this->recv (buf
, len
, 0, tv
);
63 template <class STREAM
> ssize_t
64 ACE_Streambuf_T
<STREAM
>::recv (char *buf
,
71 ssize_t rval
= peer_
->recv (buf
, len
, flags
, tv
);
77 template <class STREAM
> ssize_t
78 ACE_Streambuf_T
<STREAM
>::recv_n (char *buf
,
85 ssize_t rval
= peer_
->recv_n (buf
, len
, flags
, tv
);
91 template <class STREAM
> ACE_HANDLE
92 ACE_Streambuf_T
<STREAM
>::get_handle (void)
94 return peer_
? peer_
->get_handle () : 0;
97 // The typical constructor. This will initiailze your STREAM and then
98 // setup the iostream baseclass to use a custom streambuf based on
101 template <class STREAM
>
102 ACE_IOStream
<STREAM
>::ACE_IOStream (STREAM
&stream
,
103 u_int streambuf_size
)
108 ACE_Streambuf_T
<STREAM
> ((STREAM
*) this,
110 iostream::init (this->streambuf_
);
113 template <class STREAM
>
114 ACE_IOStream
<STREAM
>::ACE_IOStream (u_int streambuf_size
)
117 ACE_NEW (this->streambuf_
,
118 ACE_Streambuf_T
<STREAM
> ((STREAM
*) this,
120 iostream::init (this->streambuf_
);
123 // We have to get rid of the streambuf_ ourselves since we gave it to
126 template <class STREAM
>
127 ACE_IOStream
<STREAM
>::~ACE_IOStream (void)
129 delete this->streambuf_
;
132 // The only ambituity in the multiple inheritance is the close ()
135 template <class STREAM
> int
136 ACE_IOStream
<STREAM
>::close (void)
138 return STREAM::close ();
141 template <class STREAM
> ACE_IOStream
<STREAM
> &
142 ACE_IOStream
<STREAM
>::operator>> (ACE_Time_Value
*&tv
)
144 ACE_Time_Value
*old_tv
= this->streambuf_
->recv_timeout (tv
);
149 #if defined (ACE_HAS_STRING_CLASS)
151 // A simple string operator. The base iostream has 'em for char* but
152 // that isn't always the best thing for a String. If we don't provide
153 // our own here, we may not get what we want.
155 template <class STREAM
> ACE_IOStream
<STREAM
> &
156 ACE_IOStream
<STREAM
>::operator>> (ACE_IOStream_String
&v
)
164 this->get (c
) && !isspace (c
);
174 template <class STREAM
> ACE_IOStream
<STREAM
> &
175 ACE_IOStream
<STREAM
>::operator<< (ACE_IOStream_String
&v
)
179 #if defined (ACE_WIN32) && defined (_MSC_VER)
180 for (int i
= 0; i
< v
.GetLength (); ++i
)
182 for (u_int i
= 0; i
< (u_int
) v
.length (); ++i
)
183 #endif /* ACE_WIN32 && defined (_MSC_VER) */
192 // A more clever put operator for strings that knows how to deal with
193 // quoted strings containing back-quoted quotes.
195 template <class STREAM
> STREAM
&
196 operator>> (STREAM
&stream
,
197 ACE_Quoted_String
&str
)
201 if (!(stream
>> c
)) // eat space up to the first char
202 // stream.set (ios::eofbit|ios::failbit);
205 str
= ""; // Initialize the string
207 // if we don't have a quote, append until we see space
209 for (str
= c
; stream
.get (c
) && !isspace (c
); str
+= c
)
212 for (; stream
.get (c
) && c
!= '"'; str
+= c
)
223 template <class STREAM
> STREAM
&
224 operator<< (STREAM
&stream
,
225 ACE_Quoted_String
&str
)
229 for (u_int i
= 0; i
< str
.length (); ++i
)
241 ACE_END_VERSIONED_NAMESPACE_DECL
243 #endif /* ACE_HAS_STRING_CLASS */
244 #endif /* ACE_LACKS_ACE_IOSTREAM */
245 #endif /* ACE_IOSTREAM_T_CPP */