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 
26 template< typename XValueType >
27 class MHO_VectorContainer: public MHO_VectorContainerBase, public MHO_NDArrayWrapper< XValueType, 1 >, public MHO_Taggable
28 {
29  public:
30  MHO_VectorContainer(): MHO_NDArrayWrapper< XValueType, 1 >(){};
31 
32  MHO_VectorContainer(std::size_t dim): MHO_NDArrayWrapper< XValueType, 1 >(dim){};
33 
34  MHO_VectorContainer(std::size_t* dim): MHO_NDArrayWrapper< XValueType, 1 >(dim){};
35 
36  //copy constructor
37  MHO_VectorContainer(const MHO_VectorContainer& obj): MHO_NDArrayWrapper< XValueType, 1 >(obj), MHO_Taggable(obj){};
38 
39  //clone functionality
45  MHO_VectorContainer* Clone() { return new MHO_VectorContainer(*this); }
46 
47  virtual ~MHO_VectorContainer(){};
48 
55  virtual MHO_ClassVersion GetVersion() const override { return 0; };
56 
63  virtual uint64_t GetSerializedSize() const override { return ComputeSerializedSize(); }
64 
65  //have to make base class functions visible
74 
75 
82  virtual void Copy(const MHO_VectorContainer& rhs)
83  {
84  if(&rhs != this)
85  {
86  //copy the array
88  //then copy the tags
89  this->CopyTags(rhs);
90  }
91  }
92 
93  public:
99  uint64_t ComputeSerializedSize() const
100  {
101  uint64_t total_size = 0;
102  total_size += sizeof(MHO_ClassVersion);
103  total_size += MHO_Taggable::GetSerializedSize();
104  total_size += sizeof(uint64_t);
105  total_size += this->GetSize() * sizeof(XValueType); //all elements have the same size
106  return total_size;
107  }
108 
109  template< typename XStream > friend XStream& operator>>(XStream& s, MHO_VectorContainer& aData)
110  {
111  MHO_ClassVersion vers;
112  s >> vers;
113  switch(vers)
114  {
115  case 0:
116  aData.StreamInData_V0(s);
117  break;
118  default:
120  //Flag this as an unknown object version so we can skip over this data
122  }
123  return s;
124  }
125 
126  template< typename XStream > friend XStream& operator<<(XStream& s, const MHO_VectorContainer& aData)
127  {
128  switch(aData.GetVersion())
129  {
130  case 0:
131  s << aData.GetVersion();
132  aData.StreamOutData_V0(s);
133  break;
134  default:
135  msg_error("containers", "error, cannot stream out MHO_VectorContainer object with unknown version: "
136  << aData.GetVersion() << eom);
137  }
138  return s;
139  }
140 
141  private:
148  template< typename XStream > void StreamOutData_V0(XStream& s) const
149  {
150  s << static_cast< const MHO_Taggable& >(*this);
151  uint64_t dsize = this->GetSize();
152  s << (uint64_t)dsize;
153  auto data_ptr = this->GetData();
154  for(size_t i = 0; i < dsize; i++)
155  {
156  s << data_ptr[i];
157  }
158  }
159 
166  template< typename XStream > void StreamInData_V0(XStream& s)
167  {
168  s >> static_cast< MHO_Taggable& >(*this);
169  size_t total_size[1];
170  s >> total_size[0];
171  this->Resize(total_size);
172  auto data_ptr = this->GetData();
173  for(size_t i = 0; i < total_size[0]; i++)
174  {
175  s >> data_ptr[i];
176  }
177  }
178 
179  virtual MHO_UUID DetermineTypeUUID() const override
180  {
181  MHO_MD5HashGenerator gen;
182  gen.Initialize();
183  std::string name = MHO_ClassIdentity::ClassName(*this);
184  gen << name;
185  gen.Finalize();
186  return gen.GetDigestAsUUID();
187  }
188 };
189 
190 
198 {
199  uint64_t total_size = 0;
200  total_size += sizeof(MHO_ClassVersion);
201  total_size += MHO_Taggable::GetSerializedSize();
202  total_size += sizeof(uint64_t);
203  std::size_t dsize = this->GetSize();
204  auto data_ptr = this->GetData();
205  for(size_t i = 0; i < dsize; i++)
206  {
207  total_size += sizeof(uint64_t); //every string get streamed with a size
208  total_size += data_ptr[i].size(); //n char in each string
209  }
210  return total_size;
211 }
212 
213 // ////////////////////////////////////////////////////////////////////////////////
214 //using declarations for all basic 'plain-old-data' types (except bool!)
232 
234 
235 } // namespace hops
236 
237 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
template meta-programming helper functions, mostly tuple access/modification
XValueType * GetData()
Getter for data.
Definition: MHO_NDArrayWrapper_1.hh:85
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:107
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:384
MHO_VectorContainer - basis for for axis data objects in HOPS4, it is an 1-dimensional array object,...
Definition: MHO_VectorContainer.hh:28
virtual MHO_ClassVersion GetVersion() const override
Getter for version.
Definition: MHO_VectorContainer.hh:55
virtual void Copy(const MHO_VectorContainer &rhs)
Expensive copy for MHO_VectorContainer, pointers to exernally managed memory are not transferred,...
Definition: MHO_VectorContainer.hh:82
MHO_VectorContainer(const MHO_VectorContainer &obj)
Definition: MHO_VectorContainer.hh:37
virtual ~MHO_VectorContainer()
Definition: MHO_VectorContainer.hh:47
MHO_VectorContainer(std::size_t dim)
Definition: MHO_VectorContainer.hh:32
MHO_VectorContainer()
Definition: MHO_VectorContainer.hh:30
MHO_VectorContainer(std::size_t *dim)
Definition: MHO_VectorContainer.hh:34
virtual uint64_t GetSerializedSize() const override
Getter for serialized size.
Definition: MHO_VectorContainer.hh:63
friend XStream & operator>>(XStream &s, MHO_VectorContainer &aData)
Definition: MHO_VectorContainer.hh:109
MHO_VectorContainer * Clone()
Clones the current MHO_VectorContainer object.
Definition: MHO_VectorContainer.hh:45
friend XStream & operator<<(XStream &s, const MHO_VectorContainer &aData)
Definition: MHO_VectorContainer.hh:126
uint64_t ComputeSerializedSize() const
Calculates and returns the serialized size as a uint64_t.
Definition: MHO_VectorContainer.hh:99
Definition: MHO_ChannelLabeler.hh:17
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: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