VPTissue Reference Manual
ComponentFactoryProxy.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "ComponentFactoryProxy.h"
21 
22 #include "sim/CoreData.h"
23 
26 
27 
28 #include <stdexcept>
29 
30 namespace SimPT_Sim {
31 
32 using namespace std;
33 
34 template<typename T>
35 typename ComponentTraits<T>::ComponentType
36 ComponentFactoryProxy::CreateHelper(const CoreData& cd, bool default_ok, bool throw_ok) const
37 {
38  auto f = m_factory->Create(cd, T());
39  if (f == nullptr && default_ok) {
40  f = m_default->Create(cd, T());
41  }
42  if (f == nullptr && throw_ok) {
43  throw runtime_error("ComponentFactoryProxy::Create> Failed for " + ComponentTraits<T>::Label());
44  }
45 
46  return f;
47 }
48 
49 template<typename T>
50 vector<string>
51 ComponentFactoryProxy::ListHelper(bool default_ok) const
52 {
53  auto vec = m_factory->List(T());
54  if (default_ok) {
55  const auto v = m_default->List(T());
56  for (const auto& e : v) {
57  vec.push_back(e);
58  }
59  }
60  return vec;
61 }
62 
63 ComponentFactoryProxy::ComponentFactoryProxy(shared_ptr<ComponentFactoryBase> d, shared_ptr<ComponentFactoryBase> f)
64  : m_default(d), m_factory(f)
65 {
66 }
67 
68 shared_ptr<ComponentFactoryProxy> ComponentFactoryProxy::Create(const string& group_name, bool throw_ok)
69 {
70  const auto d = make_shared<SimPT_Default::ComponentFactory>() ;
71  shared_ptr<ComponentFactoryBase> f { nullptr };
72  if ( group_name == "Default" ) {
73  f = make_shared<SimPT_Default::ComponentFactory>();
74  } else if ( group_name == "Blad" ) {
75  f = std::make_shared<SimPT_Blad::ComponentFactory>();
76  }
77 
78  if (f == nullptr && throw_ok) {
79  throw runtime_error(
80  "ComponentFactoryProxy::ComponetFactoryProxy()> No such factory available for " + group_name);
81  }
82 
83  return shared_ptr<ComponentFactoryProxy>(new ComponentFactoryProxy(d, f));
84 }
85 
86 CellChemistryComponent ComponentFactoryProxy::CreateCellChemistry(const CoreData& cd, bool default_ok, bool throw_ok) const
87 {
88  return CreateHelper<CellChemistryTag>(cd, default_ok, throw_ok);
89 }
90 
91 
92 CellColorComponent ComponentFactoryProxy::CreateCellColor(const string& select, const ptree& pt, bool default_ok, bool throw_ok) const
93 {
94  auto f = m_factory->Create(select, pt, CellColorTag());
95  if (f == nullptr && default_ok) {
96  f = m_default->Create(select, pt, CellColorTag());
97  }
98  if (f == nullptr && throw_ok) {
99  throw runtime_error("ComponentFactoryProxy::Create> Failed for " + ComponentTraits<CellColorTag>::Label());
100  }
101 
102  return f;
103 }
104 
105 CellDaughtersComponent ComponentFactoryProxy::CreateCellDaughters(const CoreData& cd, bool default_ok, bool throw_ok) const
106 {
107  return CreateHelper<CellDaughtersTag>(cd, default_ok, throw_ok);
108 }
109 
110 CellHousekeepComponent ComponentFactoryProxy::CreateCellHousekeep(const CoreData& cd, bool default_ok, bool throw_ok) const
111 {
112  return CreateHelper<CellHousekeepTag>(cd, default_ok, throw_ok);
113 }
114 
115 CellSplitComponent ComponentFactoryProxy::CreateCellSplit(const CoreData& cd, bool default_ok, bool throw_ok) const
116 {
117  return CreateHelper<CellSplitTag>(cd, default_ok, throw_ok);
118 }
119 
121 {
122  return CreateHelper<CellToCellTransportTag>(cd, default_ok, throw_ok);
123 }
124 
126 {
127  return CreateHelper<DeltaHamiltonianTag>(cd, default_ok, throw_ok);
128 }
129 
130 HamiltonianComponent ComponentFactoryProxy::CreateHamiltonian(const CoreData& cd, bool default_ok, bool throw_ok) const
131 {
132  return CreateHelper<HamiltonianTag>(cd, default_ok, throw_ok);
133 }
134 
135 MoveGeneratorComponent ComponentFactoryProxy::CreateMoveGenerator(const CoreData& cd, bool default_ok, bool throw_ok) const
136 {
137  return CreateHelper<MoveGeneratorTag>(cd, default_ok, throw_ok);
138 }
139 
140 TimeEvolverComponent ComponentFactoryProxy::CreateTimeEvolver(const CoreData& cd, bool default_ok, bool throw_ok) const
141 {
142  return CreateHelper<TimeEvolverTag>(cd, default_ok, throw_ok);
143 }
144 
145 WallChemistryComponent ComponentFactoryProxy::CreateWallChemistry(const CoreData& cd, bool default_ok, bool throw_ok) const
146 {
147  return CreateHelper<WallChemistryTag>(cd, default_ok, throw_ok);
148 }
149 
150 vector<string> ComponentFactoryProxy::ListCellChemistry(bool default_ok) const
151 {
152  return ListHelper<CellChemistryTag>(default_ok);
153 }
154 
155 vector<string> ComponentFactoryProxy::ListCellColor(bool default_ok) const
156 {
157  return ListHelper<CellColorTag>(default_ok);
158 }
159 
160 vector<string> ComponentFactoryProxy::ListCellDaughters(bool default_ok) const
161 {
162  return ListHelper<CellDaughtersTag>(default_ok);
163 }
164 
165 vector<string> ComponentFactoryProxy::ListCellHousekeep(bool default_ok) const
166 {
167  return ListHelper<CellHousekeepTag>(default_ok);
168 }
169 
170 vector<string> ComponentFactoryProxy::ListCellSplit(bool default_ok) const
171 {
172  return ListHelper<CellSplitTag>(default_ok);
173 }
174 
175 vector<string> ComponentFactoryProxy::ListCellToCellTransport(bool default_ok) const
176 {
177  return ListHelper<CellToCellTransportTag>(default_ok);
178 }
179 
180 vector<string> ComponentFactoryProxy::ListDeltaHamiltonian(bool default_ok) const
181 {
182  return ListHelper<DeltaHamiltonianTag>(default_ok);
183 }
184 
185 vector<string> ComponentFactoryProxy::ListHamiltonian(bool default_ok) const
186 {
187  return ListHelper<HamiltonianTag>(default_ok);
188 }
189 
190 vector<string> ComponentFactoryProxy::ListMoveGenerator(bool default_ok) const
191 {
192  return ListHelper<MoveGeneratorTag>(default_ok);
193 }
194 
195 vector<string> ComponentFactoryProxy::ListTimeEvolver(bool default_ok) const
196 {
197  return ListHelper<TimeEvolverTag>(default_ok);
198 }
199 
200 vector<string> ComponentFactoryProxy::ListWallChemistry(bool default_ok) const
201 {
202  return ListHelper<WallChemistryTag>(default_ok);
203 }
204 
205 } // namespace
std::function< double(Cell *)> HamiltonianComponent
Hamiltonian component interface.
CellSplitComponent CreateCellSplit(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a CellSplit component.
std::function< double(const NeighborNodes &, Node *, std::array< double, 3 >)> DeltaHamiltonianComponent
DeltaHamiltonian component interface.
Core data with mesh, parameters, random engine and time data.
Definition: CoreData.h:38
STL namespace.
Core data used during model execution.
std::function< std::tuple< bool, bool, std::array< double, 3 >>(Cell *)> CellSplitComponent
CellSplit component interface.
std::function< std::array< double, 3 >()> MoveGeneratorComponent
MoveGenerator component interface.
Used in tag forwarding.
MoveGeneratorComponent CreateMoveGenerator(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a CellSplit component.
std::vector< std::string > ListCellSplit(bool default_ok=true) const
List components for CellSplit.
static std::shared_ptr< ComponentFactoryProxy > Create(const string &group_name, bool throw_ok=true)
Create a factory proxy.
std::function< void(Cell *, Cell *)> CellDaughtersComponent
CellDaughters component interface.
CellToCellTransportComponent CreateCellToCellTransport(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a CellToCellTransport component.
Namespace for the core simulator.
Component factory for SimPT_Default model group.
std::vector< std::string > ListTimeEvolver(bool default_ok=true) const
List components for TimeEvolver.
CellHousekeepComponent CreateCellHousekeep(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a CellHouskeep component.
std::vector< std::string > ListDeltaHamiltonian(bool default_ok=true) const
List components for DeltaHamiltonian.
CellColorComponent CreateCellColor(const string &select, const ptree &pt, bool default_ok=true, bool throw_ok=true) const
Create a CellColor component.
Proxy for dealing with the factories.
std::vector< std::string > ListCellColor(bool default_ok=true) const
List components for CellColor.
WallChemistryComponent CreateWallChemistry(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a WallChemistry component.
std::function< void(Cell *, double *)> CellChemistryComponent
CellChemistry component interface.
std::vector< std::string > ListCellDaughters(bool default_ok=true) const
List components for CellDaughters.
std::function< void(Cell *)> CellHousekeepComponent
CellHousekeep component interface.
Primary template never gets instantiated.
std::vector< std::string > ListCellHousekeep(bool default_ok=true) const
List components for CellHouseKeep.
Component factory for the Blad model group.
CellDaughtersComponent CreateCellDaughters(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a CellDaughters component.
std::function< void(Wall *, double *, double *)> WallChemistryComponent
Wall chemistry component interface.
HamiltonianComponent CreateHamiltonian(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a Hamiltonian component.
std::vector< std::string > ListMoveGenerator(bool default_ok=true) const
List components for MoveGenerator.
std::vector< std::string > ListCellToCellTransport(bool default_ok=true) const
List components for CellToCellTransport.
std::vector< std::string > ListHamiltonian(bool default_ok=true) const
List components for Hamiltonian.
Proxy for interaction with Component Factory of model families.
DeltaHamiltonianComponent CreateDeltaHamiltonian(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a DeltaHamiltonian component.
std::function< std::array< double, 3 >(Cell *)> CellColorComponent
CellColor component interface.
CellChemistryComponent CreateCellChemistry(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a CellChemistry component.
std::function< std::tuple< SimTimingTraits::CumulativeTimings, bool >(double, SimPhase)> TimeEvolverComponent
Time Evolver component interface.
std::vector< std::string > ListCellChemistry(bool default_ok=true) const
List components for CellChemistry.
std::function< void(Wall *, double *, double *)> CellToCellTransportComponent
CellToCellTransport component interface.
TimeEvolverComponent CreateTimeEvolver(const CoreData &cd, bool default_ok=true, bool throw_ok=true) const
Create a TimeEvolver component.
std::vector< std::string > ListWallChemistry(bool default_ok=true) const
List components for WallChemistry.