Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: combine Algorithm.h and AlgorithmFactory.h #83

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/iguana/algorithms/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,35 @@ namespace iguana {
bool m_rows_only;

};

//////////////////////////////////////////////////////////////////////////////

/// Algorithm pointer type
using algo_t = std::unique_ptr<Algorithm>;

/// @brief Factory to create an algorithm.
class AlgorithmFactory {

public:

/// Algorithm creator function type
using algo_creator_t = std::function<algo_t()>;

AlgorithmFactory() = delete;

/// Register an algorithm with a unique name. Algorithms register themselves by calling this function.
/// @param name the name of the algorithm (not equivalent to `Object::m_name`)
/// @param creator the creator function
static bool Register(const std::string& name, algo_creator_t creator) noexcept;

/// Create an algorithm.
/// @param name the name of the algorithm, which was used as an argument in the `AlgorithmFactory::Register` call
static algo_t Create(const std::string& name) noexcept;

private:

/// Association between the algorithm names and their creators
static std::unordered_map<std::string, algo_creator_t> s_creators;

};
}
2 changes: 1 addition & 1 deletion src/iguana/algorithms/AlgorithmFactory.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AlgorithmFactory.h"
#include "Algorithm.h"

namespace iguana {

Expand Down
35 changes: 0 additions & 35 deletions src/iguana/algorithms/AlgorithmFactory.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/iguana/algorithms/AlgorithmSequence.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "AlgorithmFactory.h"
#include "Algorithm.h"

namespace iguana {

Expand Down
2 changes: 1 addition & 1 deletion src/iguana/algorithms/clas12/EventBuilderFilter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "iguana/algorithms/AlgorithmFactory.h"
#include "iguana/algorithms/Algorithm.h"

namespace iguana::clas12 {

Expand Down
2 changes: 1 addition & 1 deletion src/iguana/algorithms/clas12/LorentzTransformer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "iguana/algorithms/AlgorithmFactory.h"
#include "iguana/algorithms/Algorithm.h"
#include <tuple>

namespace iguana::clas12 {
Expand Down
4 changes: 2 additions & 2 deletions src/iguana/algorithms/example/ExampleAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#pragma once

//############################################################################
//# include `AlgorithmFactory`, so that we may register this algorithm for factory creation
//# include `Algorithm.h`, which defines the base class `Algorithm`
//############################################################################
#include "iguana/algorithms/AlgorithmFactory.h"
#include "iguana/algorithms/Algorithm.h"

//############################################################################
//# define the namespace
Expand Down
1 change: 0 additions & 1 deletion src/iguana/algorithms/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ algo_sources = [
algo_public_headers = [
'Algorithm.h',
'AlgorithmBoilerplate.h',
'AlgorithmFactory.h',
'AlgorithmSequence.h',
'example/ExampleAlgorithm.h',
'clas12/EventBuilderFilter.h',
Expand Down