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 
41  void SetArgs(XArgType* in)
42  {
43  fInPlace = true;
44  fInPlaceArgs = std::make_tuple(in);
45  }
46 
47  //out-of-place operation, result stored in out, input unmodified
54  void SetArgs(const XArgType* in, XArgType* out)
55  {
56  fInPlace = false;
57  fOutOfPlaceArgs = std::make_tuple(in, out);
58  };
59 
66  virtual bool Initialize() override
67  {
68  if(fInPlace)
69  {
70  return InitializeInPlace(std::get< 0 >(fInPlaceArgs));
71  }
72  else
73  {
74  return InitializeOutOfPlace(std::get< 0 >(fOutOfPlaceArgs), std::get< 1 >(fOutOfPlaceArgs));
75  }
76  }
77 
84  virtual bool Execute() override
85  {
86  if(fInPlace)
87  {
88  return ExecuteInPlace(std::get< 0 >(fInPlaceArgs));
89  }
90  else
91  {
92  return ExecuteOutOfPlace(std::get< 0 >(fOutOfPlaceArgs), std::get< 1 >(fOutOfPlaceArgs));
93  }
94  }
95 
96  protected:
97  virtual bool InitializeInPlace(XArgType* /*in*/) { return true; }
98 
99  virtual bool InitializeOutOfPlace(const XArgType* /*in*/, XArgType* /*out*/) { return true; }
100 
101  virtual bool ExecuteInPlace(XArgType* in) = 0;
102 
103  virtual bool ExecuteOutOfPlace(const XArgType* in, XArgType* out)
104  {
105  out->Copy(*in);
106  return ExecuteInPlace(out);
107  }
108 
109  //place for args to be stored for derived class to pick them up/modify
110  bool fInPlace;
111  std::tuple< XArgType* > fInPlaceArgs;
112  std::tuple< const XArgType*, XArgType* > fOutOfPlaceArgs;
113 };
114 
115 } // namespace hops
116 
117 #endif
Class MHO_Operator.
Definition: MHO_Operator.hh:21
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
void SetArgs(const XArgType *in, XArgType *out)
Setter for args.
Definition: MHO_UnaryOperator.hh:54
virtual bool ExecuteInPlace(XArgType *in)=0
std::tuple< const XArgType *, XArgType * > fOutOfPlaceArgs
Definition: MHO_UnaryOperator.hh:112
MHO_UnaryOperator()
Definition: MHO_UnaryOperator.hh:26
void SetArgs(XArgType *in)
Setter for args.
Definition: MHO_UnaryOperator.hh:41
virtual ~MHO_UnaryOperator()
Definition: MHO_UnaryOperator.hh:34
virtual bool Execute() override
Executes operation using provided arguments and return type.
Definition: MHO_UnaryOperator.hh:84
virtual bool InitializeOutOfPlace(const XArgType *, XArgType *)
Definition: MHO_UnaryOperator.hh:99
virtual bool Initialize() override
Initializes the system using in-place or out-of-place arguments.
Definition: MHO_UnaryOperator.hh:66
virtual bool InitializeInPlace(XArgType *)
Definition: MHO_UnaryOperator.hh:97
virtual bool ExecuteOutOfPlace(const XArgType *in, XArgType *out)
Definition: MHO_UnaryOperator.hh:103
std::tuple< XArgType * > fInPlaceArgs
Definition: MHO_UnaryOperator.hh:111
bool fInPlace
Definition: MHO_UnaryOperator.hh:110
Definition: MHO_AdhocFlagging.hh:18