15 #ifndef PSEN_SCAN_V2_STANDALONE_RAW_PROCESSING_H
16 #define PSEN_SCAN_V2_STANDALONE_RAW_PROCESSING_H
25 #include <fmt/format.h>
29 namespace data_conversion_layer
35 namespace raw_processing
47 inline void write(std::ostringstream& os,
const T& data)
49 os.write(
reinterpret_cast<const char*
>(&data),
sizeof(T));
53 inline void read(std::istream& is, T& data)
55 is.read(
reinterpret_cast<char*
>(&data),
sizeof(T));
59 fmt::format(
"Failure reading {} characters from input stream, could only read {}.",
sizeof(T), is.gcount()));
64 inline T
read(std::istream& is)
67 raw_processing::read<T>(is, retval);
71 template <
class ReturnType,
class RawType>
74 template <
typename RawType,
typename ReturnType>
77 return conversion_fcn(raw_processing::read<RawType>(is));
80 template <
typename RawType,
typename ReturnType>
81 inline ReturnType
read(std::istream& is)
83 return ReturnType(raw_processing::read<RawType>(is));
86 template <
typename RawType,
typename ReturnType>
88 std::vector<ReturnType>& data,
89 const size_t& number_of_samples,
92 data.reserve(number_of_samples);
94 std::generate_n(std::back_inserter(data), number_of_samples, [&is, &conversion_fcn]() {
95 return raw_processing::read<RawType, ReturnType>(is, conversion_fcn);
99 template <
typename RawType,
typename ArrayElemType>
101 const std::vector<ArrayElemType>& array,
104 for (
const auto& elem : array)
110 template <
typename T>
113 const std::string data_str(os.str());
116 raw_data.reserve(data_str.length());
118 std::copy(data_str.begin(), data_str.end(), std::back_inserter(raw_data));
130 #endif // PSEN_SCAN_V2_STANDALONE_RAW_PROCESSING_H