TECA
teca_cf_time_axis_data.h
1 #ifndef teca_cf_time_axis_data_h
2 #define teca_cf_time_axis_data_h
3 
4 #include "teca_dataset.h"
5 #include "teca_variant_array.h"
6 #include "teca_metadata.h"
7 
8 #include <map>
9 #include <vector>
10 #include <string>
11 
12 #include "teca_shared_object.h"
13 TECA_SHARED_OBJECT_FORWARD_DECL(teca_cf_time_axis_data)
14 
15 
19 {
20 public:
21  TECA_DATASET_STATIC_NEW(teca_cf_time_axis_data)
22  TECA_DATASET_NEW_INSTANCE()
23  TECA_DATASET_NEW_COPY()
24 
25  ~teca_cf_time_axis_data() override;
26 
27  using elem_t = std::pair<p_teca_variant_array, teca_metadata>;
28 
29  // transfer the element associated with file to the dataset.
30  // after transfer the passed element is invalid in the calling context
31  void transfer(unsigned long file_id, elem_t &&data);
32 
33  // access the file's element
34  elem_t &get(unsigned long file_id);
35  const elem_t &get(unsigned long file_id) const;
36 
37  // given an element extract metadata
38  static
39  teca_metadata &get_metadata(elem_t&elem)
40  { return elem.second; }
41 
42  static
43  const teca_metadata &get_metadata(const elem_t &elem)
44  { return elem.second; }
45 
46  // given an element extract the time axis
47  static
48  p_teca_variant_array get_variant_array(elem_t &elem)
49  { return elem.first; }
50 
51  static
52  const_p_teca_variant_array get_variant_array(const elem_t &elem)
53  { return elem.first; }
54 
55  // append the data from the other instance
56  void append(const const_p_teca_dataset &other);
57  void shallow_append(const const_p_teca_dataset &other);
58 
59  // return a unique string identifier
60  std::string get_class_name() const override
61  { return "teca_cf_time_axis_data"; }
62 
63  // return an integer identifier uniquely naming the dataset type
64  int get_type_code() const override;
65 
66  // covert to bool. true if the dataset is not empty.
67  // otherwise false.
68  explicit operator bool() const noexcept
69  { return !this->empty(); }
70 
71  // return true if the dataset is empty.
72  bool empty() const noexcept override;
73 
74  // serialize the dataset to/from the given stream
75  // for I/O or communication
76  int to_stream(teca_binary_stream &) const override;
77  int from_stream(teca_binary_stream &) override;
78 
79  // stream to/from human readable representation
80  int to_stream(std::ostream &) const override;
81  int from_stream(std::istream &) override;
82 
83  // copy data and metadata. shallow copy uses reference
84  // counting, while copy duplicates the data.
85  void copy(const const_p_teca_dataset &other) override;
86 
87  // deep copy a subset of row values.
88  void copy(const const_p_teca_cf_time_axis_data &other,
89  unsigned long first_row, unsigned long last_row);
90 
91  void shallow_copy(const p_teca_dataset &other) override;
92 
93  // swap internals of the two objects
94  void swap(p_teca_dataset &other) override;
95 
96 protected:
98 
99  teca_cf_time_axis_data(const teca_cf_time_axis_data &other) = delete;
101  teca_cf_time_axis_data &operator=(const teca_cf_time_axis_data &other) = delete;
102 
103 private:
104  using internals_t = std::map<unsigned long, elem_t>;
105  internals_t *internals;
106 };
107 
108 #endif
teca_binary_stream
Definition: teca_binary_stream.h:16
teca_metadata
Definition: teca_metadata.h:17
teca_dataset
Definition: teca_dataset.h:14
teca_cf_time_axis_data
Definition: teca_cf_time_axis_data.h:19