Skip to content

Commit

Permalink
fix: combine Algorithm.h and AlgorithmFactory.h (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks authored Jan 17, 2024
1 parent b36e586 commit 262373b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 42 deletions.
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

0 comments on commit 262373b

Please sign in to comment.