forked from LLNL/zfp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzfparray.h
95 lines (77 loc) · 2.19 KB
/
zfparray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef ZFP_ARRAY_H
#define ZFP_ARRAY_H
#include <algorithm>
#include <climits>
#include <string>
#include "zfp.h"
#include "zfp/exception.h"
namespace zfp {
// abstract base class for compressed array of scalars
class array {
public:
#include "zfp/header.h"
// factory function (see zfpfactory.h)
static zfp::array* construct(const zfp::array::header& header, const void* buffer = 0, size_t buffer_size_bytes = 0);
// public virtual destructor (can delete array through base class pointer)
virtual ~array() {}
// underlying scalar type
zfp_type scalar_type() const { return type; }
// dimensionality
uint dimensionality() const { return dims; }
// rate in bits per value
virtual double rate() const = 0;
// compressed data size and buffer
virtual size_t compressed_size() const = 0;
virtual void* compressed_data() const = 0;
protected:
// default constructor
array() :
type(zfp_type_none),
dims(0),
nx(0), ny(0), nz(0), nw(0)
{}
// generic array with 'dims' dimensions and scalar type 'type'
explicit array(uint dims, zfp_type type) :
type(type),
dims(dims),
nx(0), ny(0), nz(0), nw(0)
{}
// constructor from previously-serialized compressed array
explicit array(uint dims, zfp_type type, const zfp::array::header& header) :
type(type),
dims(dims),
nx(header.size_x()), ny(header.size_y()), nz(header.size_z()), nw(header.size_w())
{
if (header.scalar_type() != type)
throw zfp::exception("zfp array scalar type does not match header");
if (header.dimensionality() != dims)
throw zfp::exception("zfp array dimensionality does not match header");
}
// copy constructor--performs a deep copy
array(const array& a)
{
deep_copy(a);
}
// assignment operator--performs a deep copy
array& operator=(const array& a)
{
deep_copy(a);
return *this;
}
// perform a deep copy
void deep_copy(const array& a)
{
// copy metadata
type = a.type;
dims = a.dims;
nx = a.nx;
ny = a.ny;
nz = a.nz;
nw = a.nw;
}
zfp_type type; // scalar type
uint dims; // array dimensionality (1, 2, 3, or 4)
size_t nx, ny, nz, nw; // array dimensions
};
}
#endif