33 #include "../mxlib.hpp"
34 #include "../mxError.hpp"
106 template<
typename dataT>
112 return binVTypes::Bool;
116 binVTypeT binVectorTypeCode<signed char>()
118 return binVTypes::SChar;
122 binVTypeT binVectorTypeCode<unsigned char>()
124 return binVTypes::UChar;
130 return binVTypes::Char;
136 return binVTypes::WChar;
142 return binVTypes::Char16;
148 return binVTypes::Char32;
154 return binVTypes::Int;
158 binVTypeT binVectorTypeCode<unsigned int>()
160 return binVTypes::UInt;
166 return binVTypes::SInt;
170 binVTypeT binVectorTypeCode<short unsigned int>()
172 return binVTypes::SUInt;
178 return binVTypes::LInt;
182 binVTypeT binVectorTypeCode<long unsigned int>()
184 return binVTypes::LUInt;
188 binVTypeT binVectorTypeCode<long long int>()
190 return binVTypes::LLInt;
194 binVTypeT binVectorTypeCode<long long unsigned int>()
196 return binVTypes::LLUInt;
203 return binVTypes::Float;
209 return binVTypes::Double;
213 binVTypeT binVectorTypeCode<long double>()
215 return binVTypes::LDouble;
219 binVTypeT binVectorTypeCode<std::complex<float>>()
221 return binVTypes::CFloat;
225 binVTypeT binVectorTypeCode<std::complex<double>>()
227 return binVTypes::CDouble;
239 template<
typename dataT>
241 const std::string & fname
249 fin = fopen(fname.c_str(),
"r");
252 mxPError(
"readBinVector", errno,
"Error from fopen [" + fname +
"]");
257 nrd = fread(&typecode,
sizeof(
binVTypeT), 1, fin);
264 mxPError(
"readBinVector", errno,
"Error reading data size [" + fname +
"]");
268 mxError(
"readBinVector", MXE_FILERERR,
"Error reading data size, did not read enough bytes. [" + fname +
"]");
274 if( typecode != binVectorTypeCode<dataT>() )
276 mxError(
"readBinVector", MXE_SIZEERR,
"Mismatch between type dataT and type in file [" + fname +
"]");
283 nrd = fread(&sz,
sizeof(
binVSizeT), 1, fin);
290 mxPError(
"readBinVector", errno,
"Error reading vector size [" + fname +
"]");
294 mxError(
"readBinVector", MXE_FILERERR,
"Error reading vector size, did not read enough bytes [" + fname +
"]");
303 nrd = fread(vec.data(),
sizeof(dataT), sz, fin);
310 mxPError(
"readBinVector", errno,
"Error reading data [" + fname +
"]");
314 mxError(
"readBinVector", MXE_FILERERR,
"Did not read enough data [" + fname +
"]");
333 template<
typename dataT>
335 std::vector<dataT> & vec
341 binVTypeT typecode = binVectorTypeCode<dataT>();
344 fout = fopen(fname.c_str(),
"wb");
347 mxPError(
"writeBinVector", errno,
"Error from fopen [" + fname +
"]");
351 nwr = fwrite( &typecode,
sizeof(
binVTypeT), 1, fout);
354 mxPError(
"writeBinVector", errno,
"Error writing typecode [" + fname +
"]");
359 nwr = fwrite( &sz,
sizeof(
binVSizeT), 1, fout);
362 mxPError(
"writeBinVector", errno,
"Error writing vector size [" + fname +
"]");
367 nwr = fwrite( vec.data(),
sizeof(dataT), vec.size(), fout);
370 mxPError(
"writeBinVector", errno,
"Error writing data [" + fname +
"]");
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.