-
Notifications
You must be signed in to change notification settings - Fork 0
/
routingpolicyfactory.cpp
74 lines (61 loc) · 1.68 KB
/
routingpolicyfactory.cpp
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
68
69
70
71
72
73
74
/*
* routingpolicyfactory.cpp
* PhoenixSim
*
* Created by Johnnie Chan on 6/23/11.
* Copyright 2011 Johnnie Chan. All rights reserved.
*
*/
#include <stdexcept>
#include <iostream>
#include "routingpolicyfactory.h"
using namespace std;
using namespace PhoenixSim;
RoutingPolicyFactory* RoutingPolicyFactory::instance = NULL;
RoutingPolicyFactoryDemolisher RoutingPolicyFactory::demolisher;
RoutingPolicyFactory* RoutingPolicyFactory::Instance()
{
if(instance == NULL)
{
instance = new RoutingPolicyFactory;
demolisher.SetInstancePointer(instance);
}
return instance;
}
RoutingPolicyFactory::RoutingPolicyFactory()
{
}
RoutingPolicyFactory::RoutingPolicyFactory(const RoutingPolicyFactory&)
{
}
RoutingPolicyFactory::~RoutingPolicyFactory()
{
}
bool RoutingPolicyFactory::RegisterRoutingPolicy(CreateRoutingPolicyCallback createFunction, string identifier)
{
return callbackFunctions.insert( pair<string, CreateRoutingPolicyCallback>(identifier, createFunction)).second;
}
bool RoutingPolicyFactory::UnregisterRoutingPolicy(string identifier)
{
return callbackFunctions.erase(identifier) == 1;
}
RoutingPolicy* RoutingPolicyFactory::CreateRoutingPolicy(string identifier)
{
CreateRoutingPolicyMap::const_iterator it = callbackFunctions.find(identifier);
if(it == callbackFunctions.end())
{
throw logic_error("in 'routingpolicyfactory.cpp' - Unknown routing policy identifier. (" + identifier + ")");
}
return (it->second)();
}
RoutingPolicyFactoryDemolisher::RoutingPolicyFactoryDemolisher()
{
}
RoutingPolicyFactoryDemolisher::~RoutingPolicyFactoryDemolisher()
{
delete instance;
}
void RoutingPolicyFactoryDemolisher::SetInstancePointer(RoutingPolicyFactory* p)
{
instance = p;
}