CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
utilities.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_cereal_utilities_cc_h__
13#define __cxz_cereal_utilities_cc_h__
14
15#include <fstream>
16#include "utilities.h"
17#include "cer_header.h"
18
19namespace CNORXZ
20{
21 namespace cer
22 {
23
24 template <Format F, typename T>
25 void write(std::ostream& os, const MArray<T>& data)
26 {
27 typedef typename OutputFormatMap<F>::type OArchive;
28 OArchive ar(os);
29
31 ar(cereal::make_nvp("cnorxz",h));
32 ar(cereal::make_nvp("array",data));
33 }
34
35 template <Format F, typename T>
36 void read(std::istream& is, MArray<T>& data)
37 {
38 typedef typename InputFormatMap<F>::type IArchive;
39 IArchive ar(is);
40
41 Header h;
42 ar(cereal::make_nvp("cnorxz",h));
43 CXZ_ASSERT(h.content == ContentType::ARRAY, "expected Array (type = "
44 << static_cast<SizeT>(ContentType::ARRAY) << "), got "
45 << static_cast<SizeT>(h.content));
46 ar(cereal::make_nvp("array",data));
47 }
48
49 template <Format F, typename T>
50 void writeFile(const String& name, const MArray<T>& data)
51 {
52 std::fstream os(name, std::ios::binary | std::ios::out);
53 CXZ_ASSERT(os.good(), "could not open output file " << name);
54 write<F>(os, data);
55 CXZ_ASSERT(os.good(), "an error occurred while writing data to file " << name);
56 os.close();
57 }
58
59 template <Format F, typename T>
60 void readFile(const String& name, MArray<T>& data)
61 {
62 std::fstream is(name, std::ios::binary | std::ios::in);
63 CXZ_ASSERT(is.good(), "could not open input file " << name);
64 read<F>(is, data);
65 //CXZ_ASSERT(not is.fail(), "an error occurred reading data from file " << name);
66 is.close();
67 }
68
69 }
70}
71
72#endif
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
CNORXZ Cereal data header declaration.
Header mkHeader(const ContentType content)
Definition cer_header.h:35
void read(std::istream &is, MArray< T > &data)
void writeFile(const String &name, const MArray< T > &data)
void readFile(const String &name, MArray< T > &data)
void write(std::ostream &os, const MArray< T > &data)
std::string String
Definition types.h:42
uint64_t SizeT
Definition types.h:38
Sptr< Range > rangeCast(const RangePtr r)
CNORXZ Cereal utilities declaration.