1 #ifndef teca_array_collection_h
2 #define teca_array_collection_h
4 #include "teca_array_collection_fwd.h"
5 #include "teca_variant_array.h"
19 p_teca_array_collection New()
29 template<
typename nT,
typename aT,
typename... oT>
30 void declare_set(nT &&a_name, aT a_type, oT &&...args);
33 template<
typename nT,
typename aT>
34 void declare(nT &&a_name, aT a_type);
38 int append(p_teca_variant_array array);
39 int append(
const std::string &name, p_teca_variant_array array);
43 int set(
unsigned int i, p_teca_variant_array array);
46 int set(
const std::string &name, p_teca_variant_array array);
49 int remove(
unsigned int i);
50 int remove(
const std::string &name);
53 unsigned int size()
const noexcept
54 {
return m_arrays.size(); }
57 p_teca_variant_array get(
unsigned int i)
58 {
return m_arrays[i]; }
60 const_p_teca_variant_array get(
unsigned int i)
const
61 {
return m_arrays[i]; }
64 bool has(
const std::string &name)
const;
67 p_teca_variant_array get(
const std::string &name);
68 const_p_teca_variant_array get(
const std::string &name)
const;
70 p_teca_variant_array operator[](
const std::string &name)
71 {
return this->get(name); }
73 const_p_teca_variant_array operator[](
const std::string &name)
const
74 {
return this->get(name); }
77 std::string &get_name(
unsigned int i)
78 {
return m_names[i]; }
80 const std::string &get_name(
unsigned int i)
const
81 {
return m_names[i]; }
84 std::string get_class_name()
const
85 {
return "teca_array_collection"; }
88 int get_type_code()
const
92 void copy(
const const_p_teca_array_collection &other);
93 void shallow_copy(
const p_teca_array_collection &other);
96 int append(
const const_p_teca_array_collection &other);
97 int shallow_append(
const p_teca_array_collection &other);
100 void swap(p_teca_array_collection &other);
108 int to_stream(std::ostream &)
const;
119 using name_vector_t = std::vector<std::string>;
120 using array_vector_t = std::vector<p_teca_variant_array>;
121 using name_array_map_t = std::map<std::string,unsigned int>;
123 name_vector_t m_names;
124 array_vector_t m_arrays;
125 name_array_map_t m_name_array_map;
129 template<
typename nT,
typename aT,
typename... oT>
130 void teca_array_collection::declare_set(nT &&a_name, aT a_type, oT &&... args)
132 this->declare(std::forward<nT>(a_name), a_type);
133 this->declare_set(args...);
137 template<
typename nT,
typename aT>
138 void teca_array_collection::declare(nT &&a_name, aT)
140 unsigned int id = m_arrays.size();
141 m_names.emplace_back(std::forward<nT>(a_name));
143 m_name_array_map.emplace(std::forward<nT>(a_name),
id);