]>
git.saurik.com Git - wxWidgets.git/blob - src/common/sstream.cpp
7ceedb65b59db5aecc3e37edb92698e7069deac5
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
)
44 // nothing to do, ofs already ok
48 ofs
+= m_str
.length()*sizeof(wxChar
);
56 wxFAIL_MSG( _T("invalid seek mode") );
57 return wxInvalidOffset
;
60 m_pos
= wx_static_cast(size_t, ofs
);
65 off_t
wxStringInputStream::OnSysTell() const
67 return wx_static_cast(off_t
, m_pos
);
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 size_t wxStringInputStream::OnSysRead(void *buffer
, size_t size
)
76 const size_t sizeMax
= m_str
.length()*sizeof(wxChar
) - m_pos
;
78 if ( size
>= sizeMax
)
82 m_lasterror
= wxSTREAM_EOF
;
89 memcpy(buffer
, m_str
.data() + m_pos
, size
);
95 // ============================================================================
96 // wxStringOutputStream implementation
97 // ============================================================================
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 size_t wxStringOutputStream::OnSysWrite(const void *buffer
, size_t size
)
105 // in Unicode mode we might not be able to write the last byte
106 size_t len
= size
/ sizeof(wxChar
);
108 const wxChar
*p
= wx_static_cast(const wxChar
*, buffer
);
110 m_str
->Append(wxString(p
, p
+ len
+ 1));
112 // return number of bytes actually written
113 return len
*sizeof(wxChar
);
116 #endif // wxUSE_STREAMS