]>
git.saurik.com Git - wxWidgets.git/blob - src/common/sstream.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/sstream.cpp
3 // Purpose: string-based streams implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/sstream.h"
31 // ============================================================================
32 // wxStringInputStream implementation
33 // ============================================================================
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 off_t
wxStringInputStream::OnSysSeek(off_t ofs
, wxSeekMode mode
)
41 const size_t ofsMax
= m_str
.length()*sizeof(wxChar
);
46 // nothing to do, ofs already ok
58 wxFAIL_MSG( _T("invalid seek mode") );
59 return wxInvalidOffset
;
62 if ( ofs
< 0 || wx_static_cast(size_t, ofs
) >= ofsMax
)
63 return wxInvalidOffset
;
65 m_pos
= wx_static_cast(size_t, ofs
);
70 off_t
wxStringInputStream::OnSysTell() const
72 return wx_static_cast(off_t
, m_pos
);
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 size_t wxStringInputStream::OnSysRead(void *buffer
, size_t size
)
81 const size_t sizeMax
= m_str
.length()*sizeof(wxChar
) - m_pos
;
83 if ( size
>= sizeMax
)
87 m_lasterror
= wxSTREAM_EOF
;
94 memcpy(buffer
, m_str
.data() + m_pos
, size
);
100 // ============================================================================
101 // wxStringOutputStream implementation
102 // ============================================================================
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 off_t
wxStringOutputStream::OnSysTell() const
110 return wx_static_cast(off_t
, m_pos
);
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 size_t wxStringOutputStream::OnSysWrite(const void *buffer
, size_t size
)
119 // in Unicode mode we might not be able to write the last byte
120 size_t len
= size
/ sizeof(wxChar
);
122 const wxChar
*p
= wx_static_cast(const wxChar
*, buffer
);
124 m_str
->Append(wxString(p
, p
+ len
));
126 // return number of bytes actually written
127 len
*= sizeof(wxChar
);
133 #endif // wxUSE_STREAMS