|
TECA
The Toolkit for Extreme Climate Analysis
|
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; }
73 int remove(
unsigned int i);
76 int remove(
const std::string &name);
79 unsigned int size() const noexcept
80 {
return m_arrays.size(); }
84 {
return m_arrays[i]; }
88 {
return m_arrays[i]; }
91 bool has(
const std::string &name)
const;
101 {
return this->get(name); }
105 {
return this->get(name); }
108 std::string &get_name(
unsigned int i)
109 {
return m_names[i]; }
112 const std::string &get_name(
unsigned int i)
const
113 {
return m_names[i]; }
116 std::vector<std::string> &get_names()
120 const std::vector<std::string> &get_names()
const
125 {
return "teca_array_collection"; }
128 int get_type_code()
const override;
131 void copy(
const const_p_teca_dataset &other,
132 allocator alloc = allocator::malloc)
override;
135 void shallow_copy(
const p_teca_dataset &other)
override;
138 int append(
const const_p_teca_array_collection &other);
141 int shallow_append(
const p_teca_array_collection &other);
144 void swap(
const p_teca_dataset &other)
override;
153 int to_stream(std::ostream &)
const override;
154 using teca_dataset::from_stream;
172 using name_vector_t = std::vector<std::string>;
173 using array_vector_t = std::vector<p_teca_variant_array>;
174 using name_array_map_t = std::map<std::string,unsigned int>;
176 name_vector_t m_names;
177 array_vector_t m_arrays;
178 name_array_map_t m_name_array_map;
179 allocator default_allocator;
183 template<
typename nT,
typename aT,
typename... oT>
186 this->
declare(std::forward<nT>(a_name), a_type);
191 template<
typename nT,
typename aT>
194 unsigned int id = m_arrays.size();
195 m_names.emplace_back(std::forward<nT>(a_name));
197 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:83
void declare_set(nT &&a_name, aT a_type, oT &&...args)
Definition: teca_array_collection.h:184
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:16
The concrete implementation of our type agnostic container for contiguous arrays.
Definition: teca_variant_array_impl.h:39
const_p_teca_variant_array get(unsigned int i) const
access an array by its by id
Definition: teca_array_collection.h:87
Interface for TECA datasets.
Definition: teca_dataset.h:231
TECA_EXPORT 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:305
std::string get_class_name() const override
Return the name of the class.
Definition: teca_array_collection.h:124
p_teca_variant_array operator[](const std::string &name)
access an array by name
Definition: teca_array_collection.h:100
A collection of named arrays.
Definition: teca_array_collection.h:20
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27
void declare(nT &&a_name, aT a_type)
declare a single array
Definition: teca_array_collection.h:192
unsigned int size() const noexcept
Return the number of arrays.
Definition: teca_array_collection.h:79
TECA_EXPORT bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:290
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
TECA_EXPORT bool append(teca_variant_array *varr, PyObject *obj)
Append values from the object to the variant array.
Definition: teca_py_array.h:221
const_p_teca_variant_array operator[](const std::string &name) const
access an array by name
Definition: teca_array_collection.h:104