1#ifndef ALGORITHM_DEFINED
2#define ALGORITHM_DEFINED
16 Argument(std::string
const &name_, std::string
const &data_)
28 Algorithm(std::vector<Argument>
const &argumentList);
31 virtual void run() = 0;
41 std::string
const &defaultValue);
46 int64_t
const defaultValue);
49 real
const defaultValue);
50 template <
typename F = real,
typename T = Tensor<F>>
52 template <
typename F = real,
typename C = std::vector<F>>
54 template <
typename F = real,
typename C = std::vector<F>>
59 std::vector<std::string> names;
60 for (
const auto &p :
arguments) { names.push_back(p.first); }
69 for (
const auto &p : actualArguments) {
70 if (std::count(args.begin(), args.end(), p) != 1) {
71 s <<
"Error: parameter (" << p <<
") unknown";
89 template <
typename F = real,
typename T = Tensor<F>>
91 void setRealArgument(std::string
const &argumentName, real
const value);
97 template <
typename F = real,
typename T = Tensor<F>>
107 std::map<std::string,
108 std::function<
Algorithm *(std::vector<Argument>
const &)>>;
118 std::vector<Argument>
const &arguments) {
120 return iterator !=
getAlgorithmMap()->end() ? iterator->second(arguments)
125 std::vector<std::string> result;
126 for (
auto const &kv : *
algorithmMap) result.push_back(kv.first);
140template <
typename AlgorithmType>
142 return new AlgorithmType(arguments);
150template <
typename AlgorithmType>
169#define ALGORITHM_REGISTRAR_DECLARATION(NAME) \
170 virtual std::string getName() { return #NAME; } \
171 static sisi4s::AlgorithmRegistrar<NAME> registrar_
178#define ALGORITHM_REGISTRAR_DEFINITION(NAME) \
179 sisi4s::AlgorithmRegistrar<NAME> NAME::registrar_(#NAME)
181#define IMPLEMENT_ALGORITHM(NAME) \
182 ALGORITHM_REGISTRAR_DEFINITION(NAME); \
185#define DEFINE_ALGORITHM_HEADER(NAME, ...) \
186 class NAME : public Algorithm { \
188 ALGORITHM_REGISTRAR_DECLARATION(NAME); \
189 NAME(std::vector<Argument> const &argumentList) \
190 : Algorithm(argumentList) {} \
192 virtual void run(); \
#define EXCEPTION(message)
Definition Exception.hpp:8
Definition Algorithm.hpp:104
static Algorithm * create(std::string const &name, std::vector< Argument > const &arguments)
Creates an algorithm object of the algorithm type specified by the given name. The given arguments ar...
Definition Algorithm.hpp:117
static AlgorithmMap * algorithmMap
Definition Algorithm.hpp:134
static std::vector< std::string > getAlgorithmNames()
Definition Algorithm.hpp:124
static AlgorithmMap * getAlgorithmMap()
Definition Algorithm.hpp:131
std::map< std::string, std::function< Algorithm *(std::vector< Argument > const &)> > AlgorithmMap
Definition Algorithm.hpp:108
Class to be statically instantiated by an algorithm to register it in the AlgorithmFactory....
Definition Algorithm.hpp:151
AlgorithmRegistrar(std::string const &name)
Constructs the registrating instance. The algorithm type must be given as template argument,...
Definition Algorithm.hpp:158
Definition Algorithm.hpp:26
virtual void dryRun()
The dryRun estimates resource consumption, especially memory and processor time.
Definition Algorithm.cxx:29
real getRealArgumentFromInteger(IntegerData *data)
Definition Algorithm.cxx:138
Data * getArgumentData(std::string const &argumentName)
Definition Algorithm.cxx:37
bool fallible
Definition Algorithm.hpp:35
T * getTensorArgument(std::string const &argumentName)
Definition Algorithm.cxx:190
real getRealArgument(std::string const &argumentName)
Definition Algorithm.cxx:121
void allocatedTensorArgument(std::string const &argumentName, T *tensor)
Specifies the location of an output tensor data.
Definition Algorithm.cxx:289
C * getContainerArgument(std::string const &argumentName)
Definition Algorithm.cxx:157
int64_t getIntegerArgument(std::string const &argumentName)
Definition Algorithm.cxx:100
std::string getTextArgument(std::string const &argumentName)
Definition Algorithm.cxx:57
bool getBooleanArgument(std::string const &name)
Definition Algorithm.cxx:77
real getRealArgumentFromTensor(TensorData< real > *data)
Definition Algorithm.cxx:147
void checkArgumentsOrDie(const std::vector< std::string > args) const
Definition Algorithm.hpp:66
T * getTensorArgumentFromReal(RealData *realData)
Converts the given real data into a scalar tensor.
Definition Algorithm.cxx:271
std::string note
Definition Algorithm.hpp:34
std::vector< std::string > getGivenArgumentNames() const
Definition Algorithm.hpp:58
virtual std::string getName()=0
virtual ~Algorithm()
Definition Algorithm.cxx:23
void setIntegerArgument(std::string const &argumentName, int const value)
Definition Algorithm.cxx:369
bool isArgumentGiven(std::string const &argumentName)
Definition Algorithm.cxx:33
void allocateContainerArgument(std::string const &argumentName, C *container)
Definition Algorithm.cxx:170
void setRealArgument(std::string const &argumentName, real const value)
Definition Algorithm.cxx:364
std::map< std::string, std::string > arguments
Definition Algorithm.hpp:101
Definition Algorithm.hpp:11
std::string name
Definition Algorithm.hpp:23
Argument(std::string const &name_)
Definition Algorithm.hpp:13
std::string const & getData() const
Definition Algorithm.hpp:20
Argument(std::string const &name_, std::string const &data_)
Definition Algorithm.hpp:16
std::string data
Definition Algorithm.hpp:23
std::string const & getName() const
Definition Algorithm.hpp:19
Definition Algorithm.hpp:10
Algorithm * createAlgorithm(std::vector< Argument > const &arguments)
template function creating an instance of the given class.
Definition Algorithm.hpp:141