-
Notifications
You must be signed in to change notification settings - Fork 0
/
trafficgeneratorfactory.cpp
75 lines (61 loc) · 1.78 KB
/
trafficgeneratorfactory.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
75
/*
* trafficgeneratorfactory.cpp
* PhoenixSim
*
* Created by Johnnie Chan on 7/8/11.
* Copyright 2011 Johnnie Chan. All rights reserved.
*
*/
#include "trafficgeneratorfactory.h"
#include <stdexcept>
#include <iostream>
using namespace std;
using namespace PhoenixSim;
TrafficGeneratorFactory* TrafficGeneratorFactory::instance = NULL;
TrafficGeneratorFactoryDemolisher TrafficGeneratorFactory::demolisher;
TrafficGeneratorFactory* TrafficGeneratorFactory::Instance()
{
if(instance == NULL)
{
instance = new TrafficGeneratorFactory;
demolisher.SetInstancePointer(instance);
}
return instance;
}
TrafficGeneratorFactory::TrafficGeneratorFactory()
{
}
TrafficGeneratorFactory::TrafficGeneratorFactory(const TrafficGeneratorFactory&)
{
}
TrafficGeneratorFactory::~TrafficGeneratorFactory()
{
}
bool TrafficGeneratorFactory::RegisterTrafficGenerator(CreateTrafficGeneratorCallback createFunction, string identifier)
{
return callbackFunctions.insert( pair<string, CreateTrafficGeneratorCallback>(identifier, createFunction)).second;
}
bool TrafficGeneratorFactory::UnregisterTrafficGenerator(string identifier)
{
return callbackFunctions.erase(identifier) == 1;
}
TrafficGenerator* TrafficGeneratorFactory::CreateTrafficGenerator(string identifier)
{
CreateTrafficGeneratorMap::const_iterator it = callbackFunctions.find(identifier);
if(it == callbackFunctions.end())
{
throw logic_error("in 'routingpolicyfactory.cpp' - Unknown routing policy identifier. (" + identifier + ")");
}
return (it->second)();
}
TrafficGeneratorFactoryDemolisher::TrafficGeneratorFactoryDemolisher()
{
}
TrafficGeneratorFactoryDemolisher::~TrafficGeneratorFactoryDemolisher()
{
delete instance;
}
void TrafficGeneratorFactoryDemolisher::SetInstancePointer(TrafficGeneratorFactory* p)
{
instance = p;
}