23 #include "openPMD/Dataset.hpp"
24 #include "openPMD/Datatype.hpp"
25 #include "openPMD/auxiliary/UniquePtr.hpp"
31 #include <type_traits>
39 inline std::unique_ptr<void, std::function<void(
void *)>>
40 allocatePtr(
Datatype dtype, uint64_t numPoints)
43 std::function<void(
void *)> del = [](
void *) {};
48 data =
new char *[numPoints];
49 del = [](
void *p) {
delete[]
static_cast<char **
>(p); };
51 case DT::VEC_LONG_DOUBLE:
53 data =
new long double[numPoints];
54 del = [](
void *p) {
delete[]
static_cast<long double *
>(p); };
59 data =
new double[numPoints];
60 del = [](
void *p) {
delete[]
static_cast<double *
>(p); };
64 data =
new float[numPoints];
65 del = [](
void *p) {
delete[]
static_cast<float *
>(p); };
67 case DT::VEC_CLONG_DOUBLE:
68 case DT::CLONG_DOUBLE:
69 data =
new std::complex<long double>[numPoints];
71 delete[]
static_cast<std::complex<long double> *
>(p);
76 data =
new std::complex<double>[numPoints];
78 delete[]
static_cast<std::complex<double> *
>(p);
83 data =
new std::complex<float>[numPoints];
85 delete[]
static_cast<std::complex<float> *
>(p);
90 data =
new short[numPoints];
91 del = [](
void *p) {
delete[]
static_cast<short *
>(p); };
95 data =
new int[numPoints];
96 del = [](
void *p) {
delete[]
static_cast<int *
>(p); };
100 data =
new long[numPoints];
101 del = [](
void *p) {
delete[]
static_cast<long *
>(p); };
103 case DT::VEC_LONGLONG:
105 data =
new long long[numPoints];
106 del = [](
void *p) {
delete[]
static_cast<long long *
>(p); };
110 data =
new unsigned short[numPoints];
111 del = [](
void *p) {
delete[]
static_cast<unsigned short *
>(p); };
115 data =
new unsigned int[numPoints];
116 del = [](
void *p) {
delete[]
static_cast<unsigned int *
>(p); };
120 data =
new unsigned long[numPoints];
121 del = [](
void *p) {
delete[]
static_cast<unsigned long *
>(p); };
123 case DT::VEC_ULONGLONG:
125 data =
new unsigned long long[numPoints];
127 delete[]
static_cast<unsigned long long *
>(p);
132 data =
new char[numPoints];
133 del = [](
void *p) {
delete[]
static_cast<char *
>(p); };
137 data =
new unsigned char[numPoints];
138 del = [](
void *p) {
delete[]
static_cast<unsigned char *
>(p); };
142 data =
new signed char[numPoints];
143 del = [](
void *p) {
delete[]
static_cast<signed char *
>(p); };
146 data =
new bool[numPoints];
147 del = [](
void *p) {
delete[]
static_cast<bool *
>(p); };
154 throw std::runtime_error(
155 "Unknown Attribute datatype (Pointer allocation)");
158 return std::unique_ptr<void, std::function<void(
void *)>>(data, del);
161 inline std::unique_ptr<void, std::function<void(
void *)>>
162 allocatePtr(
Datatype dtype, Extent
const &e)
164 uint64_t numPoints = 1u;
165 for (
auto const &dimensionSize : e)
166 numPoints *= dimensionSize;
167 return allocatePtr(dtype, numPoints);
176 using EligibleTypes = std::
178 EligibleTypes m_buffer;
183 template <
typename... Args>
185 : m_buffer(std::forward<Args>(args)...)
193 WriteBuffer const &operator=(std::shared_ptr<void const> ptr)
195 m_buffer = std::move(ptr);
201 m_buffer = std::move(ptr);
205 inline void const *get()
const
208 [](
auto const &arg) {
211 return static_cast<void const *
>(arg.get());
Public definitions of openPMD-api.
Definition: Date.cpp:29
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:51
Definition: Memory.hpp:175