-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactory.hpp
More file actions
109 lines (86 loc) · 2.8 KB
/
factory.hpp
File metadata and controls
109 lines (86 loc) · 2.8 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* This file is part of the headcode.space crypt.
*
* The 'LICENSE.txt' file in the project root holds the software license.
* Copyright (C) 2020-2021 headcode.space e.U.
* Oliver Maurhart <info@headcode.space>, https://www.headcode.space
*/
#ifndef HEADCODE_SPACE_CRYPT_FACTORY_HPP
#define HEADCODE_SPACE_CRYPT_FACTORY_HPP
#include <map>
#include <memory>
#include <string>
#include "algorithm.hpp"
#include "family.hpp"
namespace headcode::crypt {
/**
* @brief The Algorithm factory.
*/
class Factory {
public:
/**
* @brief Each concrete algorithm declares a dedicated Producer.
* The factory does not manage algorithm instances but producer instances,
* which in turn create new algorithm objects on demand.
* Every algorithm has to declare its (proper) Producer class.
*/
class Producer {
public:
/**
* @brief Call operator - creates the algorithm.
* @return A new algorithm instance.
*/
virtual std::unique_ptr<Algorithm> operator()() const = 0;
/**
* @brief Gets the algorithm description.
* @return A structure describing the algorithm.
*/
virtual Algorithm::Description const & GetDescription() const = 0;
};
/**
* @brief Constructor.
*/
Factory() = delete;
/**
* @brief Copy Constructor.
*/
Factory(Factory const &) = delete;
/**
* @brief Move Constructor.
*/
Factory(Factory &&) = delete;
/**
* @brief Destructor.
*/
~Factory() = delete;
/**
* @brief Assignment.
* @return this.
*/
Factory & operator=(Factory const &) = delete;
/**
* @brief Move Assignment.
* @return this.
*/
Factory & operator=(Factory &&) = delete;
/**
* @brief Create an instance of a specific algorithm.
* @param name the name of the algorithm to create.
* @return A shared pointer pointing to an object (which may be nullptr in case of failure).
*/
static std::unique_ptr<Algorithm> Create(std::string const & name);
/**
* @brief Gets a list of all known algorithms and their descriptions.
* @return A list of all algorithms which can be instantiated incl. their descriptions.
*/
static std::map<std::string, Algorithm::Description> const & GetAlgorithmDescriptions();
/**
* @brief Registers a producer, which can create algorithm instance of a specific name and family.
* @param name the name of the algorithm to be registered.
* @param family the family to which the algorithm belongs to.
* @param producer the Producer instance.
*/
static void Register(std::string const & name, Family family, std::shared_ptr<Factory::Producer> producer);
};
}
#endif