datstrm.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/datstrm.h
  3. // Purpose: Data stream classes
  4. // Author: Guilhem Lavaux
  5. // Modified by: Mickael Gilabert
  6. // Created: 28/06/1998
  7. // Copyright: (c) Guilhem Lavaux
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_DATSTREAM_H_
  11. #define _WX_DATSTREAM_H_
  12. #include "wx/stream.h"
  13. #include "wx/longlong.h"
  14. #include "wx/convauto.h"
  15. #if wxUSE_STREAMS
  16. // Common wxDataInputStream and wxDataOutputStream parameters.
  17. class WXDLLIMPEXP_BASE wxDataStreamBase
  18. {
  19. public:
  20. void BigEndianOrdered(bool be_order) { m_be_order = be_order; }
  21. // By default we use extended precision (80 bit) format for both float and
  22. // doubles. Call this function to switch to alternative representation in
  23. // which IEEE 754 single precision (32 bits) is used for floats and double
  24. // precision (64 bits) is used for doubles.
  25. void UseBasicPrecisions()
  26. {
  27. #if wxUSE_APPLE_IEEE
  28. m_useExtendedPrecision = false;
  29. #endif // wxUSE_APPLE_IEEE
  30. }
  31. // UseExtendedPrecision() is not very useful as it corresponds to the
  32. // default value, only call it in your code if you want the compilation
  33. // fail with the error when using wxWidgets library compiled without
  34. // extended precision support.
  35. #if wxUSE_APPLE_IEEE
  36. void UseExtendedPrecision()
  37. {
  38. m_useExtendedPrecision = true;
  39. }
  40. #endif // wxUSE_APPLE_IEEE
  41. #if wxUSE_UNICODE
  42. void SetConv( const wxMBConv &conv );
  43. wxMBConv *GetConv() const { return m_conv; }
  44. #endif
  45. protected:
  46. // Ctor and dtor are both protected, this class is never used directly but
  47. // only by its derived classes.
  48. wxDataStreamBase(const wxMBConv& conv);
  49. ~wxDataStreamBase();
  50. bool m_be_order;
  51. #if wxUSE_APPLE_IEEE
  52. bool m_useExtendedPrecision;
  53. #endif // wxUSE_APPLE_IEEE
  54. #if wxUSE_UNICODE
  55. wxMBConv *m_conv;
  56. #endif
  57. wxDECLARE_NO_COPY_CLASS(wxDataStreamBase);
  58. };
  59. class WXDLLIMPEXP_BASE wxDataInputStream : public wxDataStreamBase
  60. {
  61. public:
  62. wxDataInputStream(wxInputStream& s, const wxMBConv& conv = wxConvUTF8);
  63. bool IsOk() { return m_input->IsOk(); }
  64. #if wxHAS_INT64
  65. wxUint64 Read64();
  66. #endif
  67. #if wxUSE_LONGLONG
  68. wxLongLong ReadLL();
  69. #endif
  70. wxUint32 Read32();
  71. wxUint16 Read16();
  72. wxUint8 Read8();
  73. double ReadDouble();
  74. float ReadFloat();
  75. wxString ReadString();
  76. #if wxHAS_INT64
  77. void Read64(wxUint64 *buffer, size_t size);
  78. void Read64(wxInt64 *buffer, size_t size);
  79. #endif
  80. #if defined(wxLongLong_t) && wxUSE_LONGLONG
  81. void Read64(wxULongLong *buffer, size_t size);
  82. void Read64(wxLongLong *buffer, size_t size);
  83. #endif
  84. #if wxUSE_LONGLONG
  85. void ReadLL(wxULongLong *buffer, size_t size);
  86. void ReadLL(wxLongLong *buffer, size_t size);
  87. #endif
  88. void Read32(wxUint32 *buffer, size_t size);
  89. void Read16(wxUint16 *buffer, size_t size);
  90. void Read8(wxUint8 *buffer, size_t size);
  91. void ReadDouble(double *buffer, size_t size);
  92. void ReadFloat(float *buffer, size_t size);
  93. wxDataInputStream& operator>>(wxString& s);
  94. wxDataInputStream& operator>>(wxInt8& c);
  95. wxDataInputStream& operator>>(wxInt16& i);
  96. wxDataInputStream& operator>>(wxInt32& i);
  97. wxDataInputStream& operator>>(wxUint8& c);
  98. wxDataInputStream& operator>>(wxUint16& i);
  99. wxDataInputStream& operator>>(wxUint32& i);
  100. #if wxHAS_INT64
  101. wxDataInputStream& operator>>(wxUint64& i);
  102. wxDataInputStream& operator>>(wxInt64& i);
  103. #endif
  104. #if defined(wxLongLong_t) && wxUSE_LONGLONG
  105. wxDataInputStream& operator>>(wxULongLong& i);
  106. wxDataInputStream& operator>>(wxLongLong& i);
  107. #endif
  108. wxDataInputStream& operator>>(double& d);
  109. wxDataInputStream& operator>>(float& f);
  110. protected:
  111. wxInputStream *m_input;
  112. wxDECLARE_NO_COPY_CLASS(wxDataInputStream);
  113. };
  114. class WXDLLIMPEXP_BASE wxDataOutputStream : public wxDataStreamBase
  115. {
  116. public:
  117. wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv = wxConvUTF8);
  118. bool IsOk() { return m_output->IsOk(); }
  119. #if wxHAS_INT64
  120. void Write64(wxUint64 i);
  121. void Write64(wxInt64 i);
  122. #endif
  123. #if wxUSE_LONGLONG
  124. void WriteLL(const wxLongLong &ll);
  125. void WriteLL(const wxULongLong &ll);
  126. #endif
  127. void Write32(wxUint32 i);
  128. void Write16(wxUint16 i);
  129. void Write8(wxUint8 i);
  130. void WriteDouble(double d);
  131. void WriteFloat(float f);
  132. void WriteString(const wxString& string);
  133. #if wxHAS_INT64
  134. void Write64(const wxUint64 *buffer, size_t size);
  135. void Write64(const wxInt64 *buffer, size_t size);
  136. #endif
  137. #if defined(wxLongLong_t) && wxUSE_LONGLONG
  138. void Write64(const wxULongLong *buffer, size_t size);
  139. void Write64(const wxLongLong *buffer, size_t size);
  140. #endif
  141. #if wxUSE_LONGLONG
  142. void WriteLL(const wxULongLong *buffer, size_t size);
  143. void WriteLL(const wxLongLong *buffer, size_t size);
  144. #endif
  145. void Write32(const wxUint32 *buffer, size_t size);
  146. void Write16(const wxUint16 *buffer, size_t size);
  147. void Write8(const wxUint8 *buffer, size_t size);
  148. void WriteDouble(const double *buffer, size_t size);
  149. void WriteFloat(const float *buffer, size_t size);
  150. wxDataOutputStream& operator<<(const wxString& string);
  151. wxDataOutputStream& operator<<(wxInt8 c);
  152. wxDataOutputStream& operator<<(wxInt16 i);
  153. wxDataOutputStream& operator<<(wxInt32 i);
  154. wxDataOutputStream& operator<<(wxUint8 c);
  155. wxDataOutputStream& operator<<(wxUint16 i);
  156. wxDataOutputStream& operator<<(wxUint32 i);
  157. #if wxHAS_INT64
  158. wxDataOutputStream& operator<<(wxUint64 i);
  159. wxDataOutputStream& operator<<(wxInt64 i);
  160. #endif
  161. #if defined(wxLongLong_t) && wxUSE_LONGLONG
  162. wxDataOutputStream& operator<<(const wxULongLong &i);
  163. wxDataOutputStream& operator<<(const wxLongLong &i);
  164. #endif
  165. wxDataOutputStream& operator<<(double d);
  166. wxDataOutputStream& operator<<(float f);
  167. protected:
  168. wxOutputStream *m_output;
  169. wxDECLARE_NO_COPY_CLASS(wxDataOutputStream);
  170. };
  171. #endif
  172. // wxUSE_STREAMS
  173. #endif
  174. // _WX_DATSTREAM_H_