|
TECA
The Toolkit for Extreme Climate Analysis
|
1 #ifndef teca_array_collection_h
2 #define teca_array_collection_h
4 #include "teca_dataset.h"
23 TECA_DATASET_NEW_INSTANCE()
24 TECA_DATASET_NEW_COPY()
27 TECA_DATASET_METADATA(time,
double, 1)
28 TECA_DATASET_METADATA(calendar, std::string, 1)
29 TECA_DATASET_METADATA(time_units, std::string, 1)
30 TECA_DATASET_METADATA(time_step,
unsigned long, 1)
42 template<
typename nT,
typename aT,
typename... oT>
43 void declare_set(nT &&a_name, aT a_type, oT &&...args);
46 template<
typename nT,
typename aT>
47 void declare(nT &&a_name, aT a_type);
68 int remove(
unsigned int i);
71 int remove(
const std::string &name);
74 unsigned int size() const noexcept
75 {
return m_arrays.size(); }
79 {
return m_arrays[i]; }
83 {
return m_arrays[i]; }
86 bool has(
const std::string &name)
const;
96 {
return this->get(name); }
100 {
return this->get(name); }
103 std::string &get_name(
unsigned int i)
104 {
return m_names[i]; }
107 const std::string &get_name(
unsigned int i)
const
108 {
return m_names[i]; }
111 std::vector<std::string> &get_names()
115 const std::vector<std::string> &get_names()
const
120 {
return "teca_array_collection"; }
123 int get_type_code()
const override;
126 void copy(
const const_p_teca_dataset &other)
override;
129 void shallow_copy(
const p_teca_dataset &other)
override;
132 int append(
const const_p_teca_array_collection &other);
135 int shallow_append(
const p_teca_array_collection &other);
138 void swap(
const p_teca_dataset &other)
override;
147 int to_stream(std::ostream &)
const override;
158 using name_vector_t = std::vector<std::string>;
159 using array_vector_t = std::vector<p_teca_variant_array>;
160 using name_array_map_t = std::map<std::string,unsigned int>;
162 name_vector_t m_names;
163 array_vector_t m_arrays;
164 name_array_map_t m_name_array_map;
168 template<
typename nT,
typename aT,
typename... oT>
171 this->
declare(std::forward<nT>(a_name), a_type);
176 template<
typename nT,
typename aT>
179 unsigned int id = m_arrays.size();
180 m_names.emplace_back(std::forward<nT>(a_name));
182 m_name_array_map.emplace(std::forward<nT>(a_name),
id);
p_teca_variant_array get(unsigned int i)
access an array by its by id
Definition: teca_array_collection.h:78
void declare_set(nT &&a_name, aT a_type, oT &&...args)
Definition: teca_array_collection.h:169
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:15
The concrete implementation of our type agnostic container for contiguous arrays.
Definition: teca_variant_array.h:23
const_p_teca_variant_array get(unsigned int i) const
access an array by its by id
Definition: teca_array_collection.h:82
Interface for TECA datasets.
Definition: teca_dataset.h:216
std::string get_class_name() const override
Return the name of the class.
Definition: teca_array_collection.h:119
p_teca_variant_array operator[](const std::string &name)
access an array by name
Definition: teca_array_collection.h:95
A collection of named arrays.
Definition: teca_array_collection.h:19
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:22
void declare(nT &&a_name, aT a_type)
declare a single array
Definition: teca_array_collection.h:177
unsigned int size() const noexcept
Return the number of arrays.
Definition: teca_array_collection.h:74
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:22
bool set(teca_variant_array *varr, unsigned long i, PyObject *obj)
Set i'th element of the variant array to the value of the object.
Definition: teca_py_array.h:284
bool append(teca_variant_array *varr, PyObject *obj)
Append values from the object to the variant array.
Definition: teca_py_array.h:213
const_p_teca_variant_array operator[](const std::string &name) const
access an array by name
Definition: teca_array_collection.h:99
bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:270