22 #ifndef COMMON_DATA_IO_H 23 #define COMMON_DATA_IO_H 25 #include "common/scummsys.h" 29 enum class EndianStorageFormat {
36 template<
class TDataFormat>
42 static inline bool isLittleEndian(EndianStorageFormat storageFormat) {
43 return storageFormat == EndianStorageFormat::Little;
47 template<
class TDataFormat,
class T>
49 static const uint kMaxSize =
sizeof(T);
51 static uint computeSize(TDataFormat dataFormat);
53 static void encode(TDataFormat dataFormat, byte *data,
const T &value);
54 static void decode(TDataFormat dataFormat,
const byte *data, T &value);
57 template<
class TDataFormat,
class T>
62 template<
class TDataFormat,
class T>
64 const byte *valueBytes =
reinterpret_cast<const byte *
>(&value);
65 byte *dataBytes =
reinterpret_cast<byte *
>(data);
68 #ifdef SCUMM_LITTLE_ENDIAN 69 const bool isSystemLE =
true;
71 #ifdef SCUMM_BIG_ENDIAN 72 const bool isSystemLE =
false;
75 const bool requiresSwap = (isSystemLE != isTargetLE);
80 for (uint i = 0; i <
sizeof(T); i++)
81 temp[i] = valueBytes[
sizeof(T) - 1 - i];
83 for (uint i = 0; i <
sizeof(T); i++)
84 temp[i] = valueBytes[i];
87 for (uint i = 0; i <
sizeof(T); i++)
88 dataBytes[i] = temp[i];
91 template<
class TDataFormat,
class T>
93 byte *valueBytes =
reinterpret_cast<byte *
>(&value);
94 const byte *dataBytes =
reinterpret_cast<const byte *
>(data);
97 #ifdef SCUMM_LITTLE_ENDIAN 98 const bool isSystemLE =
true;
100 #ifdef SCUMM_BIG_ENDIAN 101 const bool isSystemLE =
false;
104 const bool requiresSwap = (isSystemLE != isTargetLE);
106 byte temp[
sizeof(T)];
109 for (uint i = 0; i <
sizeof(T); i++)
110 temp[i] = dataBytes[
sizeof(T) - 1 - i];
112 for (uint i = 0; i <
sizeof(T); i++)
113 temp[i] = dataBytes[i];
116 for (uint i = 0; i <
sizeof(T); i++)
117 valueBytes[i] = temp[i];
120 template<
class TDataFormat,
class T>
124 template<
class TDataFormat>
128 template<
class TDataFormat>
131 template<
class TDataFormat>
134 template<
class TDataFormat>
138 template<
class TDataFormat>
142 template<
class TDataFormat>
146 template<
class TDataFormat>
150 template<
class TDataFormat>
154 template<
class TDataFormat>
158 template<
class TDataFormat>
162 template<
class TDataFormat>
166 template<
class TDataFormat,
class T,
class... TMore>
169 template<
class TDataFormat,
class T>
173 static uint computeSize(TDataFormat dataFormat);
175 static void encode(TDataFormat dataFormat, byte *data,
const T &value);
176 static void decode(TDataFormat dataFormat,
const byte *data, T &value);
179 template<
class TDataFormat,
class T>
184 template<
class TDataFormat,
class T>
189 template<
class TDataFormat,
class T>
194 template<
class TDataFormat,
class T, u
int TSize>
198 static uint computeSize(TDataFormat dataFormat);
200 static void encode(TDataFormat dataFormat, byte *data,
const T (&value)[TSize]);
201 static void decode(TDataFormat dataFormat,
const byte *data, T (&value)[TSize]);
204 template<
class TDataFormat,
class T, u
int TSize>
209 template<
class TDataFormat,
class T, u
int TSize>
212 for (uint i = 0; i < TSize; i++)
216 template<
class TDataFormat,
class T, u
int TSize>
219 for (uint i = 0; i < TSize; i++)
223 template<
class TDataFormat,
class T,
class... TMore>
227 static uint computeSize(TDataFormat dataFormat);
229 static void encode(TDataFormat dataFormat, byte *data,
const T &firstValue,
const TMore &...moreValues);
230 static void decode(TDataFormat dataFormat,
const byte *data, T &firstValue, TMore &...moreValues);
233 template<
class TDataFormat,
class T,
class... TMore>
238 template<
class TDataFormat,
class T,
class... TMore>
244 template<
class TDataFormat,
class T,
class... TMore>
Definition: data-io.h:167
Definition: algorithm.h:29
Definition: data-io.h:121