HOPS
HOPS class reference
MHO_VectorContainer.hh
Go to the documentation of this file.
1 #ifndef MHO_VectorContainer_HH__
2 #define MHO_VectorContainer_HH__
3 
4 #include <complex>
5 #include <string>
6 
7 #include "MHO_Meta.hh"
8 #include "MHO_NDArrayWrapper.hh"
9 #include "MHO_Serializable.hh"
10 #include "MHO_Taggable.hh"
11 
12 namespace hops
13 {
14 
25 template< typename XValueType >
26 class MHO_VectorContainer: public MHO_VectorContainerBase, public MHO_NDArrayWrapper< XValueType, 1 >, public MHO_Taggable
27 {
28  public:
29  MHO_VectorContainer(): MHO_NDArrayWrapper< XValueType, 1 >(){};
30 
31  MHO_VectorContainer(std::size_t dim): MHO_NDArrayWrapper< XValueType, 1 >(dim){};
32 
33  MHO_VectorContainer(std::size_t* dim): MHO_NDArrayWrapper< XValueType, 1 >(dim){};
34 
35  //copy constructor
36  MHO_VectorContainer(const MHO_VectorContainer& obj): MHO_NDArrayWrapper< XValueType, 1 >(obj), MHO_Taggable(obj){};
37 
38  //clone functionality
44  MHO_VectorContainer* Clone() { return new MHO_VectorContainer(*this); }
45 
46  virtual ~MHO_VectorContainer(){};
47 
54  virtual MHO_ClassVersion GetVersion() const override { return 0; };
55 
62  virtual uint64_t GetSerializedSize() const override { return ComputeSerializedSize(); }
63 
64  //have to make base class functions visible
73 
80  virtual void Copy(const MHO_VectorContainer& rhs)
81  {
82  if(&rhs != this)
83  {
84  //copy the array
86  //then copy the tags
87  this->CopyTags(rhs);
88  }
89  }
90 
91  public:
97  uint64_t ComputeSerializedSize() const
98  {
99  uint64_t total_size = 0;
100  total_size += sizeof(MHO_ClassVersion);
101  total_size += MHO_Taggable::GetSerializedSize();
102  total_size += sizeof(uint64_t);
103  total_size += this->GetSize() * sizeof(XValueType); //all elements have the same size
104  return total_size;
105  }
106 
107  template< typename XStream > friend XStream& operator>>(XStream& s, MHO_VectorContainer& aData)
108  {
109  MHO_ClassVersion vers;
110  s >> vers;
111  switch(vers)
112  {
113  case 0:
114  aData.StreamInData_V0(s);
115  break;
116  default:
118  //Flag this as an unknown object version so we can skip over this data
120  }
121  return s;
122  }
123 
124  template< typename XStream > friend XStream& operator<<(XStream& s, const MHO_VectorContainer& aData)
125  {
126  switch(aData.GetVersion())
127  {
128  case 0:
129  s << aData.GetVersion();
130  aData.StreamOutData_V0(s);
131  break;
132  default:
133  msg_error("containers", "error, cannot stream out MHO_VectorContainer object with unknown version: "
134  << aData.GetVersion() << eom);
135  }
136  return s;
137  }
138 
139  private:
146  template< typename XStream > void StreamOutData_V0(XStream& s) const
147  {
148  s << static_cast< const MHO_Taggable& >(*this);
149  uint64_t dsize = this->GetSize();
150  s << (uint64_t)dsize;
151  auto data_ptr = this->GetData();
152  for(size_t i = 0; i < dsize; i++)
153  {
154  s << data_ptr[i];
155  }
156  }
157 
164  template< typename XStream > void StreamInData_V0(XStream& s)
165  {
166  s >> static_cast< MHO_Taggable& >(*this);
167  size_t total_size[1];
168  s >> total_size[0];
169  this->Resize(total_size);
170  auto data_ptr = this->GetData();
171  for(size_t i = 0; i < total_size[0]; i++)
172  {
173  s >> data_ptr[i];
174  }
175  }
176 
177  virtual MHO_UUID DetermineTypeUUID() const override
178  {
179  MHO_MD5HashGenerator gen;
180  gen.Initialize();
181  std::string name = MHO_ClassIdentity::ClassName(*this);
182  gen << name;
183  gen.Finalize();
184  return gen.GetDigestAsUUID();
185  }
186 };
187 
195 {
196  uint64_t total_size = 0;
197  total_size += sizeof(MHO_ClassVersion);
198  total_size += MHO_Taggable::GetSerializedSize();
199  total_size += sizeof(uint64_t);
200  std::size_t dsize = this->GetSize();
201  auto data_ptr = this->GetData();
202  for(size_t i = 0; i < dsize; i++)
203  {
204  total_size += sizeof(uint64_t); //every string get streamed with a size
205  total_size += data_ptr[i].size(); //n char in each string
206  }
207  return total_size;
208 }
209 
210 // ////////////////////////////////////////////////////////////////////////////////
211 //using declarations for all basic 'plain-old-data' types (except bool!)
229 
231 
232 } // namespace hops
233 
234 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
template meta-programming helper functions, mostly tuple access/modification
XValueType * GetData()
Getter for data.
Definition: MHO_NDArrayWrapper_1.hh:77
virtual void Resize(const std::size_t *dim)
Resize an externally managed array using provided dimensions.
Definition: MHO_NDArrayWrapper_1.hh:52
std::size_t GetSize() const
Getter for size.
Definition: MHO_NDArrayWrapper_1.hh:99
Class MHO_NDArrayWrapper.
Definition: MHO_NDArrayWrapper.hh:42
virtual void Copy(const MHO_NDArrayWrapper &rhs)
Definition: MHO_NDArrayWrapper.hh:301
Class MHO_Taggable.
Definition: MHO_Taggable.hh:26
MHO_Taggable()
Definition: MHO_Taggable.hh:28
virtual void CopyTags(const MHO_Taggable &rhs)
Copies tags from rhs to this instance if rhs is not empty and has valid object.
Definition: MHO_Taggable.hh:49
virtual uint64_t GetSerializedSize() const override
Getter for serialized size.
Definition: MHO_Taggable.hh:120
Definition: MHO_Meta.hh:414
MHO_VectorContainer - basis for for axis data objects in HOPS4, it is an 1-dimensional array object,...
Definition: MHO_VectorContainer.hh:27
virtual MHO_ClassVersion GetVersion() const override
Getter for version.
Definition: MHO_VectorContainer.hh:54
virtual void Copy(const MHO_VectorContainer &rhs)
Expensive copy for MHO_VectorContainer, pointers to exernally managed memory are not transferred,...
Definition: MHO_VectorContainer.hh:80
MHO_VectorContainer(const MHO_VectorContainer &obj)
Definition: MHO_VectorContainer.hh:36
virtual ~MHO_VectorContainer()
Definition: MHO_VectorContainer.hh:46
MHO_VectorContainer(std::size_t dim)
Definition: MHO_VectorContainer.hh:31
MHO_VectorContainer()
Definition: MHO_VectorContainer.hh:29
MHO_VectorContainer(std::size_t *dim)
Definition: MHO_VectorContainer.hh:33
virtual uint64_t GetSerializedSize() const override
Getter for serialized size.
Definition: MHO_VectorContainer.hh:62
friend XStream & operator>>(XStream &s, MHO_VectorContainer &aData)
Definition: MHO_VectorContainer.hh:107
MHO_VectorContainer * Clone()
Clones the current MHO_VectorContainer object.
Definition: MHO_VectorContainer.hh:44
friend XStream & operator<<(XStream &s, const MHO_VectorContainer &aData)
Definition: MHO_VectorContainer.hh:124
uint64_t ComputeSerializedSize() const
Calculates and returns the serialized size as a uint64_t.
Definition: MHO_VectorContainer.hh:97
Definition: MHO_AdhocFlagging.hh:18
uint32_t MHO_ClassVersion
Definition: MHO_ClassIdentity.hh:22
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