HOPS
HOPS class reference
MHO_AxisPack.hh
Go to the documentation of this file.
1 #ifndef MHO_AxisPack_HH__
2 #define MHO_AxisPack_HH__
3 
4 #include "MHO_Axis.hh"
5 #include "MHO_Meta.hh"
6 
7 namespace hops
8 {
9 
21 template< typename... XAxisTypeS > class MHO_AxisPack: public std::tuple< XAxisTypeS... >, virtual public MHO_Serializable
22 {
23  public:
24  MHO_AxisPack(): std::tuple< XAxisTypeS... >(){};
25 
26  MHO_AxisPack(const std::size_t* dim): std::tuple< XAxisTypeS... >() { resize_axis_pack(dim); };
27 
28  //copy constructor
29  MHO_AxisPack(const MHO_AxisPack& obj): std::tuple< XAxisTypeS... >(obj){};
30 
31  virtual ~MHO_AxisPack(){};
32 
33  //declare some convenience types
34  typedef std::integral_constant< std::size_t, sizeof...(XAxisTypeS) > NAXES;
35  typedef std::tuple< XAxisTypeS... > axis_pack_tuple_type;
36 
43  virtual uint64_t GetSerializedSize() const override
44  {
45  uint64_t total_size = 0;
46  total_size += sizeof(MHO_ClassVersion);
47  compute_total_size(total_size);
48  return total_size;
49  }
50 
51  virtual
52 
53  //assignment operator
55  operator=(const MHO_AxisPack& rhs)
56  {
57  this->copy(rhs);
58  return *this;
59  }
60 
61  protected:
68  template< std::size_t N = 0 >
69  typename std::enable_if< (N == sizeof...(XAxisTypeS)), void >::type
70  resize_axis_pack(const std::size_t* ){}; //terminating case, do nothing
71 
78  template< std::size_t N = 0 >
79  typename std::enable_if< (N < sizeof...(XAxisTypeS)), void >::type resize_axis_pack(const std::size_t* dim)
80  {
81  //resize the N-th element of the tuple
82  std::get< N >(*this).Resize(dim[N]);
83  //now run the induction
84  resize_axis_pack< N + 1 >(dim);
85  }
86 
87  // //inductive access to all elements of the tuple, so we compute total size for streaming
94  template< std::size_t N = 0 >
95  typename std::enable_if< (N == sizeof...(XAxisTypeS)), void >::type
96  compute_total_size(uint64_t& ) const {}; //terminating case, do nothing
97 
105  template< std::size_t N = 0 >
106  typename std::enable_if< (N < sizeof...(XAxisTypeS)), void >::type compute_total_size(uint64_t& total_size) const
107  {
108  total_size += std::get< N >(*this).GetSerializedSize();
109  //now run the induction
110  compute_total_size< N + 1 >(total_size);
111  }
112 
119  template< std::size_t N = 0 >
120  typename std::enable_if< (N == sizeof...(XAxisTypeS)), void >::type
121  copy(const MHO_AxisPack&) const {}; //terminating case, do nothing
122 
130  template< std::size_t N = 0 >
131  typename std::enable_if< (N < sizeof...(XAxisTypeS)), void >::type copy(const MHO_AxisPack& rhs)
132  {
133  std::get< N >(*this).Copy(std::get< N >(rhs));
134  copy< N + 1 >(rhs);
135  }
136 
137  public:
138  template< typename XStream > friend XStream& operator<<(XStream& s, const MHO_AxisPack& aData)
139  {
140  switch(aData.GetVersion())
141  {
142  case 0:
143  s << aData.GetVersion();
144  aData.StreamOutData_V0(s);
145  break;
146  default:
147  msg_error("containers",
148  "error, cannot stream out MHO_Axis object with unknown version: " << aData.GetVersion() << eom);
149  }
150  return s;
151  }
152 
153  template< typename XStream > friend XStream& operator>>(XStream& s, MHO_AxisPack& aData)
154  {
155  MHO_ClassVersion vers;
156  s >> vers;
157  switch(vers)
158  {
159  case 0:
160  aData.StreamInData_V0(s);
161  break;
162  default:
164  //Flag this as an unknown object version so we can skip over this data
166  }
167  return s;
168  }
169 
170  private:
177  template< typename XStream > void StreamInData_V0(XStream& s) { istream_tuple(s, *this); }
178 
186  template< typename XStream > void StreamOutData_V0(XStream& s) const { ostream_tuple(s, *this); }
187 
195  virtual MHO_UUID DetermineTypeUUID() const override
196  {
197  MHO_MD5HashGenerator gen;
198  gen.Initialize();
199  std::string name = MHO_ClassIdentity::ClassName(*this);
200  gen << name;
201  gen.Finalize();
202  return gen.GetDigestAsUUID();
203  }
204 };
205 
212 
213 //TODO FIXME -- find away to loop over macro arguments so we dont need so many
214 //boilerplate definitions
215 
216 using Int = int;
217 using Double = double;
218 using String = std::string;
219 
220 #define DefAxisPack1(TYPE1) using MHO_AxisPack_##TYPE1 = MHO_AxisPack< MHO_Axis##TYPE1 >;
221 
222 #define DefAxisPack2(TYPE1, TYPE2) using MHO_AxisPack_##TYPE1##_##TYPE2 = MHO_AxisPack< MHO_Axis##TYPE1, MHO_Axis##TYPE2 >;
223 
224 #define DefAxisPack3(TYPE1, TYPE2, TYPE3) \
225  using MHO_AxisPack_##TYPE1##_##TYPE2##_##TYPE3 = MHO_AxisPack< MHO_Axis##TYPE1, MHO_Axis##TYPE2, MHO_Axis##TYPE3 >;
226 
227 #define DefAxisPack4(TYPE1, TYPE2, TYPE3, TYPE4) \
228  using MHO_AxisPack_##TYPE1##_##TYPE2##_##TYPE3##_##TYPE4 = \
229  MHO_AxisPack< MHO_Axis##TYPE1, MHO_Axis##TYPE2, MHO_Axis##TYPE3, MHO_Axis##TYPE4 >;
230 
232 
236 
238 
248 
250 
260 
270 
280 
282 
292 
302 
312 
314 
324 
334 
344 
346 
356 
366 
376 
377 } // namespace hops
378 
379 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
template meta-programming helper functions, mostly tuple access/modification
Class MHO_AxisPack.
Definition: MHO_AxisPack.hh:22
std::enable_if<(N==sizeof...(XAxisTypeS)), void >::type copy(const MHO_AxisPack &) const
used for copying the full tuple from one axis pack to another
Definition: MHO_AxisPack.hh:121
MHO_AxisPack(const MHO_AxisPack &obj)
Definition: MHO_AxisPack.hh:29
std::enable_if<(N==sizeof...(XAxisTypeS)), void >::type compute_total_size(uint64_t &) const
Inductively computes and adds total serialized size of tuple elements to uint64_t& (needed for stream...
Definition: MHO_AxisPack.hh:96
virtual uint64_t GetSerializedSize() const override
Getter for serialized size.
Definition: MHO_AxisPack.hh:43
std::integral_constant< std::size_t, sizeof...(XAxisTypeS) > NAXES
Definition: MHO_AxisPack.hh:31
virtual MHO_AxisPack & operator=(const MHO_AxisPack &rhs)
Definition: MHO_AxisPack.hh:55
friend XStream & operator<<(XStream &s, const MHO_AxisPack &aData)
Definition: MHO_AxisPack.hh:138
std::enable_if<(N==sizeof...(XAxisTypeS)), void >::type resize_axis_pack(const std::size_t *)
inductive access to all elements of the tuple, so we can re-size them from an array
Definition: MHO_AxisPack.hh:70
std::tuple< XAxisTypeS... > axis_pack_tuple_type
Definition: MHO_AxisPack.hh:35
virtual ~MHO_AxisPack()
Definition: MHO_AxisPack.hh:31
MHO_AxisPack(const std::size_t *dim)
Definition: MHO_AxisPack.hh:26
MHO_AxisPack()
Definition: MHO_AxisPack.hh:24
std::enable_if<(N< sizeof...(XAxisTypeS)), void >::type resize_axis_pack(const std::size_t *dim)
Resize each element of the axis pack using the dimensions specified in dim.
Definition: MHO_AxisPack.hh:79
friend XStream & operator>>(XStream &s, MHO_AxisPack &aData)
Definition: MHO_AxisPack.hh:153
std::enable_if<(N< sizeof...(XAxisTypeS)), void >::type copy(const MHO_AxisPack &rhs)
Copies an axis pack recursively using template meta-programming.
Definition: MHO_AxisPack.hh:131
std::enable_if<(N< sizeof...(XAxisTypeS)), void >::type compute_total_size(uint64_t &total_size) const
Recursively computes and adds serialized size of Nth XAxisTypeS element to total_size.
Definition: MHO_AxisPack.hh:106
Class MHO_Serializable.
Definition: MHO_Serializable.hh:26
virtual MHO_ClassVersion GetVersion() const
Getter for version.
Definition: MHO_Serializable.hh:46
Definition: MHO_AdhocFlagging.hh:18
std::enable_if<(N >=sizeof...(T)), XStream & >::type istream_tuple(XStream &s, std::tuple< T... > &)
Returns an XStream& without modification for terminating case.
Definition: MHO_Meta.hh:155
DefAxisPack1(Int)
int Int
Definition: MHO_AxisPack.hh:216
DefAxisPack3(Int, Int, Int)
uint32_t MHO_ClassVersion
Definition: MHO_ClassIdentity.hh:22
DefAxisPack2(Int, Int)
std::string String
Definition: MHO_AxisPack.hh:218
DefAxisPack4(Int, Int, Int, Int)
double Double
Definition: MHO_AxisPack.hh:217
std::enable_if<(N >=sizeof...(T)), XStream & >::type ostream_tuple(XStream &s, const std::tuple< T... > &)
Terminating case for ostream_tuple, does nothing and returns s.
Definition: MHO_Meta.hh:118
static void ClassVersionErrorMsg(const XClassType &obj, MHO_ClassVersion version)
Generates an error message for when an unknown or unsupported class version is encountered.
Definition: MHO_ClassIdentity.hh:112
static std::string ClassName()
Returns the class name as a string.
Definition: MHO_ClassIdentity.hh:51
static void SetUnknown(XStreamType &)
Setter for unknown.
Definition: MHO_FileStreamer.hh:214