1 #ifndef ACE_IOS_STRING_IOSTREAM_CPP
2 #define ACE_IOS_STRING_IOSTREAM_CPP
4 #include "ace/INet/String_IOStream.h"
5 #include "ace/INet/IOS_util.h"
6 #include "ace/Truncate.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 template <class ACE_CHAR_T
, class TR
>
15 String_StreamBufferBase
<ACE_CHAR_T
, TR
>::String_StreamBufferBase (openmode mode
)
16 : BasicBufferedStreamBuffer
<ACE_CHAR_T
, TR
> (BUFFER_SIZE
, mode
),
17 string_ref_ (&string_
),
22 template <class ACE_CHAR_T
, class TR
>
23 String_StreamBufferBase
<ACE_CHAR_T
, TR
>::String_StreamBufferBase (string_type
& string
, openmode mode
)
24 : BasicBufferedStreamBuffer
<ACE_CHAR_T
, TR
> (BUFFER_SIZE
, mode
),
25 string_ref_ (&string
),
30 template <class ACE_CHAR_T
, class TR
>
31 String_StreamBufferBase
<ACE_CHAR_T
, TR
>::~String_StreamBufferBase ()
35 template <class ACE_CHAR_T
, class TR
>
36 typename String_StreamBufferBase
<ACE_CHAR_T
, TR
>::pos_type
37 String_StreamBufferBase
<ACE_CHAR_T
, TR
>::seekoff (
42 if (which
!= this->get_mode () || which
== std::ios::out
)
46 if (way
== std::ios::cur
)
48 else if (way
== std::ios::end
)
49 spos
= this->string_ref_
->length ();
51 if (spos
< this->string_ref_
->length ())
54 this->rd_ptr_
= this->string_ref_
->length ();
56 this->setg (this->eback (), this->eback (), this->eback ());
57 return pos_type (this->rd_ptr_
);
60 template <class ACE_CHAR_T
, class TR
>
61 typename String_StreamBufferBase
<ACE_CHAR_T
, TR
>::pos_type
62 String_StreamBufferBase
<ACE_CHAR_T
, TR
>::seekpos (
66 return this->seekoff (pos_type (pos
), std::ios::beg
, which
);
69 template <class ACE_CHAR_T
, class TR
>
70 const typename String_StreamBufferBase
<ACE_CHAR_T
, TR
>::string_type
&
71 String_StreamBufferBase
<ACE_CHAR_T
, TR
>::str () const
73 const_cast<String_StreamBufferBase
<ACE_CHAR_T
, TR
>*> (this)->sync ();
74 return *this->string_ref_
;
77 template <class ACE_CHAR_T
, class TR
>
78 void String_StreamBufferBase
<ACE_CHAR_T
, TR
>::close_string ()
81 this->string_ref_
= 0;
84 template <class ACE_CHAR_T
, class TR
>
85 void String_StreamBufferBase
<ACE_CHAR_T
, TR
>::clear_string ()
88 this->string_ref_
->clear ();
91 template <class ACE_CHAR_T
, class TR
>
92 int String_StreamBufferBase
<ACE_CHAR_T
, TR
>::read_from_stream (char_type
* buffer
, std::streamsize length
)
95 if (this->string_ref_
)
97 if ((this->rd_ptr_
+ length
) > this->string_ref_
->length ())
99 length
= this->string_ref_
->length () - this->rd_ptr_
;
101 ACE_OS::memmove (buffer
, &(*this->string_ref_
)[this->rd_ptr_
], length
* sizeof (char_type
));
102 this->rd_ptr_
+= length
;
103 n
= ACE_Utils::truncate_cast
<int> (length
);
108 template <class ACE_CHAR_T
, class TR
>
109 int String_StreamBufferBase
<ACE_CHAR_T
, TR
>::write_to_stream (const char_type
* buffer
, std::streamsize length
)
112 if (this->string_ref_
)
114 this->string_ref_
->append (buffer
, length
);
115 n
= ACE_Utils::truncate_cast
<int> (length
);
120 template <class ACE_CHAR_T
, class TR
>
121 String_IOSBase
<ACE_CHAR_T
, TR
>::String_IOSBase (openmode mode
)
124 ace_ios_init (&this->streambuf_
);
127 template <class ACE_CHAR_T
, class TR
>
128 String_IOSBase
<ACE_CHAR_T
, TR
>::String_IOSBase (string_type
& string
, openmode mode
)
129 : streambuf_ (string
, mode
)
131 ace_ios_init (&this->streambuf_
);
134 template <class ACE_CHAR_T
, class TR
>
135 String_IOSBase
<ACE_CHAR_T
, TR
>::~String_IOSBase ()
140 template <class ACE_CHAR_T
, class TR
>
141 typename String_IOSBase
<ACE_CHAR_T
, TR
>::buffer_type
*
142 String_IOSBase
<ACE_CHAR_T
, TR
>::rdbuf ()
144 return &this->streambuf_
;
147 template <class ACE_CHAR_T
, class TR
>
148 void String_IOSBase
<ACE_CHAR_T
, TR
>::close ()
150 this->streambuf_
.close_string ();
153 template <class ACE_CHAR_T
, class TR
>
154 const typename String_IOSBase
<ACE_CHAR_T
, TR
>::buffer_type
&
155 String_IOSBase
<ACE_CHAR_T
, TR
>::stream () const
157 return this->streambuf_
;
160 template <class ACE_CHAR_T
, class TR
>
161 String_OStreamBase
<ACE_CHAR_T
, TR
>::String_OStreamBase()
162 : String_IOSBase
<ACE_CHAR_T
, TR
> (std::ios::out
),
163 std::basic_ostream
<ACE_CHAR_T
, TR
> (String_IOSBase
<ACE_CHAR_T
, TR
>::rdbuf ())
167 template <class ACE_CHAR_T
, class TR
>
168 String_OStreamBase
<ACE_CHAR_T
, TR
>::String_OStreamBase(string_type
& string
)
169 : String_IOSBase
<ACE_CHAR_T
, TR
> (string
, std::ios::out
),
170 std::basic_ostream
<ACE_CHAR_T
, TR
> (String_IOSBase
<ACE_CHAR_T
, TR
>::rdbuf ())
174 template <class ACE_CHAR_T
, class TR
>
175 String_OStreamBase
<ACE_CHAR_T
, TR
>::~String_OStreamBase()
179 template <class ACE_CHAR_T
, class TR
>
180 const typename String_OStreamBase
<ACE_CHAR_T
, TR
>::string_type
&
181 String_OStreamBase
<ACE_CHAR_T
, TR
>::str () const
183 return this->stream ().str ();
186 template <class ACE_CHAR_T
, class TR
>
187 void String_OStreamBase
<ACE_CHAR_T
, TR
>::clear ()
189 return this->rdbuf ()->clear_string ();
192 template <class ACE_CHAR_T
, class TR
>
193 String_IStreamBase
<ACE_CHAR_T
, TR
>::String_IStreamBase()
194 : String_IOSBase
<ACE_CHAR_T
, TR
> (std::ios::in
),
195 std::basic_istream
<ACE_CHAR_T
, TR
> (String_IOSBase
<ACE_CHAR_T
, TR
>::rdbuf ())
199 template <class ACE_CHAR_T
, class TR
>
200 String_IStreamBase
<ACE_CHAR_T
, TR
>::String_IStreamBase(const string_type
& string
)
201 : String_IOSBase
<ACE_CHAR_T
, TR
> (const_cast<string_type
&> (string
),
203 std::basic_istream
<ACE_CHAR_T
, TR
> (String_IOSBase
<ACE_CHAR_T
, TR
>::rdbuf ())
207 template <class ACE_CHAR_T
, class TR
>
208 String_IStreamBase
<ACE_CHAR_T
, TR
>::~String_IStreamBase()
212 template <class ACE_CHAR_T
, class TR
>
213 String_IStreamBase
<ACE_CHAR_T
, TR
>&
214 String_IStreamBase
<ACE_CHAR_T
, TR
>::rewind ()
216 this->rdbuf ()->pubseekpos (0, std::ios::in
);
223 ACE_END_VERSIONED_NAMESPACE_DECL
225 #endif /* ACE_IOS_STRING_IOSTREAM_CPP */