1 // $Id: IOStream_T.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #ifndef ACE_IOSTREAM_T_CPP
4 #define ACE_IOSTREAM_T_CPP
6 #include "ace/IOStream_T.h"
7 #include "ace/OS_Memory.h"
9 #if !defined (ACE_LACKS_PRAGMA_ONCE)
11 #endif /* ACE_LACKS_PRAGMA_ONCE */
13 #if !defined (ACE_LACKS_ACE_IOSTREAM)
15 #if !defined (__ACE_INLINE__)
16 #include "ace/IOStream_T.inl"
17 #endif /* !__ACE_INLINE__ */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 // We will be given a STREAM by the iostream object which creates us.
22 // See the ACE_IOStream template for how that works. Like other
23 // streambuf objects, we can be input-only, output-only or both.
25 template <class STREAM
>
26 ACE_Streambuf_T
<STREAM
>::ACE_Streambuf_T (STREAM
*peer
,
29 : ACE_Streambuf (streambuf_size
, io_mode
),
32 // A streambuf allows for unbuffered IO where every character is
33 // read as requested and written as provided. To me, this seems
34 // terribly inefficient for socket-type operations, so I've disabled
35 // it. All of the work would be done by the underflow/overflow
36 // functions anyway and I haven't implemented anything there to
37 // support unbuffered IO.
39 #if !defined (ACE_LACKS_UNBUFFERED_STREAMBUF)
41 #endif /* ! ACE_LACKS_UNBUFFERED_STREAMBUF */
43 // Linebuffered is similar to unbuffered. Again, I don't have any
44 // need for this and I don't see the advantage. I believe this
45 // would have to be supported by underflow/overflow to be effective.
46 #if !defined (ACE_LACKS_LINEBUFFERED_STREAMBUF)
47 this->linebuffered (0);
48 #endif /* ! ACE_LACKS_LINEBUFFERED_STREAMBUF */
51 template <class STREAM
> ssize_t
52 ACE_Streambuf_T
<STREAM
>::send (char *buf
, ssize_t len
)
54 return peer_
->send_n (buf
,len
);
57 template <class STREAM
> ssize_t
58 ACE_Streambuf_T
<STREAM
>::recv (char *buf
,
62 return this->recv (buf
, len
, 0, tv
);
65 template <class STREAM
> ssize_t
66 ACE_Streambuf_T
<STREAM
>::recv (char *buf
,
73 ssize_t rval
= peer_
->recv (buf
, len
, flags
, tv
);
79 template <class STREAM
> ssize_t
80 ACE_Streambuf_T
<STREAM
>::recv_n (char *buf
,
87 ssize_t rval
= peer_
->recv_n (buf
, len
, flags
, tv
);
93 template <class STREAM
> ACE_HANDLE
94 ACE_Streambuf_T
<STREAM
>::get_handle (void)
96 return peer_
? peer_
->get_handle () : 0;
99 // The typical constructor. This will initiailze your STREAM and then
100 // setup the iostream baseclass to use a custom streambuf based on
103 template <class STREAM
>
104 ACE_IOStream
<STREAM
>::ACE_IOStream (STREAM
&stream
,
105 u_int streambuf_size
)
110 ACE_Streambuf_T
<STREAM
> ((STREAM
*) this,
112 iostream::init (this->streambuf_
);
115 template <class STREAM
>
116 ACE_IOStream
<STREAM
>::ACE_IOStream (u_int streambuf_size
)
119 ACE_NEW (this->streambuf_
,
120 ACE_Streambuf_T
<STREAM
> ((STREAM
*) this,
122 iostream::init (this->streambuf_
);
125 // We have to get rid of the streambuf_ ourselves since we gave it to
128 template <class STREAM
>
129 ACE_IOStream
<STREAM
>::~ACE_IOStream (void)
131 delete this->streambuf_
;
134 // The only ambituity in the multiple inheritance is the close ()
137 template <class STREAM
> int
138 ACE_IOStream
<STREAM
>::close (void)
140 return STREAM::close ();
143 template <class STREAM
> ACE_IOStream
<STREAM
> &
144 ACE_IOStream
<STREAM
>::operator>> (ACE_Time_Value
*&tv
)
146 ACE_Time_Value
*old_tv
= this->streambuf_
->recv_timeout (tv
);
151 #if defined (ACE_HAS_STRING_CLASS)
153 // A simple string operator. The base iostream has 'em for char* but
154 // that isn't always the best thing for a String. If we don't provide
155 // our own here, we may not get what we want.
157 template <class STREAM
> ACE_IOStream
<STREAM
> &
158 ACE_IOStream
<STREAM
>::operator>> (ACE_IOStream_String
&v
)
166 this->get (c
) && !isspace (c
);
176 template <class STREAM
> ACE_IOStream
<STREAM
> &
177 ACE_IOStream
<STREAM
>::operator<< (ACE_IOStream_String
&v
)
181 #if defined (ACE_WIN32) && defined (_MSC_VER)
182 for (int i
= 0; i
< v
.GetLength (); ++i
)
184 for (u_int i
= 0; i
< (u_int
) v
.length (); ++i
)
185 #endif /* ACE_WIN32 && defined (_MSC_VER) */
194 // A more clever put operator for strings that knows how to deal with
195 // quoted strings containing back-quoted quotes.
197 template <class STREAM
> STREAM
&
198 operator>> (STREAM
&stream
,
199 ACE_Quoted_String
&str
)
203 if (!(stream
>> c
)) // eat space up to the first char
204 // stream.set (ios::eofbit|ios::failbit);
207 str
= ""; // Initialize the string
209 // if we don't have a quote, append until we see space
211 for (str
= c
; stream
.get (c
) && !isspace (c
); str
+= c
)
214 for (; stream
.get (c
) && c
!= '"'; str
+= c
)
225 template <class STREAM
> STREAM
&
226 operator<< (STREAM
&stream
,
227 ACE_Quoted_String
&str
)
231 for (u_int i
= 0; i
< str
.length (); ++i
)
243 ACE_END_VERSIONED_NAMESPACE_DECL
245 #endif /* ACE_HAS_STRING_CLASS */
246 #endif /* ACE_LACKS_ACE_IOSTREAM */
247 #endif /* ACE_IOSTREAM_T_CPP */