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
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
BALL_EXPORT LogStream Log
void setSwapEndian(bool swap_endian)
Set the swap_endian flag.
BinaryFileAdaptor()
Default constructor.
void setData(const T &data)
LogStream & error(int n=0)
bool getSwapEndian() const
return the swap_endian flag
const T & getData() const