Atoms Crowd  7.0.0
MetadataFactory.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 <AtomsCore/Metadata/MetadataFactory.h>
13 #include <map>
14 #include <unordered_map>
15 #include <vector>
16 
17 namespace AtomsCore
18 {
20 
22  class ATOMSCORE_EXPORT MetadataFactory
23  {
24  public:
25 
26  typedef Metadata* (*creatorFn)();
27 
30 
32 
36  AtomsPtr<Metadata> createMetadata(const std::string& typeName);
37 
39 
43  AtomsPtr<Metadata> createMetadata(unsigned int id);
44 
46 
50  Metadata* createMetadataRawPtr(const std::string& typeName);
51 
53 
57  Metadata* createMetadataRawPtr(unsigned int& id);
58 
60 
64  void registerMetadata(const std::string& name, unsigned int id, creatorFn funct);
65 
67 
70  void deregisterMetadata(const std::string& name);
71 
73 
76  std::vector<std::string> getRegisteredMetadata();
77 
79 
83  bool isRegistered(const std::string& name);
84 
86 
90  const std::string getMetadataName(unsigned int id);
91 
92  private:
93 
96 
99 
101  ~MetadataFactory();
102 
104  MetadataFactory& operator=(const MetadataFactory&);
105 
106  typedef std::unordered_map<std::string, creatorFn> FactoryMap;
107 
109 
112  FactoryMap m_factoryMap;
113 
115  std::unordered_map<unsigned int, std::string> m_idNameMap;
116 
117  };
118 }
Metadata factory.
Definition: MetadataFactory.h:23
Metadata * createMetadataRawPtr(unsigned int &id)
Create a metadata.
static MetadataFactory & instance()
Singleton access.
bool isRegistered(const std::string &name)
Check if a metadata type is registered.
Metadata * createMetadataRawPtr(const std::string &typeName)
Create a metadata.
AtomsPtr< Metadata > createMetadata(const std::string &typeName)
Create a metadata.
std::vector< std::string > getRegisteredMetadata()
Get all registered metadata.
void registerMetadata(const std::string &name, unsigned int id, creatorFn funct)
Register a metadata type to the factory.
const std::string getMetadataName(unsigned int id)
Get metadata name from id.
void deregisterMetadata(const std::string &name)
Deregister a metadata type from the factory.
AtomsPtr< Metadata > createMetadata(unsigned int id)
Create a metadata.
Base Metadata class.
Definition: Metadata.h:24
AtomsCore namespace.
Definition: Agent.h:344