OW_StringStream.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #include "OW_config.h"
00037 #include "OW_StringStream.hpp"
00038 
00039 namespace OW_NAMESPACE
00040 {
00041 
00043 OStringStreamBuf::OStringStreamBuf(size_t size)
00044    : BaseStreamBuffer(size, "out"), m_buf(size)
00045 {
00046 }
00048 OStringStreamBuf::~OStringStreamBuf()
00049 {
00050 }
00052 String OStringStreamBuf::toString() const
00053 {
00054    return m_buf.toString();
00055 }
00057 String OStringStreamBuf::releaseString()
00058 {
00059    return m_buf.releaseString();
00060 }
00062 size_t OStringStreamBuf::length() const
00063 {
00064    return m_buf.length();
00065 }
00067 const char* OStringStreamBuf::c_str() const
00068 {
00069    return m_buf.c_str();
00070 }
00072 void OStringStreamBuf::reset()
00073 {
00074    m_buf.reset();
00075 }
00077 int OStringStreamBuf::buffer_to_device(const char *c, int n)
00078 {
00079    m_buf.append(c, n);
00080    return 0;
00081 }
00083 OStringStreamBase::OStringStreamBase(size_t sz)
00084    : m_buf(sz)
00085 {
00086 }
00088 OStringStream::OStringStream(size_t size)
00089    : OStringStreamBase(size)
00090    , std::basic_ostream<char, std::char_traits<char> >(&m_buf)
00091 {
00092 }
00094 OStringStream::~OStringStream()
00095 {
00096 }
00098 OStringStream::OStringStream(const OStringStream& ostr)
00099 #if !defined(__GNUC__) || __GNUC__ > 2
00100    : std::basic_ios<char>()
00101 #else
00102    : std::ios() // gcc 2.95.x broken library.
00103 #endif
00104    , OStringStreamBase(ostr.length())
00105    , std::basic_ostream<char, std::char_traits<char> >(&m_buf)
00106 {
00107    *this << ostr.toString();
00108 }
00110 OStringStream& OStringStream::operator=(const OStringStream& ostr)
00111 {
00112    if ( &ostr != this )
00113    {
00114       this->reset();
00115       *this << ostr.toString();
00116    }
00117    return *this;
00118 }
00119 
00120 
00122 String OStringStream::toString() const
00123 {
00124    m_buf.sync();
00125    return m_buf.toString();
00126 }
00128 String OStringStream::releaseString()
00129 {
00130    m_buf.sync();
00131    return m_buf.releaseString();
00132 }
00134 size_t OStringStream::length() const
00135 {
00136    m_buf.sync();
00137    return m_buf.length();
00138 }
00140 const char* OStringStream::c_str() const
00141 {
00142    m_buf.sync();
00143    return m_buf.c_str();
00144 }
00146 void OStringStream::reset()
00147 {
00148    m_buf.reset();
00149 }
00150 
00151 } // end namespace OW_NAMESPACE
00152 

Generated on Thu Feb 9 08:48:16 2006 for openwbem by  doxygen 1.4.6