TECA
teca_programmable_algorithm.h
1 #ifndef teca_programmable_algorithm_h
2 #define teca_programmable_algorithm_h
3 
4 #include "teca_algorithm.h"
5 #include "teca_metadata.h"
6 #include "teca_dataset_fwd.h"
7 #include "teca_programmable_algorithm_fwd.h"
8 
10 
57 {
58 public:
59  TECA_ALGORITHM_STATIC_NEW(teca_programmable_algorithm)
60  TECA_ALGORITHM_DELETE_COPY_ASSIGN(teca_programmable_algorithm)
62 
63  // set/get the class name.
64  virtual int set_name(const std::string &name);
65 
66  const char *get_class_name() const override
67  { return this->class_name; }
68 
69  // set the number of input and outputs
70  using teca_algorithm::set_number_of_input_connections;
71  using teca_algorithm::set_number_of_output_ports;
72 
73  // install the default implementation
74  void use_default_report_action();
75  void use_default_request_action();
76  void use_default_execute_action();
77 
78  // set callback that responds to reporting stage
79  // of pipeline execution. the report callback must
80  // be callable with signature:
81  //
82  // teca_metadata (unsigned int,
83  // const std::vector<teca_metadata> &)
84  //
85  // the default implementation forwards downstream
86  TECA_ALGORITHM_CALLBACK_PROPERTY(
87  report_callback_t, report_callback)
88 
89  // set the callback that responds to the requesting
90  // stage of pipeline execution. the request callback
91  // must be callable with the signature:
92  //
93  // std::vector<teca_metadata> (
94  // unsigned int,
95  // const std::vector<teca_metadata> &,
96  // const teca_metadata &)
97  //
98  // the default implementation forwards upstream
99  TECA_ALGORITHM_CALLBACK_PROPERTY(
100  request_callback_t, request_callback)
101 
102  // set the callback that responds to the execution stage
103  // of pipeline execution. the execute callback must be
104  // callable with the signature:
105  //
106  // const_p_teca_dataset (
107  // unsigned int, const std::vector<const_p_teca_dataset> &,
108  // const teca_metadata &)
109  //
110  // the default implementation returns a nullptr
111  TECA_ALGORITHM_CALLBACK_PROPERTY(
112  execute_callback_t, execute_callback)
113 
114 protected:
116 
117 private:
118  teca_metadata get_output_metadata(
119  unsigned int port,
120  const std::vector<teca_metadata> &input_md) override;
121 
122  std::vector<teca_metadata> get_upstream_request(
123  unsigned int port,
124  const std::vector<teca_metadata> &input_md,
125  const teca_metadata &request) override;
126 
127  const_p_teca_dataset execute(
128  unsigned int port,
129  const std::vector<const_p_teca_dataset> &input_data,
130  const teca_metadata &request) override;
131 
132 protected:
133  report_callback_t report_callback;
134  request_callback_t request_callback;
135  execute_callback_t execute_callback;
136  char class_name[64];
137 };
138 
139 #endif
teca_metadata
Definition: teca_metadata.h:17
teca_programmable_algorithm
an algorithm implemented with user provided callbacks
Definition: teca_programmable_algorithm.h:57
teca_algorithm
Definition: teca_algorithm.h:25