Atoms Crowd  7.0.0
ArrayMetadata.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsCore/Globals.h>
11 #include <AtomsCore/Metadata/Metadata.h>
12 #include <string>
13 #include <map>
14 #include <vector>
15 
16 namespace AtomsCore
17 {
19 
22  class ATOMSCORE_EXPORT ArrayMetadata : public Metadata
23  {
24  public:
25 
26  typedef std::vector<AtomsPtr<Metadata> > valueType;
27 
29 
32  std::string typeStr() const;
33 
35  static std::string staticTypeStr();
36 
38 
41  unsigned int typeId() const;
42 
43 
45  static unsigned int staticTypeId();
46 
49 
52 
55 
58 
60 
64  virtual void copy(Metadata *other);
65 
67 
70  virtual AtomsPtr<Metadata> clone() const;
71 
73 
76  virtual size_t memSize() const;
77 
79 
82  size_t size() const;
83 
85 
89  AtomsPtr<Metadata> operator[](size_t index);
90 
92 
96  AtomsPtr<const Metadata> operator[](size_t index) const;
97 
99 
103  template<class T>
104  AtomsPtr<T> getTypedElement(size_t index);
105 
107 
111  template<class T>
112  AtomsPtr<const T> getTypedElement(size_t index) const;
113 
115  /*
116  \param key Entry key
117  */
118  void erase(size_t index);
119 
121 
126  void push_back(const AtomsPtr<Metadata>& data);
127 
129 
134  void push_back(Metadata* data);
135 
137 
142  void insert(size_t index, const AtomsPtr<Metadata>& data);
143 
145 
150  void insert(size_t index, Metadata* data);
151 
153 
156  void clear();
157 
159  virtual void hash(MurmurHash3& hasher) const;
160 
161  virtual void* dataPtr() { return reinterpret_cast<void*>(&m_value); }
162 
163  public:
164 
166 
170  static Metadata* creator();
171 
173  bool serialise(Archive& outStream) const;
174 
176  bool deserialise(Archive& inStream);
177 
178  void toString(std::stringstream& ss) const;
179 
181  bool serialiseCompressed(Archive& outStream) const;
182 
184  bool deserialiseCompressed(Archive& outStream);
185 
187  bool deserialiseKeys(Archive& outStream, const std::vector<size_t>& keys, bool append = false);
188 
189  bool deserialiseKeys(const std::string& fileName, const std::vector<std::size_t>& keysToDeserialise, bool append = false);
190 
191  private:
192 
194  valueType m_value;
195  };
196 }
197 
198 namespace AtomsCore
199 {
201  ATOMSCORE_EXPORT AtomsCore::Archive& operator<<(AtomsCore::Archive& os, const AtomsCore::ArrayMetadata& data);
202 
204  ATOMSCORE_EXPORT AtomsCore::Archive& operator >> (AtomsCore::Archive& is, AtomsCore::ArrayMetadata& data);
205 }
206 #include "ArrayMetadata.impl.h"
Archive class.
Definition: Serialiser.h:29
ArrayMetadata class.
Definition: ArrayMetadata.h:23
void clear()
Clear map.
bool deserialiseCompressed(Archive &outStream)
Deserialise random access compressed archive.
~ArrayMetadata()
Destructor.
size_t size() const
Array size.
bool deserialise(Archive &inStream)
Deserialise.
virtual void copy(Metadata *other)
copy value
void insert(size_t index, Metadata *data)
Insert an entry.
ArrayMetadata(const ArrayMetadata &rhs)
Copy constructor.
AtomsPtr< const Metadata > operator[](size_t index) const
Subscript operator.
std::string typeStr() const
Type string.
static unsigned int staticTypeId()
Class static type string.
void push_back(Metadata *data)
Add an entry.
ArrayMetadata & operator=(const ArrayMetadata &other)
Assign operator.
virtual AtomsPtr< Metadata > clone() const
clone object
AtomsPtr< Metadata > operator[](size_t index)
Get an element.
bool serialise(Archive &outStream) const
Serialise.
void toString(std::stringstream &ss) const
String conversion.
static Metadata * creator()
Creator function.
void push_back(const AtomsPtr< Metadata > &data)
Add an entry.
std::vector< AtomsPtr< Metadata > > valueType
value type
Definition: ArrayMetadata.h:26
static std::string staticTypeStr()
Class static type string.
bool deserialiseKeys(Archive &outStream, const std::vector< size_t > &keys, bool append=false)
Deserialise only specific keys.
virtual size_t memSize() const
Memory size.
bool serialiseCompressed(Archive &outStream) const
Serialise random access compressed archive.
ArrayMetadata()
Constructor.
unsigned int typeId() const
Type id.
void erase(size_t index)
Remove an element.
virtual void hash(MurmurHash3 &hasher) const
Hash function.
void insert(size_t index, const AtomsPtr< Metadata > &data)
Insert an entry at the given index.
Base Metadata class.
Definition: Metadata.h:24
Definition: Hash.h:23
AtomsCore namespace.
Definition: Agent.h:344