33#include "../mxlib.hpp"
107template <
typename dataT>
113 return binVTypes::Bool;
117binVTypeT binVectorTypeCode<signed char>()
119 return binVTypes::SChar;
123binVTypeT binVectorTypeCode<unsigned char>()
125 return binVTypes::UChar;
131 return binVTypes::Char;
137 return binVTypes::WChar;
143 return binVTypes::Char16;
149 return binVTypes::Char32;
155 return binVTypes::Int;
159binVTypeT binVectorTypeCode<unsigned int>()
161 return binVTypes::UInt;
167 return binVTypes::SInt;
171binVTypeT binVectorTypeCode<short unsigned int>()
173 return binVTypes::SUInt;
179 return binVTypes::LInt;
183binVTypeT binVectorTypeCode<long unsigned int>()
185 return binVTypes::LUInt;
189binVTypeT binVectorTypeCode<long long int>()
191 return binVTypes::LLInt;
195binVTypeT binVectorTypeCode<long long unsigned int>()
197 return binVTypes::LLUInt;
203 return binVTypes::Float;
209 return binVTypes::Double;
213binVTypeT binVectorTypeCode<long double>()
215 return binVTypes::LDouble;
219binVTypeT binVectorTypeCode<std::complex<float>>()
221 return binVTypes::CFloat;
225binVTypeT binVectorTypeCode<std::complex<double>>()
227 return binVTypes::CDouble;
239template <
typename dataT>
241 const std::string &fname
249 fin = fopen( fname.c_str(),
"r" );
257 nrd = fread( &typecode,
sizeof(
binVTypeT ), 1, fin );
269 "Error reading data size, did not read enough bytes. [" + fname +
"]" );
275 if( typecode != binVectorTypeCode<dataT>() )
278 "Mismatch between type dataT and type in file [" + fname +
"]" );
284 nrd = fread( &sz,
sizeof(
binVSizeT ), 1, fin );
296 "Error reading vector size, did not read enough bytes [" + fname +
"]" );
305 nrd = fread( vec.data(),
sizeof( dataT ), sz, fin );
335template <
typename dataT>
337 std::vector<dataT> &vec
343 binVTypeT typecode = binVectorTypeCode<dataT>();
346 fout = fopen( fname.c_str(),
"wb" );
353 nwr = fwrite( &typecode,
sizeof(
binVTypeT ), 1, fout );
361 nwr = fwrite( &sz,
sizeof(
binVSizeT ), 1, fout );
369 nwr = fwrite( vec.data(),
sizeof( dataT ), vec.size(), fout );
uint64_t binVSizeT
The type used for binVector sizes.
int writeBinVector(const std::string &fname, std::vector< dataT > &vec)
Write a BinVector file to disk.
binVTypeT binVectorTypeCode()
Get the integer type code corresponding to the type.
uint64_t binVTypeT
The type of binVector type codes.
int readBinVector(std::vector< dataT > &vec, const std::string &fname)
Read a BinVector file from disk.
static constexpr error_t errno2error_t(const int &err)
Convert an errno code to error_t.
@ filererr
An error occurred while reading from a file.
@ sizeerr
A size was invalid or calculated incorrectly.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.