1 #ifndef teca_array_collection_h
2 #define teca_array_collection_h
4 #include "teca_config.h"
5 #include "teca_dataset.h"
24 TECA_DATASET_NEW_INSTANCE()
25 TECA_DATASET_NEW_COPY()
28 TECA_DATASET_METADATA(time,
double, 1)
29 TECA_DATASET_METADATA(calendar, std::
string, 1)
30 TECA_DATASET_METADATA(time_units, std::
string, 1)
31 TECA_DATASET_METADATA(time_step,
unsigned long, 1)
43 template<typename nT, typename aT, typename... oT>
44 void declare_set(nT &&a_name, aT a_type, oT &&...args);
47 template<typename nT, typename aT>
48 void declare(nT &&a_name, aT a_type);
51 void set_default_allocator(allocator alloc)
52 { this->default_allocator = alloc; }
79 unsigned int size() const noexcept
80 {
return m_arrays.size(); }
84 {
return m_arrays[i]; }
88 {
return m_arrays[i]; }
91 template <
typename array_t>
92 std::shared_ptr<array_t>
get_as(
unsigned int i)
93 {
return std::dynamic_pointer_cast<array_t>(m_arrays[i]); }
96 template <
typename array_t>
97 std::shared_ptr<const array_t>
get_as(
unsigned int i)
const
98 {
return std::dynamic_pointer_cast<const array_t>(m_arrays[i]); }
101 bool has(
const std::string &name)
const;
104 template <
typename array_t>
105 std::shared_ptr<array_t>
get_as(
const std::string &name)
106 {
return std::dynamic_pointer_cast<array_t>(this->get(name)); }
109 template <
typename array_t>
110 std::shared_ptr<const array_t>
get_as(
const std::string &name)
const
111 {
return std::dynamic_pointer_cast<const array_t>(this->get(name)); }
121 {
return this->get(name); }
125 {
return this->get(name); }
128 std::string &get_name(
unsigned int i)
129 {
return m_names[i]; }
132 const std::string &get_name(
unsigned int i)
const
133 {
return m_names[i]; }
136 std::vector<std::string> &get_names()
140 const std::vector<std::string> &get_names()
const
145 {
return "teca_array_collection"; }
151 void copy(
const const_p_teca_dataset &other,
152 allocator alloc = allocator::malloc)
override;
158 int append(
const const_p_teca_array_collection &other);
164 void swap(
const p_teca_dataset &other)
override;
192 using name_vector_t = std::vector<std::string>;
193 using array_vector_t = std::vector<p_teca_variant_array>;
194 using name_array_map_t = std::map<std::string,unsigned int>;
196 name_vector_t m_names;
197 array_vector_t m_arrays;
198 name_array_map_t m_name_array_map;
199 allocator default_allocator;
203 template<
typename nT,
typename aT,
typename... oT>
206 this->
declare(std::forward<nT>(a_name), a_type);
211 template<
typename nT,
typename aT>
214 unsigned int id = m_arrays.size();
215 m_names.push_back(a_name);
217 m_name_array_map.emplace(std::forward<nT>(a_name),
id);
A collection of named arrays.
Definition: teca_array_collection.h:21
std::shared_ptr< array_t > get_as(unsigned int i)
access a typed array by id
Definition: teca_array_collection.h:92
void shallow_copy(const p_teca_dataset &other) override
int remove(unsigned int i)
remove the ith array
void swap(const p_teca_dataset &other) override
swap
std::shared_ptr< const array_t > get_as(unsigned int i) const
access a typed array by id
Definition: teca_array_collection.h:97
p_teca_variant_array operator[](const std::string &name)
access an array by name
Definition: teca_array_collection.h:120
int set(const std::string &name, p_teca_variant_array array)
add or replace the named array, returns 0 on success.
void declare_set(nT &&a_name, aT a_type, oT &&...args)
Definition: teca_array_collection.h:204
void declare(nT &&a_name, aT a_type)
declare a single array
Definition: teca_array_collection.h:212
int to_stream(std::ostream &) const override
stream to a human readable representation
unsigned int size() const noexcept
Return the number of arrays.
Definition: teca_array_collection.h:79
const_p_teca_variant_array operator[](const std::string &name) const
access an array by name
Definition: teca_array_collection.h:124
std::string get_class_name() const override
Return the name of the class.
Definition: teca_array_collection.h:144
std::shared_ptr< array_t > get_as(const std::string &name)
access a typed array by name
Definition: teca_array_collection.h:105
int get_type_code() const override
return an integer identifier uniquely naming the dataset type
const_p_teca_variant_array get(unsigned int i) const
access an array by its id
Definition: teca_array_collection.h:87
p_teca_variant_array get(unsigned int i)
access an array by its id
Definition: teca_array_collection.h:83
int to_stream(teca_binary_stream &s) const override
serialize the data to the given stream for I/O or communication
bool has(const std::string &name) const
test for array
int append(const std::string &name, p_teca_variant_array array)
const_p_teca_variant_array get(const std::string &name) const
access an array by name
int shallow_append(const p_teca_array_collection &other)
shallow append
int append(const const_p_teca_array_collection &other)
append
int remove(const std::string &name)
remove the named array
int append(p_teca_variant_array array)
void copy(const const_p_teca_dataset &other, allocator alloc=allocator::malloc) override
std::shared_ptr< const array_t > get_as(const std::string &name) const
access a typed array by name
Definition: teca_array_collection.h:110
p_teca_variant_array get(const std::string &name)
access an array by name
int set(unsigned int i, p_teca_variant_array array)
int from_stream(teca_binary_stream &s) override
serialize the data from the given stream for I/O or communication
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:17
Interface for TECA datasets.
Definition: teca_dataset.h:232
virtual int from_stream(teca_binary_stream &)
deserialize the dataset from the given stream for I/O or communication
The concrete implementation of our type agnostic container for contiguous arrays.
Definition: teca_variant_array_impl.h:380
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27