00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00036 #ifndef OW_STRINGSTREAM_HPP_INCLUDE_GUARD_
00037 #define OW_STRINGSTREAM_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_StringBuffer.hpp"
00040 #include "OW_BaseStreamBuffer.hpp"
00041 #if defined(OW_HAVE_OSTREAM) && defined(OW_HAVE_ISTREAM)
00042 #include <istream>
00043 #include <ostream>
00044 #else
00045 #include <iostream>
00046 #endif
00047 #ifdef OW_HAVE_STREAMBUF
00048 #include <streambuf>
00049 #else
00050 #include <streambuf.h>
00051 #endif
00052 
00053 namespace OW_NAMESPACE
00054 {
00055 
00057 class IStringStreamBuf : public std::streambuf
00058 {
00059 public:
00060    IStringStreamBuf(const String& s)
00061       : std::streambuf()
00062       , m_buf(s)
00063    {
00064       setg(const_cast<char*>(reinterpret_cast<const char*>(m_buf.c_str())),
00065          const_cast<char*>(reinterpret_cast<const char*>(m_buf.c_str())),
00066          const_cast<char*>(reinterpret_cast<const char*>(m_buf.c_str()+m_buf.length())));
00067    }
00068 protected:
00069    int underflow()
00070    {
00071       return (gptr() < egptr()) ? static_cast<unsigned char>(*gptr()) : EOF;  
00072    }
00073 private:
00074    String m_buf;
00075 };
00077 class IStringStreamBase
00078 {
00079 public:
00080    IStringStreamBase(const String& s) : m_buf(s) {}
00081    mutable IStringStreamBuf m_buf;
00082 };
00083 
00085 class IStringStream : private IStringStreamBase, public std::istream
00086 {
00087 public:
00088    IStringStream(const String& s);
00089    ~IStringStream();
00090    void reset();
00091 private:
00092    
00093    IStringStream(const IStringStream&);
00094    IStringStream& operator=(const IStringStream&);
00095 };
00096 
00098 class OW_COMMON_API OStringStreamBuf : public BaseStreamBuffer
00099 {
00100 public:
00101    OStringStreamBuf(size_t size);
00102    virtual ~OStringStreamBuf();
00103    String toString() const;
00104    
00105    String releaseString();
00106    size_t length() const;
00107    const char* c_str() const;
00108    void reset();
00109 protected:
00110    virtual int buffer_to_device(const char *c, int n);
00111 private:
00112    StringBuffer m_buf;
00113    friend class OStringStream;
00114 };
00116 class OW_COMMON_API OStringStreamBase
00117 {
00118 public:
00119    OStringStreamBase(size_t sz);
00120    mutable OStringStreamBuf m_buf;
00121 };
00123 class OW_COMMON_API OStringStream : private OStringStreamBase, public std::ostream
00124 {
00125 public:
00126    OStringStream(size_t size = 256);
00127    ~OStringStream();
00128    OStringStream(const OStringStream&);
00129    OStringStream& operator=(const OStringStream&);  
00130    String toString() const;
00131    
00132    String releaseString();
00133    size_t length() const;
00134    const char* c_str() const;
00135    void reset();
00136 };
00137 
00138 } 
00139 
00140 #endif