21 #include <type_traits>
31 template <
class DataType,
bool FreeOnClose>
32 void FreeType(DataType,
typename std::enable_if<!std::is_pointer<DataType>::value>::type* = 0) {}
33 template <
class DataType,
bool FreeOnClose>
34 void FreeType(DataType,
typename std::enable_if<std::is_pointer<DataType>::value>::type* = 0,
35 typename std::enable_if<!FreeOnClose>::type* = 0) {}
36 template <
class DataType,
bool FreeOnClose>
37 void FreeType(DataType d,
typename std::enable_if<std::is_pointer<DataType>::value>::type* = 0,
38 typename std::enable_if<FreeOnClose>::type* = 0) {
44 template <
class T,
class value_type = T,
bool FreeOnClose = false>
53 for (
auto& p :
DataPointers) FreeType<value_type, FreeOnClose>(p);
65 template <
class DataType,
class value_type = DataType>
70 typedef std::shared_ptr<Marshalled_Data<DataType, mutable_DataType>>
serialized_type;
81 auto res = std::make_shared<Marshalled_Data<DataType, mutable_DataType>>();
82 res->DataPointers = std::vector<mutable_DataType>(d.size());
88 for (
size_t i = 0; i < (size_t)d.size(); ++i) res->DataPointers[i] = d[i];
97 auto res = std::make_shared<typename serialized_type::element_type>(
pointerOwner_);
98 res->DataPointers = std::vector<mutable_DataType>(numObjects);
103 const size_t ds = data.size(), dp = p->DataPointers.size();
105 for (
size_t i = 0; i < (size_t)data.size(); ++i) {
106 data[i] = p->DataPointers[i];
112 template <
class DataType,
class value_type = std::remove_po
inter<std::decay<DataType>>>
126 auto res = std::make_shared<Marshalled_Data<DataType, mutable_DataType>>();
127 res->DataPointers = std::vector<mutable_DataType>(d.size());
128 std::copy_n(
reinterpret_cast<char*
>(d.data()), d.size_bytes(),
129 reinterpret_cast<char*
>(res->DataPointers.data()));
143 auto res = std::make_shared<typename serialized_type::element_type>(
pointerOwner_);
144 res->DataPointers = std::vector<mutable_DataType>(numObjects);
149 const size_t ds = data.size(), dp = p->DataPointers.size();
151 std::copy_n(
reinterpret_cast<char*
>(p->DataPointers.data()), data.size_bytes(),
152 reinterpret_cast<char*
>(data.data()));
160 template <
class DataType,
class value_type = DataType*>
164 typedef std::shared_ptr<const Marshalled_Data<DataType, mutable_value_type, false>>
166 typedef std::shared_ptr<Marshalled_Data<DataType, mutable_value_type, true>>
serialized_type;
174 auto res = std::make_shared<Marshalled_Data<DataType, mutable_value_type, false>>();
175 for (
const auto& i : d) {
181 auto res = std::make_shared<typename serialized_type::element_type>(
pointerOwner_);
182 res->DataPointers = std::vector<mutable_value_type>(numObjects);
186 const size_t ds = data.size(), dp = p->DataPointers.size();
188 for (
size_t i = 0; i < ds; ++i) {
189 if (p->DataPointers[i])
190 data[i] = p->DataPointers[i];
196 template <
class DataType,
class value_type = DataType*>
200 typedef std::shared_ptr<const Marshalled_Data<DataType, mutable_value_type, false>>
202 typedef std::shared_ptr<Marshalled_Data<DataType, mutable_value_type, true>>
serialized_type;
210 auto res = std::make_shared<Marshalled_Data<DataType, mutable_value_type, false>>();
211 for (
const auto& i : d) {
217 auto res = std::make_shared<typename serialized_type::element_type>(
pointerOwner_);
218 res->DataPointers = std::vector<mutable_value_type>(numObjects);
222 const size_t ds = data.size(), dp = p->DataPointers.size();
224 for (
size_t i = 0; i < (size_t)data.size(); ++i) {
225 data[i] = p->DataPointers[i];
231 template <
typename T>
257 template <
typename DataType>
Frontend/backend bindings for the type system.
The ioda exception class.
Common preprocessor definitions used throughout IODA.
typename detail::Object_AccessorTypedef< DataType >::type Object_Accessor
PointerOwner
Who owns (and should free) pointers passed across the frontend / backend interface?
void FreeType(DataType, typename std::enable_if<!std::is_pointer< DataType >::value >::type *=0)
@ Caller
The user has to free pointers.
@ Engine
The backend engine frees pointers that it provides.
Structure used to pass data between the frontend and the backend engine.
Marshalled_Data(detail::PointerOwner pointerOwner=detail::PointerOwner::Caller)
std::vector< value_type > DataPointers
detail::PointerOwner pointerOwner_
Object_Accessor_Fixed_Array(detail::PointerOwner pointerOwner=detail::PointerOwner::Caller)
std::remove_const< value_type >::type mutable_value_type
const_serialized_type serialize(::gsl::span< const DataType > d)
Converts an object into a void* byte stream.
serialized_type prep_deserialize(size_t numObjects)
Construct an object from a byte stream, and deallocate any temporary buffer.
std::shared_ptr< Marshalled_Data< DataType, mutable_DataType > > serialized_type
void deserialize(serialized_type p, gsl::span< DataType > data)
Unpack the data. For POD, nothing special here.
std::remove_const< DataType >::type mutable_DataType
detail::PointerOwner pointerOwner_
std::shared_ptr< const Marshalled_Data< DataType, mutable_DataType > > const_serialized_type
Object_Accessor_Regular(detail::PointerOwner pointerOwner=detail::PointerOwner::Caller)
std::shared_ptr< Marshalled_Data< DataType, mutable_DataType > > serialized_type
std::remove_const< value_type >::type mutable_value_type
std::remove_const< DataType >::type mutable_DataType
serialized_type prep_deserialize(size_t numObjects)
Construct an object from a byte stream, and deallocate any temporary buffer.
const_serialized_type serialize(::gsl::span< const DataType > d)
Converts an object into a void* byte stream.
std::shared_ptr< const Marshalled_Data< DataType, mutable_DataType > > const_serialized_type
void deserialize(serialized_type p, gsl::span< DataType > data)
Unpack the data. For POD, nothing special here.
detail::PointerOwner pointerOwner_
Object_Accessor_Variable_Array_With_Data_Method(detail::PointerOwner pointerOwner=detail::PointerOwner::Caller)
std::shared_ptr< Marshalled_Data< DataType, mutable_value_type, true > > serialized_type
void deserialize(serialized_type p, gsl::span< DataType > data)
std::remove_const< value_type >::type mutable_value_type
std::remove_const< DataType >::type mutable_DataType
serialized_type prep_deserialize(size_t numObjects)
const_serialized_type serialize(::gsl::span< const DataType > d)
std::shared_ptr< const Marshalled_Data< DataType, mutable_value_type, false > > const_serialized_type
detail::PointerOwner pointerOwner_
detail::PointerOwner pointerOwner_
std::shared_ptr< Marshalled_Data< DataType, mutable_value_type, true > > serialized_type
Object_Accessor_Variable_Raw_Array(detail::PointerOwner pointerOwner=detail::PointerOwner::Caller)
void deserialize(serialized_type p, gsl::span< DataType > data)
std::remove_const< DataType >::type mutable_DataType
std::remove_const< value_type >::type mutable_value_type
serialized_type prep_deserialize(size_t numObjects)
const_serialized_type serialize(::gsl::span< const DataType > d)
std::shared_ptr< const Marshalled_Data< DataType, mutable_value_type, false > > const_serialized_type
Object_Accessor_Fixed_Array< int[2]> type
Object_Accessor_Fixed_Array< std::array< int, 2 >, int > type
Object_Accessor_Variable_Array_With_Data_Method< std::string, char * > type
Object_Accessor_Regular< T > type