HOPS
HOPS class reference
MHO_ScalarContainer.hh
Go to the documentation of this file.
1 #ifndef MHO_ScalarContainer_HH__
2 #define MHO_ScalarContainer_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 
23 template< typename XValueType >
24 class MHO_ScalarContainer: public MHO_ScalarContainerBase, public MHO_NDArrayWrapper< XValueType, 0 >, public MHO_Taggable
25 {
26  public:
27  MHO_ScalarContainer(): MHO_NDArrayWrapper< XValueType, 0 >(){};
28 
29  virtual ~MHO_ScalarContainer(){};
30 
32 
39  virtual MHO_ClassVersion GetVersion() const override { return 0; };
40 
47  virtual uint64_t GetSerializedSize() const override { return ComputeSerializedSize(); }
48 
55  uint64_t ComputeSerializedSize() const
56  {
57  uint64_t total_size = 0;
58  total_size += sizeof(MHO_ClassVersion); //version
59  total_size += sizeof(XValueType); //contents
60  total_size += MHO_Taggable::GetSerializedSize();
61  return total_size;
62  }
63 
69  void SetValue(const XValueType& value) { fData = value; };
70 
76  XValueType GetValue() { return fData; };
77 
78  //have to make base class functions visible
81 
87  std::size_t GetSize() const { return 1; };
88 
89  public:
90  template< typename XStream > friend XStream& operator>>(XStream& s, MHO_ScalarContainer& aData)
91  {
92  MHO_ClassVersion vers;
93  s >> vers;
94  switch(vers)
95  {
96  case 0:
97  aData.StreamInData_V0(s);
98  break;
99  default:
101  //Flag this as an unknown object version so we can skip over this data
103  }
104  return s;
105  }
106 
107  template< typename XStream > friend XStream& operator<<(XStream& s, const MHO_ScalarContainer& aData)
108  {
109  switch(aData.GetVersion())
110  {
111  case 0:
112  s << aData.GetVersion();
113  aData.StreamOutData_V0(s);
114  break;
115  default:
116  msg_error("containers", "error, cannot stream out MHO_ScalarContainer object with unknown version: "
117  << aData.GetVersion() << eom);
118  }
119  return s;
120  }
121 
122  private:
129  template< typename XStream > void StreamInData_V0(XStream& s)
130  {
131  s >> this->fData;
132  s >> static_cast< MHO_Taggable& >(*this);
133  };
134 
141  template< typename XStream > void StreamOutData_V0(XStream& s) const
142  {
143  s << this->fData;
144  s << static_cast< const MHO_Taggable& >(*this);
145  };
146 
153  virtual MHO_UUID DetermineTypeUUID() const override
154  {
155  MHO_MD5HashGenerator gen;
156  gen.Initialize();
157  std::string name = MHO_ClassIdentity::ClassName(*this);
158  gen << name;
159  gen.Finalize();
160  return gen.GetDigestAsUUID();
161  }
162 
163  protected:
165 };
166 
167 //specialization for string elements
168 //(NOTE: we need to use 'inline' to satisfy one-definiton rule, otherwise we have to stash this in a .cc file)
175 {
176  uint64_t total_size = 0;
177  total_size += sizeof(MHO_ClassVersion); //version
178  total_size += sizeof(uint64_t); //string size parameter
179  total_size += fData.size(); //size of the string
180  total_size += MHO_Taggable::GetSerializedSize();
181  return total_size;
182 }
183 
185 //using declarations for all basic 'plain-old-data' types
204 
206 
207 } // namespace hops
208 
209 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:244
template meta-programming helper functions, mostly tuple access/modification
XValueType fData
Definition: MHO_NDArrayWrapper_0.hh:83
Class MHO_NDArrayWrapper.
Definition: MHO_NDArrayWrapper.hh:42
Definition: MHO_Meta.hh:387
MHO_ScalarContainer, and wrapper class for storage of a scalar object.
Definition: MHO_ScalarContainer.hh:25
std::size_t GetSize() const
Getter for size.
Definition: MHO_ScalarContainer.hh:87
virtual MHO_ClassVersion GetVersion() const override
Getter for version.
Definition: MHO_ScalarContainer.hh:39
friend XStream & operator<<(XStream &s, const MHO_ScalarContainer &aData)
Definition: MHO_ScalarContainer.hh:107
uint64_t ComputeSerializedSize() const
Calculates and returns the serialized size of an object.
Definition: MHO_ScalarContainer.hh:55
void SetValue(const XValueType &value)
Setter for value.
Definition: MHO_ScalarContainer.hh:69
virtual uint64_t GetSerializedSize() const override
Getter for serialized size.
Definition: MHO_ScalarContainer.hh:47
XValueType GetValue()
Getter for value.
Definition: MHO_ScalarContainer.hh:76
virtual ~MHO_ScalarContainer()
Definition: MHO_ScalarContainer.hh:29
MHO_ScalarContainer()
Definition: MHO_ScalarContainer.hh:27
MHO_ScalarContainer(MHO_ScalarContainer &obj)
Definition: MHO_ScalarContainer.hh:31
friend XStream & operator>>(XStream &s, MHO_ScalarContainer &aData)
Definition: MHO_ScalarContainer.hh:90
Class MHO_Taggable.
Definition: MHO_Taggable.hh:26
virtual uint64_t GetSerializedSize() const override
Getter for serialized size.
Definition: MHO_Taggable.hh:120
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
Definition: vex.h:175