BioDynaMo  v1.05.120-25dc9790
operation_registry.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_OPERATION_OPERATION_REGISTRY_H_
16 #define CORE_OPERATION_OPERATION_REGISTRY_H_
17 
19 
20 #include <unordered_map>
21 
22 namespace bdm {
23 
28  public:
31 
38  Operation *GetOperation(const std::string &op_name);
39 
50  bool AddOperationImpl(const std::string &op_name, OpComputeTarget target,
51  OperationImpl *impl, uint32_t frequency = 1);
52 
53  private:
55  std::unordered_map<std::string, Operation *> operations_;
56 
59 };
60 
64 #define BDM_REGISTER_OP(op, name, target) \
65  bool op::registered_ = OperationRegistry::GetInstance()->AddOperationImpl( \
66  name, OpComputeTarget::target, new op());
67 
71 #define BDM_REGISTER_OP_WITH_FREQ(op, name, target, frequency) \
72  bool op::registered_ = OperationRegistry::GetInstance()->AddOperationImpl( \
73  name, OpComputeTarget::target, new op(), frequency);
74 
78 #define BDM_REGISTER_TEMPLATE_OP(op, T, name, target) \
79  template <> \
80  bool op<T>::registered_ = \
81  OperationRegistry::GetInstance()->AddOperationImpl( \
82  name, OpComputeTarget::target, new op<T>());
83 
85 inline Operation *NewOperation(const std::string &name) {
87 }
88 
91 #define BDM_OP_HEADER(class_name) \
92  private: \
93  static bool registered_; \
94  \
95  public: \
96  class_name *Clone() override { return new class_name(*this); }
97 
98 } // namespace bdm
99 
100 #endif // CORE_OPERATION_OPERATION_REGISTRY_H_
bdm::OperationRegistry::~OperationRegistry
~OperationRegistry()
Definition: operation_registry.cc:19
bdm::OperationRegistry::GetOperation
Operation * GetOperation(const std::string &op_name)
Definition: operation_registry.cc:30
bdm
Definition: agent.cc:39
operation.h
bdm::OperationImpl
Definition: operation.h:46
bdm::Operation::Clone
Operation * Clone()
Definition: operation.cc:32
bdm::OperationRegistry::AddOperationImpl
bool AddOperationImpl(const std::string &op_name, OpComputeTarget target, OperationImpl *impl, uint32_t frequency=1)
Definition: operation_registry.cc:39
bdm::OpComputeTarget
OpComputeTarget
Definition: operation.h:31
bdm::OperationRegistry::OperationRegistry
OperationRegistry()
bdm::OperationRegistry::GetInstance
static OperationRegistry * GetInstance()
Singleton class - returns the static instance.
Definition: operation_registry.cc:25
bdm::NewOperation
Operation * NewOperation(const std::string &name)
A convenient function to get a new operation from the registry by its name.
Definition: operation_registry.h:85
bdm::OperationRegistry::operations_
std::unordered_map< std::string, Operation * > operations_
The map containing the operations; accessible by their name.
Definition: operation_registry.h:55
bdm::Operation
Definition: operation.h:99
bdm::OperationRegistry
Definition: operation_registry.h:27