Develop Biology
The language of life
Reaction.h
Go to the documentation of this file.
1/*
2 * This file is a part of the Biology project by eons LLC.
3 * Biology (aka Develop Biology) is a framework for approaching software
4 * development from a natural sciences perspective.
5 *
6 * Copyright (C) 2022 Séon O'Shannon & eons LLC
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
25#include "Reactants.h"
26#include "Products.h"
32#include "bio/common/TypeName.h"
33
34namespace bio {
35namespace chemical {
36
74class Reaction :
75 public chemical::Class< Reaction >,
76 virtual public Structure //for use in LinearMotifs downstream, we must have interface methods available, even though Reaction does not directly contain anything.
77{
78public:
79
85
90 &ReactionPerspective::Instance(),
93
94
98 explicit Reaction(
99 Name name,
101 );
102
109 virtual void Require(Reactant* reactant);
110
117 void Require(
118 Name typeName,
119 const Substance* substance
120 );
121
130 Name typeName,
131 const typename UnorderedMotif< Property >::Contents* properties,
132 const typename UnorderedMotif< State >::Contents* states
133 );
134
141 template < typename T >
142 void Require()
143 {
144 Properties empty;
145 States enabled;
146 enabled.push_back(state::Enabled());
147 Require(
148 TypeName< T >(),
149 empty,
150 enabled
151 );
152 }
153
160 template < typename T >
161 void Require(const T* substance)
162 {
163 Require(
164 TypeName< T >(),
165 substance
166 );
167 }
168
174 template < typename T >
176 const typename UnorderedMotif< Property >::Contents* properties,
177 const typename UnorderedMotif< State >::Contents* states
178 )
179 {
180 Require(
181 TypeName< T >(),
182 properties,
183 states
184 );
185 }
186
194 {
195
196 // YOUR CODE GOES HERE
197
199 }
200
208 virtual bool ReactantsMeetRequirements(const Reactants* toCheck) const;
209
216 virtual Products operator()(Reactants* reactants) const;
217
225 static const Reaction* Initiate(StandardDimension id);
226
234 template < typename T >
235 static const T* Initiate()
236 {
237 const T* ret = ReactionPerspective::Instance().template GetTypeFromNameAs< T >(TypeName< T >());
239 return ret,
240 return NULL);
241 }
242
249 template < typename T >
251 {
252 BIO_SANITIZE_WITH_CACHE(Initiate< T >(),
253 return (*Cast< const T* >(RESULT))(reactants),
254 return Products(
257 ));
258 }
259
260 template < typename T >
261 static Products Attempt(Substances& substances)
262 {
263 Reactants reactants(substances);
264 BIO_SANITIZE_WITH_CACHE(Initiate< T >(),
265 return (*Cast< const T* >(RESULT))(&reactants),
266 return Products(
269 ));
270 }
271
281 template < typename T >
283 Substance* reactant1,
284 Substance* reactant2 = NULL,
285 Substance* reactant3 = NULL
286 )
287 {
288 Substances substances;
289 substances.push_back(reactant1);
290 substances.push_back(reactant2);
291 substances.push_back(reactant3);
292 Reactants reactants(substances);
293 return Attempt< T >(&reactants);
294 }
295
296protected:
298};
299
300} //chemical namespace
301} //bio namespace
#define BIO_DEFAULT_IDENTIFIABLE_CONSTRUCTORS(ns, class,...)
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)
#define BIO_SANITIZE_WITH_CACHE(test, success, failure)
static Products Attempt(Substances &substances)
Definition: Reaction.h:261
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(chemical, Reaction) BIO_DEFAULT_IDENTIFIABLE_CONSTRUCTORS(chemical
virtual bool ReactantsMeetRequirements(const Reactants *toCheck) const
Definition: Reaction.cpp:77
static Products Attempt(Reactants *reactants)
Definition: Reaction.h:250
Reactants m_requiredReactants
Definition: Reaction.h:297
const Reactants * reactants
Definition: Reaction.h:101
static const T * Initiate()
Definition: Reaction.h:235
virtual Products operator()(Reactants *reactants) const
Definition: Reaction.cpp:89
static Products Attempt(Substance *reactant1, Substance *reactant2=NULL, Substance *reactant3=NULL)
Definition: Reaction.h:282
void Require(const typename UnorderedMotif< Property >::Contents *properties, const typename UnorderedMotif< State >::Contents *states)
Definition: Reaction.h:175
void Require(const T *substance)
Definition: Reaction.h:161
& ReactionPerspective::Instance()
virtual Products Process(Reactants *reactants) const
Definition: Reaction.h:193
std::vector< Substance * > Substances
Definition: Types.h:79
Code NotImplemented()
Filter Chemical()
State Enabled()
SymmetryType Operation()
Definition: Cell.h:31
const char * Name
Definition: Types.h:46
uint8_t Properties
Definition: Types.h:58