-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApproximationController.cpp
42 lines (38 loc) · 1.52 KB
/
ApproximationController.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
#include "ApproximationController.h"
#include "BaselProblemApproximatingAlgorithm.h"
#include "FactorialApproximatingAlgorithm.h"
#include "MonteCarloApproximatingAlgorithm.h"
#include "IntegrationApproximatingAlgorithm.h"
#include "WallisProductApproximatingAlgorithm.h"
#include "LeibnizFormulaApproximatingAlgorithm.h"
#include "HalfCircleAreaIntegrationApproximatingAlgorithm.h"
ApproximationController::ApproximationController()
{
algorithms.emplace_back(new BaselProblemApproximatingAlgorithm());
algorithms.emplace_back(new FactorialApproximatingAlgorithm());
algorithms.emplace_back(new MonteCarloApproximatingAlgorithm());
algorithms.emplace_back(new IntegrationApproximatingAlgorithm());
algorithms.emplace_back(new WallisProductApproximatingAlgorithm());
algorithms.emplace_back(new LeibnizFormulaApproximatingAlgorithm());
algorithms.emplace_back(new HalfCircleAreaIntegrationApproximatingAlgorithm());
}
double ApproximationController::approximate_pi(int accuracy_level, int algorithm) const
{
return (*algorithms[static_cast<int>(algorithm)])(accuracy_level);
}
int ApproximationController::implemented_algorithms_count() const
{
return algorithms.size();
}
ApproximationController & ApproximationController::get_approximation_controller()
{
static ApproximationController approximating_algorithm;
return approximating_algorithm;
}
std::vector<std::string> ApproximationController::get_names()
{
std::vector<std::string> result;
for (ApproxAlgoPtr& ptr : algorithms)
result.push_back(ptr->get_name());
return result;
}