Grid 0.7.0
BinaryIO.cc
Go to the documentation of this file.
1 /*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/serialisation/BinaryIO.cc
6
7 Copyright (C) 2015
8
9Author: Antonin Portelli <antonin.portelli@me.com>
10Author: paboyle <paboyle@ph.ed.ac.uk>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26 See the full license in the file "LICENSE" in the top level distribution directory
27 *************************************************************************************/
28 /* END LEGAL */
29#include <Grid/GridCore.h>
30
32
33// Writer implementation ///////////////////////////////////////////////////////
34BinaryWriter::BinaryWriter(const std::string &fileName)
35: file_(fileName, std::ios::binary|std::ios::out)
36{}
37
38template <>
39void BinaryWriter::writeDefault(const std::string &s, const std::string &x)
40{
41 uint64_t sz = x.size();
42
43 write("", sz);
44 for (uint64_t i = 0; i < sz; ++i)
45 {
46 write("", x[i]);
47 }
48}
49
50void BinaryWriter::writeDefault(const std::string &s, const char *x)
51{
52 std::string sx(x);
53
54 writeDefault(s, sx);
55}
56
57// Reader implementation ///////////////////////////////////////////////////////
58BinaryReader::BinaryReader(const std::string &fileName)
59: file_(fileName, std::ios::binary|std::ios::in)
60{}
61
62template <>
63void BinaryReader::readDefault(const std::string &s, std::string &output)
64{
65 uint64_t sz;
66
67 read("", sz);
68 output.resize(sz);
69 file_.read((char *)output.data(), sz);
70}
71
Out accelerator_inline binary(Input1 src_1, Input2 src_2, Operation op)
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
std::ifstream file_
Definition BinaryIO.h:74
void readDefault(const std::string &s, U &output)
Definition BinaryIO.h:122
BinaryReader(const std::string &fileName)
Definition BinaryIO.cc:58
BinaryWriter(const std::string &fileName)
Definition BinaryIO.cc:34
void writeDefault(const std::string &s, const U &x)
Definition BinaryIO.h:79
std::ofstream file_
Definition BinaryIO.h:57