Loading...
Searching...
No Matches
binary_archive.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24#ifndef __BITPIT_BINARY_ARCHIVE_HPP__
25#define __BITPIT_BINARY_ARCHIVE_HPP__
26
27#include <array>
28#include <iostream>
29#include <limits>
30#include <fstream>
31
32#include "bitpit_common.hpp"
33
34namespace bitpit {
35
36class BinaryArchive : protected std::fstream
37{
38
39public:
40 BITPIT_PUBLIC_API static const int HEADER_SIZE = 1024;
41 BITPIT_PUBLIC_API static const int VERSION_UNDEFINED = - std::numeric_limits<int>::max();
42
43 BITPIT_PUBLIC_API static const std::string EXTENSION_DEFAULT;
44
45 static std::string generatePath(const std::string &name, int block = -1);
46 static std::string generatePath(const std::string &name, const std::string &extension, int block = -1);
47
48 using std::fstream::close;
49
52
53 int getVersion() const;
54 std::string getHeader() const;
55 std::string getPath() const;
56
57protected:
58 int m_version;
59 std::string m_header;
60 std::string m_path;
61
62 void open(const std::string &name, const std::string &extension,
63 ios_base::openmode mode, int block = -1);
64
65};
66
68{
69
70public:
71 IBinaryArchive() = default;
72 IBinaryArchive(const std::string &name, int block = -1);
73 IBinaryArchive(const std::string &name, const std::string &extension, int block = -1);
74
75 void open(const std::string &name, int block = -1);
76 void open(const std::string &name, const std::string &extension, int block = -1);
77
78 std::istream & getStream();
79
80 bool checkVersion(int version);
81
82 using BinaryArchive::operator>>;
83 using BinaryArchive::read;
84
85};
86
88{
89
90public:
91 OBinaryArchive() = default;
92 OBinaryArchive(const std::string &name, int version,
93 int block = -1);
94 OBinaryArchive(const std::string &name, int version, const std::string &header,
95 int block = -1);
96 OBinaryArchive(const std::string &name, const std::string &extension, int version,
97 int block = -1);
98 OBinaryArchive(const std::string &name, const std::string &extension, int version,
99 const std::string &header, int block = -1);
100
101 void open(const std::string &name, const int version,
102 int block = -1);
103 void open(const std::string &name, int version, const std::string &header,
104 int block = -1);
105 void open(const std::string &name, const std::string &extension, int version,
106 int block = -1);
107 void open(const std::string &name, const std::string &extension, int version,
108 const std::string &header, int block = -1);
109
110 std::ostream & getStream();
111
112 using BinaryArchive::operator<<;
113 using BinaryArchive::write;
114
115};
116
117}
118
119#endif
Base class for binary archives.
std::string getHeader() const
static std::string generatePath(const std::string &name, int block=-1)
void open(const std::string &name, const std::string &extension, ios_base::openmode mode, int block=-1)
std::string getPath() const
Input binary archive.
bool checkVersion(int version)
void open(const std::string &name, int block=-1)
std::istream & getStream()
Output binary archive.
void open(const std::string &name, const int version, int block=-1)
std::ostream & getStream()
--- layout: doxygen_footer ---