Atoms Crowd  7.0.0
MetadataImpl.impl.h
1 namespace AtomsCore
2 {
3  template <class T>
5  Metadata(),
6  m_value(T())
7  {
9  }
10 
11  template <class T>
13  Metadata(),
14  m_value(value)
15  {
16  }
17 
18  template <class T>
20  {
21  }
22 
23  template <class T>
25  Metadata(),
26  m_value(other.m_value)
27  {
28  }
29 
30  template <class T>
32  {
33  this->m_value = other.m_value;
34  return *this;
35  }
36 
37  template <class T>
39  {
40  MetadataImpl<T>* data = static_cast<MetadataImpl<T>*>(other);
41  if (data)
42  this->m_value = data->m_value;
43  }
44 
45  template <class T>
46  AtomsPtr<Metadata> MetadataImpl<T>::clone() const
47  {
48  return AtomsPtr<Metadata>(dynamic_cast<Metadata*>(new MetadataImpl<T>(*this)));
49  }
50 
51  template <class T>
52  size_t MetadataImpl<T>::memSize() const
53  {
54  return sizeof(unsigned int) + AtomsCore::memSize(m_value);
55  }
56 
57  template <class T>
58  std::string MetadataImpl<T>::typeStr() const
59  {
61  }
62 
63  template <class T>
64  unsigned int MetadataImpl<T>::typeId() const
65  {
67  }
68 
69  template <class T>
70  void MetadataImpl<T>::set(const T& value)
71  {
72  m_value = value;
73  }
74 
75  template <class T>
77  {
78  return m_value;
79  }
80 
81  template <class T>
82  const T& MetadataImpl<T>::get() const
83  {
84  return m_value;
85  }
86 
87  template <class T>
89  {
90  return m_value;
91  }
92 
93  template <class T>
95  {
96  return new MetadataImpl<T>();
97  }
98 
99  template <class T>
100  bool MetadataImpl<T>::serialise(Archive& outStream) const
101  {
102  if (outStream.size == 0)
103  {
104  outStream.resize(memSize());
105  }
106 
107  outStream << typeId();
108  outStream << m_value;
109  return true;
110  }
111 
112  template <class T>
114  {
115  unsigned int typeIdValue;
116  inStream >> typeIdValue;
117  inStream >> m_value;
118  return true;
119  }
120 
121  template <class T>
122  void MetadataImpl<T>::toString(std::stringstream& ss) const
123  {
124 #ifdef ATOMS_UNREAL
125 
126 #else
127  ss << m_value;
128 #endif
129  }
130 
131  template <class T>
132  bool MetadataImpl<T>::setWithValuesAndWeights(const std::vector<AtomsPtr<Metadata>> &values, const std::vector<double> &weights)
133  {
134  return false;
135  }
136 
137  template <class T>
138  bool MetadataImpl<T>::setWithValuesAndWeights(const std::vector<Metadata *> &values, const std::vector<double> &weights)
139  {
140  return false;
141  }
142 
143  template <class T>
144  void MetadataImpl<T>::hash(MurmurHash3& hasher) const
145  {
146  hasher.append(m_value);
147  }
148 
149  template <class T>
150  bool MetadataImpl<T>::isEqual(Metadata* right, double err) const
151  {
152  if (this == right) return true;
153 
154  if (right->typeId() != typeId())
155  return false;
156 
157  return m_value == static_cast<MetadataImpl<T>*>(right)->get();
158  }
159 
160  template <class T>
162  {
163  return false;
164  }
165 
166  template <class T>
168  {
169  return false;
170  }
171 }
Archive class.
Definition: Serialiser.h:29
size_t size
Memory size of the binary stream.
Definition: Serialiser.h:106
void resize(size_t len)
Resize buffer.
Base Metadata class.
Definition: Metadata.h:24
virtual unsigned int typeId() const =0
Type id.
Metadata template class.
Definition: MetadataImpl.h:158
bool serialise(Archive &outArchive) const
Binary Serialise.
Definition: MetadataImpl.impl.h:100
T & get()
Get reference.
Definition: MetadataImpl.impl.h:88
virtual bool isGreater(Metadata *right) const
Is greater then.
Definition: MetadataImpl.impl.h:161
MetadataImpl()
Default constructor.
Definition: MetadataImpl.impl.h:4
std::string typeStr() const
Type string.
Definition: MetadataImpl.impl.h:58
bool deserialise(Archive &inStream)
Binary Deserialise.
Definition: MetadataImpl.impl.h:113
~MetadataImpl()
Destructor.
Definition: MetadataImpl.impl.h:19
virtual void toString(std::stringstream &ss) const
String conversion.
Definition: MetadataImpl.impl.h:122
T value() const
Get value.
Definition: MetadataImpl.impl.h:76
virtual bool isEqual(Metadata *right, double err=0.0) const
Equal function.
Definition: MetadataImpl.impl.h:150
virtual void hash(MurmurHash3 &hasher) const
Hash function.
Definition: MetadataImpl.impl.h:144
virtual bool isLess(Metadata *right) const
Is less then.
Definition: MetadataImpl.impl.h:167
virtual bool setWithValuesAndWeights(const std::vector< AtomsPtr< Metadata >> &values, const std::vector< double > &weights)
Set with weighted values.
Definition: MetadataImpl.impl.h:132
static unsigned int staticTypeId()
Class static type string.
MetadataImpl & operator=(const MetadataImpl &other)
Assign operator.
Definition: MetadataImpl.impl.h:31
void set(const T &value)
Set value.
Definition: MetadataImpl.impl.h:70
virtual AtomsPtr< Metadata > clone() const
clone object
Definition: MetadataImpl.impl.h:46
unsigned int typeId() const
Type id.
Definition: MetadataImpl.impl.h:64
virtual size_t memSize() const
Memory size.
Definition: MetadataImpl.impl.h:52
static Metadata * creator()
Creator function.
Definition: MetadataImpl.impl.h:94
static std::string staticTypeStr()
Class static type string.
virtual void copy(Metadata *other)
copy value
Definition: MetadataImpl.impl.h:38
Definition: Hash.h:23
AtomsCore namespace.
Definition: Agent.h:344
static const void initialize(T &value)
initializes the metadata value
Definition: MetadataTraits.h:27