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()
34 TECA_DATASET_METADATA(calendar, std::
string, 1)
35 TECA_DATASET_METADATA(time_units, std::
string, 1)
53 template<typename nT, typename cT, typename... oT>
54 void declare_columns(nT &&col_name, cT col_type, oT &&...args);
57 template<typename nT, typename cT>
58 void declare_column(nT &&col_name, cT col_type);
61 void set_default_allocator(allocator alloc)
68 unsigned long get_number_of_rows() const noexcept;
83 template <typename array_t>
84 std::shared_ptr<array_t> get_column_as(
unsigned int i)
86 return std::dynamic_pointer_cast<array_t>(this->get_column(i));
90 template <
typename array_t>
93 return std::dynamic_pointer_cast<array_t>(this->get_column(col_name));
97 template <
typename array_t>
100 return std::dynamic_pointer_cast<const array_t>(this->get_column(i));
104 template <
typename array_t>
105 std::shared_ptr<const array_t>
get_column_as(
const std::string &col_name)
const
107 return std::dynamic_pointer_cast<const array_t>(this->get_column(col_name));
112 {
return m_impl->columns->has(col_name); }
116 {
return m_impl->columns->get_name(i); }
120 {
return m_impl->columns->append(array); }
124 {
return m_impl->columns->append(name, array); }
128 {
return m_impl->columns->remove(i); }
132 {
return m_impl->columns->remove(name); }
136 {
return m_impl->columns; }
140 {
return m_impl->columns; }
151 template<
typename cT,
typename... oT>
152 void append(cT &&val, oT &&... args);
156 {
return "teca_table"; }
162 explicit operator bool() const noexcept
163 {
return !this->empty(); }
166 bool empty() const noexcept override;
175 int to_stream(std::ostream &) const override;
178 int from_stream(std::istream &) override;
181 void copy(const const_p_teca_dataset &other,
182 allocator alloc = allocator::malloc) override;
185 void copy(const const_p_teca_table &other,
186 unsigned long first_row,
unsigned long last_row,
187 allocator alloc = allocator::malloc);
190 void shallow_copy(const p_teca_dataset &other) override;
193 void copy_structure(const const_p_teca_table &other);
196 void swap(const p_teca_dataset &other) override;
199 void concatenate_rows(const const_p_teca_table &other);
205 void concatenate_cols(const const_p_teca_table &other,
bool deep=false);
220 void declare_columns(){}
228 p_teca_array_collection columns;
229 unsigned int active_column;
231 std::shared_ptr<impl_t> m_impl;
242 return m_impl->columns->get(i);
249 return m_impl->columns->get(i);
253 template<
typename nT,
typename cT,
typename... oT>
256 m_impl->columns->declare(std::forward<nT>(col_name), col_type);
261 template<
typename nT,
typename cT>
264 m_impl->columns->declare(std::forward<nT>(col_name), col_type);
268 template<
typename cT,
typename... oT>
272 m_impl->columns->get(col)->append(std::forward<cT>(val));
277 p_teca_table &
operator<<(p_teca_table &t, T &&v)
279 t->append(std::forward<T>(v));
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:17
Interface for TECA datasets.
Definition: teca_dataset.h:232
A collection of columnar data with row based accessors and communication and I/O support.
Definition: teca_table.h:21
int get_type_code() const override
return an integer identifier uniquely naming the dataset type
void resize(unsigned long n)
resize the table to hold n rows of data, new rows are default initialized
const_p_teca_array_collection get_columns() const
get the container holding the columns
Definition: teca_table.h:139
bool empty() const noexcept override
return true if the dataset is empty.
void reserve(unsigned long n)
reserve memory for n rows of data without changing the tables size
std::shared_ptr< const array_t > get_column_as(unsigned int i) const
get a specific column. return a nullptr if the column doesn't exist.
Definition: teca_table.h:98
void append(cT &&val, oT &&... args)
Definition: teca_table.h:269
int remove_column(unsigned int i)
remove a column
Definition: teca_table.h:127
p_teca_array_collection get_columns()
get the container holding the columns
Definition: teca_table.h:135
int remove_column(const std::string &name)
remove a column
Definition: teca_table.h:131
void set_default_allocator(allocator alloc)
set the allocator to use with ::declare_column
Definition: teca_table.h:61
std::shared_ptr< const array_t > get_column_as(const std::string &col_name) const
get a specific column. return a nullptr if the column doesn't exist.
Definition: teca_table.h:105
unsigned int get_number_of_columns() const noexcept
get the number of columns
void declare_column(nT &&col_name, cT col_type)
Adds a column definition to the table.
Definition: teca_table.h:262
std::string get_column_name(unsigned int i) const
get the name of column i, see also get_number_of_columns
Definition: teca_table.h:115
int append_column(const std::string &name, p_teca_variant_array array)
add a column to the table
Definition: teca_table.h:123
void declare_columns(nT &&col_name, cT col_type, oT &&...args)
Definition: teca_table.h:254
p_teca_variant_array get_column(unsigned int i)
get a specific column. return a nullptr if the column doesn't exist.
Definition: teca_table.h:240
int append_column(p_teca_variant_array array)
add a column to the table
Definition: teca_table.h:119
std::shared_ptr< array_t > get_column_as(const std::string &col_name)
get a specific column. return a nullptr if the column doesn't exist.
Definition: teca_table.h:91
bool has_column(const std::string &col_name) const
test for the existence of a specific column
Definition: teca_table.h:111
std::string get_class_name() const override
return a unique string identifier
Definition: teca_table.h:155
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
TECA_EXPORT bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:290
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
TECA_EXPORT std::ostream & operator<<(std::ostream &os, const teca_calendar_util::time_point &tpt)
send the time_point to a stream in humnan readable form
std::shared_ptr< teca_variant_array > p_teca_variant_array
Definition: teca_variant_array.h:27
std::shared_ptr< const teca_variant_array > const_p_teca_variant_array
Definition: teca_variant_array.h:27