4 #include "teca_config.h"
5 #include "teca_dataset.h"
7 #include "teca_array_collection.h"
24 TECA_DATASET_NEW_INSTANCE()
25 TECA_DATASET_NEW_COPY()
30 TECA_DATASET_METADATA(calendar, std::
string, 1)
31 TECA_DATASET_METADATA(time_units, std::
string, 1)
40 template<typename nT, typename cT, typename... oT>
41 void declare_columns(nT &&col_name, cT col_type, oT &&...args);
44 template<typename nT, typename cT>
45 void declare_column(nT &&col_name, cT col_type);
48 void set_default_allocator(allocator alloc)
52 unsigned int get_number_of_columns() const noexcept;
53 unsigned long get_number_of_rows() const noexcept;
64 bool has_column(const std::
string &col_name)
const
65 {
return m_impl->columns->has(col_name); }
68 std::string get_column_name(
unsigned int i)
const
69 {
return m_impl->columns->get_name(i); }
73 {
return m_impl->columns->append(array); }
76 {
return m_impl->columns->append(name, array); }
79 int remove_column(
unsigned int i)
80 {
return m_impl->columns->remove(i); }
82 int remove_column(
const std::string &name)
83 {
return m_impl->columns->remove(name); }
86 p_teca_array_collection get_columns()
87 {
return m_impl->columns; }
89 const_p_teca_array_collection get_columns()
const
90 {
return m_impl->columns; }
93 void resize(
unsigned long n);
96 void reserve(
unsigned long n);
101 template<
typename cT,
typename... oT>
102 void append(cT &&val, oT &&... args);
105 std::string get_class_name()
const override
106 {
return "teca_table"; }
109 int get_type_code()
const override;
113 explicit operator bool() const noexcept
114 {
return !this->empty(); }
117 bool empty() const noexcept override;
125 int to_stream(std::ostream &) const override;
126 int from_stream(std::istream &) override;
129 void copy(const const_p_teca_dataset &other,
130 allocator alloc = allocator::malloc) override;
133 void copy(const const_p_teca_table &other,
134 unsigned long first_row,
unsigned long last_row,
135 allocator alloc = allocator::malloc);
138 void shallow_copy(const p_teca_dataset &other) override;
141 void copy_structure(const const_p_teca_table &other);
144 void swap(const p_teca_dataset &other) override;
148 void concatenate_rows(const const_p_teca_table &other);
153 void concatenate_cols(const const_p_teca_table &other,
bool deep=false);
168 void declare_columns(){}
176 p_teca_array_collection columns;
177 unsigned int active_column;
179 std::shared_ptr<impl_t> m_impl;
190 return m_impl->columns->get(i);
197 return m_impl->columns->get(i);
201 template<
typename nT,
typename cT,
typename... oT>
202 void teca_table::declare_columns(nT &&col_name, cT col_type, oT &&... args)
204 m_impl->columns->declare(std::forward<nT>(col_name), col_type);
205 this->declare_columns(args...);
209 template<
typename nT,
typename cT>
210 void teca_table::declare_column(nT &&col_name, cT col_type)
212 m_impl->columns->declare(std::forward<nT>(col_name), col_type);
216 template<
typename cT,
typename... oT>
217 void teca_table::append(cT &&val, oT &&... args)
219 unsigned int col = m_impl->active_column++%this->get_number_of_columns();
220 m_impl->columns->get(col)->append(std::forward<cT>(val));
221 this->append(args...);
225 p_teca_table &
operator<<(p_teca_table &t, T &&v)
227 t->append(std::forward<T>(v));