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