GridFormat 0.2.1
I/O-Library for grid-like data structures
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2// SPDX-License-Identifier: MIT
8#ifndef GRIDFORMAT_COMPRESSION_COMMON_HPP_
9#define GRIDFORMAT_COMPRESSION_COMMON_HPP_
10
11#include <vector>
12#include <utility>
13#include <numeric>
14
15#include <gridformat/common/exceptions.hpp>
16#include <gridformat/common/serialization.hpp>
17
18namespace GridFormat::Compression {
19
22
23inline constexpr std::size_t default_block_size = (1 << 15);
24
26template<std::integral HeaderType = std::size_t>
27struct Blocks {
28 const HeaderType block_size;
29 const HeaderType residual_block_size;
30 const HeaderType number_of_blocks;
31
32 Blocks(HeaderType size_in_bytes, HeaderType block_size)
33 : block_size{block_size}
34 , residual_block_size{size_in_bytes%block_size}
35 , number_of_blocks{residual_block_size ? size_in_bytes/block_size + 1 : size_in_bytes/block_size}
36 {}
37};
38
40template<std::integral HeaderType = std::size_t>
42 const HeaderType block_size;
43 const HeaderType residual_block_size;
44 const HeaderType number_of_blocks;
45 const std::vector<HeaderType> compressed_block_sizes;
46
48 std::vector<HeaderType>&& comp_block_sizes)
49 : block_size{blocks.block_size}
50 , residual_block_size{blocks.residual_block_size}
51 , number_of_blocks{blocks.number_of_blocks}
52 , compressed_block_sizes{std::move(comp_block_sizes)} {
53 if (compressed_block_sizes.size() != number_of_blocks)
54 throw SizeError("Mismatch between blocks and number of compressed blocks");
55 }
56
57 std::size_t compressed_size() const {
58 return std::accumulate(
59 compressed_block_sizes.begin(),
60 compressed_block_sizes.end(),
61 1
62 );
63 }
64};
65
67
68} // end namespace GridFormat::Compression
69
70#endif // GRIDFORMAT_COMPRESSION_COMMON_HPP_
constexpr std::size_t default_block_size
as in VTK (https://gitlab.kitware.com/vtk/vtk/-/blob/65fc526a83ac829628a9462f61fa57f1801e2c7e/IO/XML/...
Definition: common.hpp:23
Stores the block sizes used for compressing the given amount of bytes.
Definition: common.hpp:27
Stores the uncompressed/compressed block sizes after completion of a compression.
Definition: common.hpp:41