-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMappingRegistry.cpp
More file actions
67 lines (50 loc) · 1.3 KB
/
MappingRegistry.cpp
File metadata and controls
67 lines (50 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "stdafx.h"
#include "MappingRegistry.h"
void swap(MappingRegistry &left, MappingRegistry &right)
{
using std::swap;
swap(left._mapCreators, right._mapCreators);
}
MappingRegistry::MappingRegistry()
{
}
MappingRegistry::MappingRegistry(const MappingRegistry &other) :
_mapCreators(other._mapCreators)
{
}
MappingRegistry::MappingRegistry(MappingRegistry &&other) :
MappingRegistry()
{
swap(*this, other);
}
MappingRegistry::~MappingRegistry()
{
}
MappingRegistry &MappingRegistry::operator =(MappingRegistry other)
{
swap(*this, other);
return *this;
}
void MappingRegistry::Register(const std::string &entityTypeName, const std::function<std::shared_ptr<IMappingProvider>()> &mapCreator)
{
_mapCreators[entityTypeName] = mapCreator;
}
std::shared_ptr<IMappingProvider> MappingRegistry::GetMapping(const std::string &entityTypeName) const
{
auto iter = _mapCreators.find(entityTypeName);
std::function<std::shared_ptr<IMappingProvider> ()> mappingCreator;
if (iter == _mapCreators.cend())
{
std::string message("Could not find mapping for class '");
message.append(entityTypeName);
message.append("'.");
std::exception e(message.c_str());
throw e;
}
else
{
mappingCreator = iter->second;
}
std::shared_ptr<IMappingProvider> mapping = mappingCreator();
return mapping;
}