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:
62 
69  template< std::size_t N = 0 >
70  typename std::enable_if< (N == sizeof...(XAxisTypeS)), void >::type
71  resize_axis_pack(const std::size_t* ){}; //terminating case, do nothing
72 
79  template< std::size_t N = 0 >
80  typename std::enable_if< (N < sizeof...(XAxisTypeS)), void >::type resize_axis_pack(const std::size_t* dim)
81  {
82  //resize the N-th element of the tuple
83  std::get< N >(*this).Resize(dim[N]);
84  //now run the induction
85  resize_axis_pack< N + 1 >(dim);
86  }
87 
88  // //inductive access to all elements of the tuple, so we compute total size for streaming
95  template< std::size_t N = 0 >
96  typename std::enable_if< (N == sizeof...(XAxisTypeS)), void >::type
97  compute_total_size(uint64_t& ) const {}; //terminating case, do nothing
98 
106  template< std::size_t N = 0 >
107  typename std::enable_if< (N < sizeof...(XAxisTypeS)), void >::type compute_total_size(uint64_t& total_size) const
108  {
109  total_size += std::get< N >(*this).GetSerializedSize();
110  //now run the induction
111  compute_total_size< N + 1 >(total_size);
112  }
113 
114 
121  template< std::size_t N = 0 >
122  typename std::enable_if< (N == sizeof...(XAxisTypeS)), void >::type
123  copy(const MHO_AxisPack&) const {}; //terminating case, do nothing
124 
132  template< std::size_t N = 0 >
133  typename std::enable_if< (N < sizeof...(XAxisTypeS)), void >::type copy(const MHO_AxisPack& rhs)
134  {
135  std::get< N >(*this).Copy(std::get< N >(rhs));
136  copy< N + 1 >(rhs);
137  }
138 
139  public:
140  template< typename XStream > friend XStream& operator<<(XStream& s, const MHO_AxisPack& aData)
141  {
142  switch(aData.GetVersion())
143  {
144  case 0:
145  s << aData.GetVersion();
146  aData.StreamOutData_V0(s);
147  break;
148  default:
149  msg_error("containers",
150  "error, cannot stream out MHO_Axis object with unknown version: " << aData.GetVersion() << eom);
151  }
152  return s;
153  }
154 
155  template< typename XStream > friend XStream& operator>>(XStream& s, MHO_AxisPack& aData)
156  {
157  MHO_ClassVersion vers;
158  s >> vers;
159  switch(vers)
160  {
161  case 0:
162  aData.StreamInData_V0(s);
163  break;
164  default:
166  //Flag this as an unknown object version so we can skip over this data
168  }
169  return s;
170  }
171 
172  private:
179  template< typename XStream > void StreamInData_V0(XStream& s) { istream_tuple(s, *this); }
180 
181 
189  template< typename XStream > void StreamOutData_V0(XStream& s) const { ostream_tuple(s, *this); }
190 
198  virtual MHO_UUID DetermineTypeUUID() const override
199  {
200  MHO_MD5HashGenerator gen;
201  gen.Initialize();
202  std::string name = MHO_ClassIdentity::ClassName(*this);
203  gen << name;
204  gen.Finalize();
205  return gen.GetDigestAsUUID();
206  }
207 };
208 
215 
216 //TODO FIXME -- find away to loop over macro arguments so we dont need so many
217 //boilerplate definitions
218 
219 using Int = int;
220 using Double = double;
221 using String = std::string;
222 
223 #define DefAxisPack1(TYPE1) using MHO_AxisPack_##TYPE1 = MHO_AxisPack< MHO_Axis##TYPE1 >;
224 
225 #define DefAxisPack2(TYPE1, TYPE2) using MHO_AxisPack_##TYPE1##_##TYPE2 = MHO_AxisPack< MHO_Axis##TYPE1, MHO_Axis##TYPE2 >;
226 
227 #define DefAxisPack3(TYPE1, TYPE2, TYPE3) \
228  using MHO_AxisPack_##TYPE1##_##TYPE2##_##TYPE3 = MHO_AxisPack< MHO_Axis##TYPE1, MHO_Axis##TYPE2, MHO_Axis##TYPE3 >;
229 
230 #define DefAxisPack4(TYPE1, TYPE2, TYPE3, TYPE4) \
231  using MHO_AxisPack_##TYPE1##_##TYPE2##_##TYPE3##_##TYPE4 = \
232  MHO_AxisPack< MHO_Axis##TYPE1, MHO_Axis##TYPE2, MHO_Axis##TYPE3, MHO_Axis##TYPE4 >;
233 
235 
239 
241 
251 
253 
263 
273 
283 
285 
295 
305 
315 
317 
327 
337 
347 
349 
359 
369 
379 
380 } // namespace hops
381 
382 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
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:123
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:97
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:140
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:71
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:80
friend XStream & operator>>(XStream &s, MHO_AxisPack &aData)
Definition: MHO_AxisPack.hh:155
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:133
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:107
Class MHO_Serializable.
Definition: MHO_Serializable.hh:26
virtual MHO_ClassVersion GetVersion() const
Getter for version.
Definition: MHO_Serializable.hh:46
Definition: MHO_ChannelLabeler.hh:17
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:219
DefAxisPack3(Int, Int, Int)
uint32_t MHO_ClassVersion
Definition: MHO_ClassIdentity.hh:22
DefAxisPack2(Int, Int)
std::string String
Definition: MHO_AxisPack.hh:221
DefAxisPack4(Int, Int, Int, Int)
double Double
Definition: MHO_AxisPack.hh:220
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:99
static std::string ClassName()
Returns the class name as a string.
Definition: MHO_ClassIdentity.hh:36
static void SetUnknown(XStreamType &)
Setter for unknown.
Definition: MHO_FileStreamer.hh:215