PSCF v1.1
BinaryFileIArchive.cpp
1/*
2* Util Package - C++ Utilities for Scientific Computation
3*
4* Copyright 2010 - 2017, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "BinaryFileIArchive.h"
9
10#include <vector>
11
12namespace Util
13{
14
15 /*
16 * Constructor.
17 */
19 : filePtr_(0),
20 version_(0),
21 createdFile_(true)
22 { filePtr_ = new std::ifstream(); }
23
24 /*
25 * Constructor.
26 */
28 : filePtr_(0),
29 version_(0),
30 createdFile_(true)
31 { filePtr_ = new std::ifstream(filename.c_str()); }
32
33 /*
34 * Constructor.
35 */
37 : filePtr_(&file),
38 version_(0),
39 createdFile_(false)
40 {}
41
42 /*
43 * Destructor.
44 */
46 {
47 if (filePtr_ && createdFile_) {
48 delete filePtr_;
49 }
50 }
51
52 /*
53 * Return underlying file by reference.
54 */
55 std::ifstream& BinaryFileIArchive::file()
56 { return *filePtr_; }
57
58 /*
59 * Load a std::string from BinaryFileIArchive.
60 */
61 template <>
62 void serialize(BinaryFileIArchive& ar, std::string& data,
63 const unsigned int version)
64 {
65 static std::vector<char> charvec;
66 size_t size;
67 ar.unpack(size);
68 if (size > charvec.capacity()) {
69 charvec.reserve(size + 8);
70 }
71 ar.unpack(&charvec[0], size);
72 data = &charvec[0];
73 }
74
75
76}
Saving archive for binary istream.
void unpack(T &data)
Unpack a single T object.
std::ifstream & file()
Get the underlying ifstream by reference.
virtual ~BinaryFileIArchive()
Destructor.
Utility classes for scientific computation.
Definition: accumulators.mod:1