TECA
The Toolkit for Extreme Climate Analysis
teca_database.h
1 #ifndef teca_database_h
2 #define teca_database_h
3 
4 #include "teca_dataset.h"
5 #include "teca_table.h"
6 #include "teca_shared_object.h"
7 #include "teca_table_collection.h"
8 #include <iosfwd>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_database)
12 
13 /// A collection of named tables.
14 /**
15  * A dataset consisting of a collection of named tables. This
16  * is a thin wrapper around the teca_table_collection implementing
17  * the teca_dataset API.
18  */
20 {
21 public:
22  TECA_DATASET_STATIC_NEW(teca_database)
23  TECA_DATASET_NEW_INSTANCE()
24  TECA_DATASET_NEW_COPY()
25 
26  ~teca_database();
27 
28  // append table
29  int append_table(p_teca_table table)
30  { return this->tables->append(table); }
31 
32  int append_table(const std::string &name, p_teca_table table)
33  { return this->tables->append(name, table); }
34 
35  // declare a table
36  void declare_table(const std::string &name)
37  { this->tables->declare(name); }
38 
39  // declare a set of unnamed tables
40  void declare_tables(unsigned int n);
41 
42  // get the number of tables
43  unsigned int get_number_of_tables() const
44  { return this->tables->size(); }
45 
46  // get the ith table
47  p_teca_table get_table(unsigned int i)
48  { return this->tables->get(i); }
49 
50  const_p_teca_table get_table(unsigned int i) const
51  { return this->tables->get(i); }
52 
53  // get table by its name
54  p_teca_table get_table(const std::string &name)
55  { return this->tables->get(name); }
56 
57  const_p_teca_table get_table(const std::string &name) const
58  { return this->tables->get(name); }
59 
60  // get the name of the ith table
61  std::string get_table_name(unsigned int i)
62  { return this->tables->get_name(i); }
63 
64  const std::string &get_table_name(unsigned int i) const
65  { return this->tables->get_name(i); }
66 
67  // set the table by name or index
68  int set_table(const std::string &name, p_teca_table table)
69  { return this->tables->set(name, table); }
70 
71  int set_table(unsigned int i, p_teca_table table)
72  { return this->tables->set(i, table); }
73 
74  // remove the table
75  int remove_table(unsigned int i)
76  { return this->tables->remove(i); }
77 
78  int remove_table(const std::string &name)
79  { return this->tables->remove(name); }
80 
81  // return a unique string identifier
82  std::string get_class_name() const override
83  { return "teca_database"; }
84 
85  // return an integer identifier uniquely naming the dataset type
86  int get_type_code() const override;
87 
88  // return true if the dataset is empty.
89  bool empty() const noexcept override;
90 
91  // copy data and metadata. shallow copy uses reference
92  // counting, while copy duplicates the data.
93  void copy(const const_p_teca_dataset &other) override;
94  void shallow_copy(const p_teca_dataset &other) override;
95 
96  // copy metadata. always a deep copy.
97  void copy_metadata(const const_p_teca_dataset &other) override;
98 
99  // swap internals of the two objects
100  void swap(const p_teca_dataset &other) override;
101 
102  // serialize the dataset to/from the given stream
103  // for I/O or communication
104  int to_stream(teca_binary_stream &) const override;
105  int from_stream(teca_binary_stream &) override;
106 
107  // stream to/from human readable representation
108  int to_stream(std::ostream &) const override;
109  int from_stream(std::istream &) override { return -1; }
110 
111 protected:
112  teca_database();
113 
114 private:
115  p_teca_table_collection tables;
116 };
117 
118 #endif
teca_binary_stream
Serialize objects into a binary stream.
Definition: teca_binary_stream.h:15
teca_dataset
Interface for TECA datasets.
Definition: teca_dataset.h:216
teca_database
A collection of named tables.
Definition: teca_database.h:19
teca_shared_object.h
teca_py_array::copy
bool copy(teca_variant_array *varr, PyObject *obj)
Copy values from the object into variant array.
Definition: teca_py_array.h:270