#ifndef ACE_IOS_STRING_IOSTREAM_CPP #define ACE_IOS_STRING_IOSTREAM_CPP #include "ace/INet/String_IOStream.h" #include "ace/INet/IOS_util.h" #include "ace/Truncate.h" ACE_BEGIN_VERSIONED_NAMESPACE_DECL namespace ACE { namespace IOS { template String_StreamBufferBase::String_StreamBufferBase (openmode mode) : BasicBufferedStreamBuffer (BUFFER_SIZE, mode), string_ref_ (&string_), rd_ptr_ (0) { } template String_StreamBufferBase::String_StreamBufferBase (string_type& string, openmode mode) : BasicBufferedStreamBuffer (BUFFER_SIZE, mode), string_ref_ (&string), rd_ptr_ (0) { } template String_StreamBufferBase::~String_StreamBufferBase () { } template typename String_StreamBufferBase::pos_type String_StreamBufferBase::seekoff ( off_type off, seekdir way, openmode which) { if (which != this->get_mode () || which == std::ios::out) return pos_type (-1); size_type spos = 0; if (way == std::ios::cur) spos = this->rd_ptr_; else if (way == std::ios::end) spos = this->string_ref_->length (); spos += off; if (spos < this->string_ref_->length ()) this->rd_ptr_ = spos; else this->rd_ptr_ = this->string_ref_->length (); this->setg (this->eback (), this->eback (), this->eback ()); return pos_type (this->rd_ptr_); } template typename String_StreamBufferBase::pos_type String_StreamBufferBase::seekpos ( pos_type pos, openmode which) { return this->seekoff (pos_type (pos), std::ios::beg, which); } template const typename String_StreamBufferBase::string_type& String_StreamBufferBase::str () const { const_cast*> (this)->sync (); return *this->string_ref_; } template void String_StreamBufferBase::close_string () { this->sync (); this->string_ref_ = 0; } template void String_StreamBufferBase::clear_string () { this->sync (); this->string_ref_->clear (); } template int String_StreamBufferBase::read_from_stream (char_type* buffer, std::streamsize length) { int n = 0; if (this->string_ref_) { if ((this->rd_ptr_ + length) > this->string_ref_->length ()) { length = this->string_ref_->length () - this->rd_ptr_; } ACE_OS::memmove (buffer, &(*this->string_ref_)[this->rd_ptr_], length * sizeof (char_type)); this->rd_ptr_ += length; n = ACE_Utils::truncate_cast (length); } return n; } template int String_StreamBufferBase::write_to_stream (const char_type* buffer, std::streamsize length) { int n = 0; if (this->string_ref_) { this->string_ref_->append (buffer, length); n = ACE_Utils::truncate_cast (length); } return n; } template String_IOSBase::String_IOSBase (openmode mode) : streambuf_ (mode) { ace_ios_init (&this->streambuf_); } template String_IOSBase::String_IOSBase (string_type& string, openmode mode) : streambuf_ (string, mode) { ace_ios_init (&this->streambuf_); } template String_IOSBase::~String_IOSBase () { this->close (); } template typename String_IOSBase::buffer_type* String_IOSBase::rdbuf () { return &this->streambuf_; } template void String_IOSBase::close () { this->streambuf_.close_string (); } template const typename String_IOSBase::buffer_type& String_IOSBase::stream () const { return this->streambuf_; } template String_OStreamBase::String_OStreamBase() : String_IOSBase (std::ios::out), std::basic_ostream (String_IOSBase::rdbuf ()) { } template String_OStreamBase::String_OStreamBase(string_type& string) : String_IOSBase (string, std::ios::out), std::basic_ostream (String_IOSBase::rdbuf ()) { } template String_OStreamBase::~String_OStreamBase() { } template const typename String_OStreamBase::string_type& String_OStreamBase::str () const { return this->stream ().str (); } template void String_OStreamBase::clear () { return this->rdbuf ()->clear_string (); } template String_IStreamBase::String_IStreamBase() : String_IOSBase (std::ios::in), std::basic_istream (String_IOSBase::rdbuf ()) { } template String_IStreamBase::String_IStreamBase(const string_type& string) : String_IOSBase (const_cast (string), std::ios::in), std::basic_istream (String_IOSBase::rdbuf ()) { } template String_IStreamBase::~String_IStreamBase() { } template String_IStreamBase& String_IStreamBase::rewind () { this->rdbuf ()->pubseekpos (0, std::ios::in); this->clear (); return *this; } } } ACE_END_VERSIONED_NAMESPACE_DECL #endif /* ACE_IOS_STRING_IOSTREAM_CPP */