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