4 #include "teca_config.h"
12 #include <type_traits>
22 #define TECA_DATASET_STATIC_NEW(T) \
26 return std::make_shared<T>(); \
29 std::shared_ptr<T> shared_from_this() \
31 return std::static_pointer_cast<T>( \
32 teca_dataset::shared_from_this()); \
35 std::shared_ptr<T const> shared_from_this() const \
37 return std::static_pointer_cast<T const>( \
38 teca_dataset::shared_from_this()); \
42 #define TECA_DATASET_NEW_INSTANCE() \
43 virtual p_teca_dataset new_instance() const override \
45 return std::make_shared \
46 <std::remove_const<std::remove_reference \
47 <decltype(*this)>::type>::type >(); \
51 #define TECA_DATASET_NEW_COPY() \
53 virtual p_teca_dataset new_copy(allocator alloc = \
54 allocator::malloc) const override \
56 p_teca_dataset o = std::make_shared \
57 <std::remove_const<std::remove_reference \
58 <decltype(*this)>::type>::type>(); \
60 o->copy(this->shared_from_this(), alloc); \
65 virtual p_teca_dataset new_shallow_copy() override \
67 p_teca_dataset o = std::make_shared \
68 <std::remove_const<std::remove_reference \
69 <decltype(*this)>::type>::type>(); \
71 o->shallow_copy(this->shared_from_this()); \
78 #define TECA_DATASET_PROPERTY(T, name) \
80 void set_##name(const T &val) \
85 const T &get_##name() const \
96 #define TECA_DATASET_METADATA(key, T, len) \
97 TECA_DATASET_METADATA_V(T, key, len) \
98 TECA_DATASET_METADATA_A(T, key, len) \
99 TECA_DATASET_METADATA_ ## len (T, key)
102 #define TECA_DATASET_METADATA_1(T, key) \
103 void set_##key(const T & val_1) \
105 this->get_metadata().set<T>(#key, val_1); \
108 int get_##key(T &val_1) const \
110 return this->get_metadata().get<T>( \
114 #define TECA_DATASET_METADATA_2(T, key) \
115 void set_##key(const T & val_1, const T & val_2) \
117 this->get_metadata().set<T>( \
118 #key, {val_1, val_2}); \
121 int get_##key(T &val_1, T &val_2) const \
123 std::vector<T> vals; \
124 if (this->get_metadata().get<T>(#key, vals)) \
131 #define TECA_DATASET_METADATA_3(T, key) \
132 void set_##key(const T & val_1, const T & val_2, \
135 this->get_metadata().set<T>(#key, \
136 {val_1, val_2, val_3}); \
139 int get_##key(T &val_1, T &val_2, T &val_3) const \
141 std::vector<T> vals; \
142 if (this->get_metadata().get<T>(#key, vals)) \
150 #define TECA_DATASET_METADATA_4(T, key) \
151 void set_##key(const T & val_1, const T & val_2, \
152 const T & val_3, const T & val_4) \
154 this->get_metadata().set<T>(#key, \
155 {val_1, val_2, val_3, val_4}); \
158 #define TECA_DATASET_METADATA_6(T, key) \
159 void set_##key(const T & val_1, const T & val_2, \
160 const T & val_3, const T & val_4, \
161 const T & val_5, const T & val_6) \
163 this->get_metadata().set<T>(#key, \
164 {val_1, val_2, val_3, \
165 val_4, val_5, val_6}); \
168 #define TECA_DATASET_METADATA_8(T, key) \
169 void set_##key(const T & val_1, const T & val_2, \
170 const T & val_3, const T & val_4, \
171 const T & val_5, const T & val_6, \
172 const T & val_7, const T & val_8) \
174 this->get_metadata().set<T>(#key, \
175 {val_1, val_2, val_3, val_4, val_5, \
176 val_6, val_7, val_8}); \
179 #define TECA_DATASET_METADATA_V(T, key, len) \
180 void set_##key(const std::vector<T> &vals) \
182 if (vals.size() != len) \
184 TECA_ERROR(#key " requires " #len " values") \
186 this->get_metadata().set<T>(#key, vals); \
189 int get_##key(std::vector<T> &vals) const \
191 return this->get_metadata().get<T>(#key, vals); \
194 void set_##key(const p_teca_variant_array &vals) \
196 if (vals->size() != len) \
198 TECA_ERROR(#key " requires " #len " values") \
200 this->get_metadata().set(#key, vals); \
203 int get_##key(p_teca_variant_array vals) const \
205 return this->get_metadata().get(#key, vals); \
208 void set_##key(const std::initializer_list<T> &l) \
210 std::vector<T> vals(l); \
211 if (vals.size() != len) \
213 TECA_ERROR(#key " requires " #len " values") \
215 this->get_metadata().set<T>(#key, vals); \
218 #define TECA_DATASET_METADATA_A(T, key, len) \
219 void set_##key(const T *vals) \
221 this->get_metadata().set<T>(#key, vals, len); \
224 int get_##key(T *vals) const \
226 return this->get_metadata().get<T>( \
243 TECA_DATASET_METADATA(index_request_key, std::string, 1)
256 virtual
int set_request_indices(const std::
string &request_key,
257 const
unsigned long ids[2]);
267 virtual
int get_request_indices(
unsigned long ids[2]) const;
278 virtual
int get_request_index(
unsigned long &index) const;
290 virtual
int set_request_index(const std::
string &request_key,
291 unsigned long index);
296 explicit operator
bool() const noexcept
297 {
return !this->empty(); }
312 virtual p_teca_dataset
new_copy(allocator alloc = allocator::malloc)
const = 0;
321 virtual std::string get_class_name()
const = 0;
324 virtual int get_type_code()
const = 0;
332 virtual void copy(
const const_p_teca_dataset &other,
333 allocator alloc = allocator::malloc);
346 virtual void swap(
const p_teca_dataset &other);
364 virtual
int to_stream(std::ostream &) const;
367 virtual
int from_stream(std::istream &);
375 void operator=(const p_teca_dataset &other) = delete;
376 void operator=(p_teca_dataset &&other) = delete;
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:17
Interface for TECA datasets.
Definition: teca_dataset.h:232
virtual void swap(const p_teca_dataset &other)
swap internals of the two objects
virtual p_teca_dataset new_copy(allocator alloc=allocator::malloc) const =0
virtual bool empty() const noexcept
Definition: teca_dataset.h:300
virtual teca_metadata & get_metadata() noexcept
get the dataset metadata
virtual p_teca_dataset new_instance() const =0
virtual constructor. return a new dataset of the same type.
virtual p_teca_dataset new_shallow_copy()=0
virtual void copy_metadata(const const_p_teca_dataset &other)
copy metadata. always a deep copy.
virtual void shallow_copy(const p_teca_dataset &other)
virtual void copy(const const_p_teca_dataset &other, allocator alloc=allocator::malloc)
hamr::buffer_allocator allocator
allocator types
Definition: teca_variant_array.h:46
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.