1 #ifndef BALL_SYSTEM_BINARYFILEADAPTOR_H
2 #define BALL_SYSTEM_BINARYFILEADAPTOR_H
7 #ifndef BALL_COMMON_LOGSTREAM_H
19 if (
sizeof(T) % 2 != 0)
21 Log.
error() <<
"Cannot swap types of uneven size." << std::endl;
25 char* tmp =
reinterpret_cast<char*
>(&t);
26 std::reverse(tmp, tmp +
sizeof(T));
101 template <
typename T>
108 template <
typename T>
111 swap_endian_(swap_endian)
115 template <
typename T>
118 swap_endian_ = swap_endian;
121 template <
typename T>
127 template <
typename T>
133 template <
typename T>
139 template <
typename T>
146 template <
typename T>
147 std::ostream& operator << (std::ostream& os, const BinaryFileAdaptor<T>& data)
150 if (!data.getSwapEndian())
152 os.write(reinterpret_cast<const char*>(&data.getData()),
sizeof(T));
156 T swapped_data = data.getData();
158 os.write(reinterpret_cast<const char*>(&swapped_data),
sizeof(T));
164 template <
typename T>
170 is.read(reinterpret_cast<char*>(&data.
getData()),
sizeof(T));
175 is.read(reinterpret_cast<char*>(&swapped_data),
sizeof(T));
184 #ifndef BALL_NO_INLINE_FUNCTIONS
185 #include <BALL/SYSTEM/binaryFileAdaptor.iC>
188 #endif //BALL_SYSTEM_BINARYFILEADAPTOR_H