+template <class T>
+static void DoWriteLL(const T *buffer, size_t size, wxOutputStream *output, bool be_order)
+{
+ typedef T DataType;
+ unsigned char *pchBuffer = new unsigned char[size * 8];
+ size_t idx_base = 0;
+ if ( be_order )
+ {
+ for ( size_t uiIndex = 0; uiIndex != size; ++uiIndex )
+ {
+ DataType i64 = buffer[uiIndex];
+ for ( unsigned ui = 0; ui != 8; ++ui )
+ {
+ pchBuffer[idx_base + 7 - ui] =
+ (unsigned char) (i64.GetLo() & 255l);
+ i64 >>= 8l;
+ }
+
+ idx_base += 8;
+ }
+ }
+ else // little endian
+ {
+ for ( size_t uiIndex=0; uiIndex != size; ++uiIndex )
+ {
+ DataType i64 = buffer[uiIndex];
+ for (unsigned ui=0; ui!=8; ++ui)
+ {
+ pchBuffer[idx_base + ui] =
+ (unsigned char) (i64.GetLo() & 255l);
+ i64 >>= 8l;
+ }
+
+ idx_base += 8;
+ }
+ }
+
+ // TODO: Check for overflow when size is of type uint and is > than 512m
+ output->Write(pchBuffer, size * 8);
+ delete[] pchBuffer;
+}
+
+#endif // wxUSE_LONGLONG
+
+#ifdef wxLongLong_t
+
+template <class T>
+static
+void DoReadI64(T *buffer, size_t size, wxInputStream *input, bool be_order)
+{
+ typedef T DataType;
+ unsigned char *pchBuffer = (unsigned char*) buffer;
+ // TODO: Check for overflow when size is of type uint and is > than 512m
+ input->Read(pchBuffer, size * 8);
+ if ( be_order )
+ {
+ for ( wxUint32 i = 0; i < size; i++ )
+ {
+ DataType v = wxUINT64_SWAP_ON_LE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+ else // little endian
+ {
+ for ( wxUint32 i=0; i<size; i++ )
+ {
+ DataType v = wxUINT64_SWAP_ON_BE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+}
+
+template <class T>
+static
+void DoWriteI64(const T *buffer, size_t size, wxOutputStream *output, bool be_order)
+{
+ typedef T DataType;
+ if ( be_order )
+ {
+ for ( size_t i = 0; i < size; i++ )
+ {
+ DataType i64 = wxUINT64_SWAP_ON_LE(*buffer);
+ buffer++;
+ output->Write(&i64, 8);
+ }
+ }
+ else // little endian
+ {
+ for ( size_t i=0; i < size; i++ )
+ {
+ DataType i64 = wxUINT64_SWAP_ON_BE(*buffer);
+ buffer++;
+ output->Write(&i64, 8);
+ }
+ }
+}
+
+#endif // wxLongLong_t
+
+
+#if wxHAS_INT64
+void wxDataInputStream::Read64(wxUint64 *buffer, size_t size)
+{
+#ifndef wxLongLong_t
+ DoReadLL(buffer, size, m_input, m_be_order);
+#else
+ DoReadI64(buffer, size, m_input, m_be_order);
+#endif
+}
+
+void wxDataInputStream::Read64(wxInt64 *buffer, size_t size)
+{
+#ifndef wxLongLong_t
+ DoReadLL(buffer, size, m_input, m_be_order);
+#else
+ DoReadI64(buffer, size, m_input, m_be_order);
+#endif
+}
+#endif // wxHAS_INT64
+
+#if defined(wxLongLong_t) && wxUSE_LONGLONG
+void wxDataInputStream::Read64(wxULongLong *buffer, size_t size)
+{
+ DoReadLL(buffer, size, m_input, m_be_order);
+}
+
+void wxDataInputStream::Read64(wxLongLong *buffer, size_t size)
+{
+ DoReadLL(buffer, size, m_input, m_be_order);
+}
+#endif // wxLongLong_t
+
+#if wxUSE_LONGLONG
+void wxDataInputStream::ReadLL(wxULongLong *buffer, size_t size)
+{
+ DoReadLL(buffer, size, m_input, m_be_order);
+}
+
+void wxDataInputStream::ReadLL(wxLongLong *buffer, size_t size)
+{
+ DoReadLL(buffer, size, m_input, m_be_order);
+}
+
+wxLongLong wxDataInputStream::ReadLL(void)
+{
+ wxLongLong ll;
+ DoReadLL(&ll, (size_t)1, m_input, m_be_order);
+ return ll;
+}
+#endif // wxUSE_LONGLONG
+
+void wxDataInputStream::Read32(wxUint32 *buffer, size_t size)
+{
+ m_input->Read(buffer, size * 4);
+
+ if (m_be_order)
+ {
+ for (wxUint32 i=0; i<size; i++)
+ {
+ wxUint32 v = wxUINT32_SWAP_ON_LE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+ else
+ {
+ for (wxUint32 i=0; i<size; i++)
+ {
+ wxUint32 v = wxUINT32_SWAP_ON_BE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+}
+
+void wxDataInputStream::Read16(wxUint16 *buffer, size_t size)
+{
+ m_input->Read(buffer, size * 2);
+
+ if (m_be_order)
+ {
+ for (wxUint32 i=0; i<size; i++)
+ {
+ wxUint16 v = wxUINT16_SWAP_ON_LE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+ else
+ {
+ for (wxUint32 i=0; i<size; i++)
+ {
+ wxUint16 v = wxUINT16_SWAP_ON_BE(*buffer);
+ *(buffer++) = v;
+ }
+ }
+}
+
+void wxDataInputStream::Read8(wxUint8 *buffer, size_t size)
+{
+ m_input->Read(buffer, size);
+}
+
+void wxDataInputStream::ReadDouble(double *buffer, size_t size)
+{
+ for (wxUint32 i=0; i<size; i++)
+ {
+ *(buffer++) = ReadDouble();
+ }
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxString& s)
+{
+ s = ReadString();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt8& c)
+{
+ c = (wxInt8)Read8();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt16& i)
+{
+ i = (wxInt16)Read16();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt32& i)
+{
+ i = (wxInt32)Read32();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxUint8& c)
+{
+ c = Read8();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxUint16& i)
+{
+ i = Read16();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxUint32& i)
+{
+ i = Read32();
+ return *this;
+}
+
+#if wxHAS_INT64
+wxDataInputStream& wxDataInputStream::operator>>(wxUint64& i)
+{
+ i = Read64();
+ return *this;
+}
+
+wxDataInputStream& wxDataInputStream::operator>>(wxInt64& i)
+{
+ i = Read64();
+ return *this;
+}
+#endif // wxHAS_INT64
+
+#if defined(wxLongLong_t) && wxUSE_LONGLONG
+wxDataInputStream& wxDataInputStream::operator>>(wxULongLong& i)
+{
+ i = ReadLL();
+ return *this;
+}