4 #include "teca_dataset.h"
5 #include "teca_variant_array.h"
6 #include "teca_array_collection.h"
7 #include "teca_shared_object.h"
23 TECA_DATASET_NEW_INSTANCE()
24 TECA_DATASET_NEW_COPY()
29 TECA_DATASET_METADATA(calendar, std::string, 1)
30 TECA_DATASET_METADATA(time_units, std::string, 1)
39 template<
typename nT,
typename cT,
typename... oT>
40 void declare_columns(nT &&col_name, cT col_type, oT &&...args);
43 template<
typename nT,
typename cT>
44 void declare_column(nT &&col_name, cT col_type);
47 unsigned int get_number_of_columns()
const noexcept;
48 unsigned long get_number_of_rows()
const noexcept;
52 p_teca_variant_array get_column(
unsigned int i);
53 p_teca_variant_array get_column(
const std::string &col_name);
55 const_p_teca_variant_array get_column(
unsigned int i)
const;
56 const_p_teca_variant_array get_column(
const std::string &col_name)
const;
59 bool has_column(
const std::string &col_name)
const
60 {
return m_impl->columns->has(col_name); }
63 std::string get_column_name(
unsigned int i)
const
64 {
return m_impl->columns->get_name(i); }
67 int append_column(p_teca_variant_array array)
68 {
return m_impl->columns->append(array); }
70 int append_column(
const std::string &name, p_teca_variant_array array)
71 {
return m_impl->columns->append(name, array); }
74 int remove_column(
unsigned int i)
75 {
return m_impl->columns->remove(i); }
77 int remove_column(
const std::string &name)
78 {
return m_impl->columns->remove(name); }
81 p_teca_array_collection get_columns()
82 {
return m_impl->columns; }
84 const_p_teca_array_collection get_columns()
const
85 {
return m_impl->columns; }
88 void resize(
unsigned long n);
91 void reserve(
unsigned long n);
96 template<
typename cT,
typename... oT>
97 void append(cT &&val, oT &&... args);
100 std::string get_class_name()
const override
101 {
return "teca_table"; }
104 int get_type_code()
const override;
108 explicit operator bool()
const noexcept
109 {
return !this->empty(); }
112 bool empty()
const noexcept
override;
120 int to_stream(std::ostream &)
const override;
121 int from_stream(std::istream &)
override;
125 void copy(
const const_p_teca_dataset &other)
override;
128 void copy(
const const_p_teca_table &other,
129 unsigned long first_row,
unsigned long last_row);
131 void shallow_copy(
const p_teca_dataset &other)
override;
134 void copy_structure(
const const_p_teca_table &other);
137 void swap(p_teca_dataset &other)
override;
141 void concatenate_rows(
const const_p_teca_table &other);
146 void concatenate_cols(
const const_p_teca_table &other,
bool deep=
false);
155 void declare_columns(){}
163 p_teca_array_collection columns;
164 unsigned int active_column;
166 std::shared_ptr<impl_t> m_impl;
175 p_teca_variant_array teca_table::get_column(
unsigned int i)
177 return m_impl->columns->get(i);
182 const_p_teca_variant_array teca_table::get_column(
unsigned int i)
const
184 return m_impl->columns->get(i);
188 template<
typename nT,
typename cT,
typename... oT>
189 void teca_table::declare_columns(nT &&col_name, cT col_type, oT &&... args)
191 m_impl->columns->declare(std::forward<nT>(col_name), col_type);
192 this->declare_columns(args...);
196 template<
typename nT,
typename cT>
197 void teca_table::declare_column(nT &&col_name, cT col_type)
199 m_impl->columns->declare(std::forward<nT>(col_name), col_type);
203 template<
typename cT,
typename... oT>
204 void teca_table::append(cT &&val, oT &&... args)
206 unsigned int col = m_impl->active_column++%this->get_number_of_columns();
207 m_impl->columns->get(col)->append(std::forward<cT>(val));
208 this->append(args...);
212 p_teca_table &operator<<(p_teca_table &t, T &&v)
214 t->append(std::forward<T>(v));