HOPS
HOPS class reference
MHO_UnaryOperator.hh
Go to the documentation of this file.
1 #ifndef MHO_UnaryOperator_HH__
2 #define MHO_UnaryOperator_HH__
3 
4 #include "MHO_Operator.hh"
5 
6 #include <tuple>
7 
8 namespace hops
9 {
10 
19 //
23 template< class XArgType > class MHO_UnaryOperator: public MHO_Operator
24 {
25  public:
27  {
28  fInPlace = false;
29  std::get< 0 >(fInPlaceArgs) = nullptr;
30  std::get< 0 >(fOutOfPlaceArgs) = nullptr;
31  std::get< 1 >(fOutOfPlaceArgs) = nullptr;
32  };
33 
34  virtual ~MHO_UnaryOperator(){};
35 
42  virtual void SetArgs(XArgType* in)
43  {
44  fInPlace = true;
45  fInPlaceArgs = std::make_tuple(in);
46  }
47 
48  //out-of-place operation, result stored in out, input unmodified
56  virtual void SetArgs(const XArgType* in, XArgType* out)
57  {
58  fInPlace = false;
59  fOutOfPlaceArgs = std::make_tuple(in, out);
60  };
61 
68  virtual bool Initialize() override
69  {
70  if(fInPlace)
71  {
72  return InitializeInPlace(std::get< 0 >(fInPlaceArgs));
73  }
74  else
75  {
76  return InitializeOutOfPlace(std::get< 0 >(fOutOfPlaceArgs), std::get< 1 >(fOutOfPlaceArgs));
77  }
78  }
79 
86  virtual bool Execute() override
87  {
88  if(fInPlace)
89  {
90  return ExecuteInPlace(std::get< 0 >(fInPlaceArgs));
91  }
92  else
93  {
94  return ExecuteOutOfPlace(std::get< 0 >(fOutOfPlaceArgs), std::get< 1 >(fOutOfPlaceArgs));
95  }
96  }
97 
98  protected:
106  virtual bool InitializeInPlace(XArgType* in) = 0;
115  virtual bool InitializeOutOfPlace(const XArgType* in, XArgType* out) = 0;
116 
124  virtual bool ExecuteInPlace(XArgType* in) = 0;
133  virtual bool ExecuteOutOfPlace(const XArgType* in, XArgType* out) = 0;
134 
135  //place for args to be stored for derived class to pick them up/modify
136  bool fInPlace;
137  std::tuple< XArgType* > fInPlaceArgs;
138  std::tuple< const XArgType*, XArgType* > fOutOfPlaceArgs;
139 };
140 
141 } // namespace hops
142 
143 #endif
Class MHO_Operator.
Definition: MHO_Operator.hh:21
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
virtual bool InitializeInPlace(XArgType *in)=0
Function InitializeInPlace.
virtual bool ExecuteInPlace(XArgType *in)=0
Function ExecuteInPlace.
virtual void SetArgs(XArgType *in)
Setter for args.
Definition: MHO_UnaryOperator.hh:42
std::tuple< const XArgType *, XArgType * > fOutOfPlaceArgs
Definition: MHO_UnaryOperator.hh:138
virtual bool ExecuteOutOfPlace(const XArgType *in, XArgType *out)=0
Function ExecuteOutOfPlace.
MHO_UnaryOperator()
Definition: MHO_UnaryOperator.hh:26
virtual ~MHO_UnaryOperator()
Definition: MHO_UnaryOperator.hh:34
virtual void SetArgs(const XArgType *in, XArgType *out)
Setter for args.
Definition: MHO_UnaryOperator.hh:56
virtual bool Execute() override
Executes operation using provided arguments and return type.
Definition: MHO_UnaryOperator.hh:86
virtual bool InitializeOutOfPlace(const XArgType *in, XArgType *out)=0
Function InitializeOutOfPlace.
virtual bool Initialize() override
Initializes the system using in-place or out-of-place arguments.
Definition: MHO_UnaryOperator.hh:68
std::tuple< XArgType * > fInPlaceArgs
Definition: MHO_UnaryOperator.hh:137
bool fInPlace
Definition: MHO_UnaryOperator.hh:136
Definition: MHO_ChannelLabeler.hh:17