Atoms Crowd  7.0.0
MapMetadata.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 {
18 
20 
23  class ATOMSCORE_EXPORT MapMetadata: public Metadata
24  {
25  public:
26 
27  typedef std::string Key;
28 
29  typedef std::map<Key, AtomsPtr<Metadata> > valueType;
30 
32 
35  std::string typeStr() const;
36 
38  static std::string staticTypeStr();
39 
41 
44  unsigned int typeId() const;
45 
47  static unsigned int staticTypeId();
48 
51 
53  MapMetadata(const MapMetadata& rhs);
54 
57 
60 
62 
66  virtual void copy(Metadata *other);
67 
69 
72  virtual AtomsPtr<Metadata> clone() const;
73 
75 
78  virtual size_t memSize() const;
79 
81 
84  unsigned int size() const;
85 
87 
92  bool hasKey(const Key& key) const;
93 
95 
99  std::vector<Key> getKeys() const;
100 
102 
106  AtomsPtr<Metadata> getEntry(const Key& key);
107 
109 
113  AtomsPtr<const Metadata> getEntry(const Key& key) const;
114 
116 
120  template<class T>
121  AtomsPtr<T> getTypedEntry(const Key& key);
122 
124 
128  template<class T>
129  AtomsPtr<const T> getTypedEntry(const Key& key) const;
130 
132 
136  template<class T>
137  T* getTypedEntryRaw(const Key& key);
138 
140  /*
141  \param key Entry key
142  */
143  void eraseEntry(const Key& key);
144 
146 
151  void addEntry(const Key& key, AtomsPtr<Metadata>& data, bool cloneData = true);
152 
154 
159  void addEntry(const Key& key, const AtomsPtr<const Metadata>& data);
160 
162 
167  void addEntry(const Key& key, Metadata* data);
168 
170 
175  void insertEntry(const Key& key, AtomsPtr<Metadata> data);
176 
178  void addEmptyEntry(const Key& key);
179 
181 
184  void clear();
185 
187  inline valueType::iterator begin();
188 
190  inline valueType::iterator end();
191 
193  inline valueType::const_iterator cbegin() const;
194 
196  inline valueType::const_iterator cend() const;
197 
199  virtual void hash(MurmurHash3& hasher) const;
200 
201  inline valueType& data();
202 
203  inline const valueType& data() const;
204 
205  virtual void* dataPtr() { return reinterpret_cast<void*>(&m_value); }
206 
207  public:
208 
210 
214  static Metadata* creator();
215 
217  bool serialise(Archive& outStream) const;
218 
220  bool deserialise(Archive& inStream);
221 
223  void toString(std::stringstream& ss) const;
224 
226  bool serialiseCompressed(Archive& outStream) const;
227 
229  bool deserialiseCompressed(Archive& outStream);
230 
232  bool deserialiseKeys(Archive& outStream, const std::vector<std::string>& keys, bool append = false);
233 
234  bool deserialiseKeys(const std::string& filePath, const std::vector<std::string>& keys, bool append = false, bool multithread = false);
235 
236  private:
237 
239  valueType m_value;
240  };
241 }
242 namespace AtomsCore
243 {
245  ATOMSCORE_EXPORT AtomsCore::Archive& operator<<(AtomsCore::Archive& os, const AtomsCore::MapMetadata& data);
246 
248  ATOMSCORE_EXPORT AtomsCore::Archive& operator >> (AtomsCore::Archive& is, AtomsCore::MapMetadata& data);
249 }
250 #include "MapMetadata.impl.h"
251 
Archive class.
Definition: Serialiser.h:29
MapMetadata class.
Definition: MapMetadata.h:24
bool serialiseCompressed(Archive &outStream) const
Serialise random access compressed archive.
AtomsPtr< Metadata > getEntry(const Key &key)
Get an entry.
AtomsPtr< const Metadata > getEntry(const Key &key) const
Get an entry.
unsigned int size() const
Map size.
std::vector< Key > getKeys() const
Get keys.
virtual void copy(Metadata *other)
copy value
bool hasKey(const Key &key) const
Has key.
void addEntry(const Key &key, Metadata *data)
Add an entry.
static Metadata * creator()
Creator function.
void addEntry(const Key &key, AtomsPtr< Metadata > &data, bool cloneData=true)
Add an entry.
void eraseEntry(const Key &key)
Remove an entry.
virtual size_t memSize() const
Memory size.
bool deserialiseCompressed(Archive &outStream)
Deserialise random access compressed archive.
MapMetadata()
Constructor.
bool deserialise(Archive &inStream)
Deserialise.
void addEmptyEntry(const Key &key)
Add n empty entry.
~MapMetadata()
Destructor.
void clear()
Clear map.
void addEntry(const Key &key, const AtomsPtr< const Metadata > &data)
Add an entry.
std::string typeStr() const
Type string.
bool deserialiseKeys(Archive &outStream, const std::vector< std::string > &keys, bool append=false)
Deserialise only specific keys.
void toString(std::stringstream &ss) const
String conversion.
MapMetadata(const MapMetadata &rhs)
Copy constructor.
virtual AtomsPtr< Metadata > clone() const
clone object
unsigned int typeId() const
Type id.
static std::string staticTypeStr()
Class static type string.
std::map< Key, AtomsPtr< Metadata > > valueType
value type
Definition: MapMetadata.h:29
virtual void hash(MurmurHash3 &hasher) const
Hash.
void insertEntry(const Key &key, AtomsPtr< Metadata > data)
Add an entry.
bool serialise(Archive &outStream) const
Serialise.
static unsigned int staticTypeId()
Class static type string.
MapMetadata & operator=(const MapMetadata &other)
Assign operator.
Base Metadata class.
Definition: Metadata.h:24
Definition: Hash.h:23
AtomsCore namespace.
Definition: Agent.h:344