TECA
teca_dataset.h
1 #ifndef teca_dataset_h
2 #define teca_dataset_h
3 
4 #include "teca_variant_array.h"
5 #include "teca_dataset_fwd.h"
6 #include <iosfwd>
8 class teca_metadata;
9 
13 class teca_dataset : public std::enable_shared_from_this<teca_dataset>
14 {
15 public:
16  virtual ~teca_dataset();
17 
18  // the name of the key that holds the index identifing this dataset
19  // this should be set by the algorithm that creates the dataset.
20  TECA_DATASET_METADATA(index_request_key, std::string, 1)
21 
22  // a dataset metadata that uses the value of index_request_key to
23  // store the index that identifies this dataset. this should be set
24  // by the algorithm that creates the dataset.
25  virtual int get_request_index(long &val) const;
26  virtual int set_request_index(const std::string &key, long val);
27  virtual int set_request_index(long val);
28 
29  // covert to bool. true if the dataset is not empty.
30  // otherwise false.
31  explicit operator bool() const noexcept
32  { return !this->empty(); }
33 
34  // return true if the dataset is empty.
35  virtual bool empty() const noexcept
36  { return true; }
37 
38  // virtual constructor. return a new dataset of the same type.
39  virtual p_teca_dataset new_instance() const = 0;
40 
41  // virtual copy constructor. return a shallow/deep copy of this
42  // dataset in a new instance.
43  virtual p_teca_dataset new_copy() const = 0;
44  virtual p_teca_dataset new_shallow_copy() = 0;
45 
46  // return a string identifier uniquely naming the dataset type
47  virtual std::string get_class_name() const = 0;
48 
49  // return an integer identifier uniquely naming the dataset type
50  virtual int get_type_code() const = 0;
51 
52  // copy data and metadata. shallow copy uses reference
53  // counting, while copy duplicates the data.
54  virtual void copy(const const_p_teca_dataset &other);
55  virtual void shallow_copy(const p_teca_dataset &other);
56 
57  // copy metadata. always a deep copy.
58  virtual void copy_metadata(const const_p_teca_dataset &other);
59 
60  // swap internals of the two objects
61  virtual void swap(p_teca_dataset &other);
62 
63  // access metadata
64  virtual teca_metadata &get_metadata() noexcept;
65  virtual const teca_metadata &get_metadata() const noexcept;
66  virtual void set_metadata(const teca_metadata &md);
67 
68  // serialize the dataset to/from the given stream
69  // for I/O or communication
70  virtual int to_stream(teca_binary_stream &) const;
71  virtual int from_stream(teca_binary_stream &);
72 
73  // stream to/from human readable representation
74  virtual int to_stream(std::ostream &) const;
75  virtual int from_stream(std::istream &);
76 
77 protected:
78  teca_dataset();
79 
80  teca_dataset(const teca_dataset &) = delete;
81  teca_dataset(const teca_dataset &&) = delete;
82 
83  void operator=(const p_teca_dataset &other) = delete;
84  void operator=(p_teca_dataset &&other) = delete;
85 
86  teca_metadata *metadata;
87 };
88 
89 #endif
teca_binary_stream
Definition: teca_binary_stream.h:16
teca_metadata
Definition: teca_metadata.h:17
teca_dataset
Definition: teca_dataset.h:14