Develop Biology
The language of life
Reaction.cpp
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) 2021 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
26
27namespace bio {
28namespace chemical {
29
31 Name name,
32 const Reactants* reactants
33)
34 :
35 chemical::Class< Reaction >(
36 this,
37 name,
38 &ReactionPerspective::Instance(),
39 filter::Chemical(),
40 symmetry_type::Operation()),
41 m_requiredReactants(*reactants)
42{
43}
44
45void Reaction::Require(Reactant* reactant)
46{
47 m_requiredReactants.Add< Substance* >(reactant);
48}
49
50void Reaction::Require(
51 Name typeName,
52 const Substance* substance
53)
54{
55 Require(
56 new Reactant(
57 typeName,
58 substance
59 ));
60}
61
62void Reaction::Require(
63 Name typeName,
66)
67{
68 Require(
69 new Reactant(
70 typeName,
71 properties,
72 states
73 ));
74}
75
76
77bool Reaction::ReactantsMeetRequirements(const Reactants* toCheck) const
78{
79 return toCheck->HasAll< Substance* >(m_requiredReactants.GetAll< Substance* >());
80}
81
82/*static*/ const Reaction* Reaction::Initiate(StandardDimension id)
83{
84 BIO_SANITIZE_WITH_CACHE(ReactionPerspective::Instance().GetTypeFromIdAs< Reaction* >(id),
85 return *(Cast< const Reaction** >(RESULT)),
86 return NULL);
87}
88
89Products Reaction::operator()(Reactants* reactants) const
90{
91 //Always level 2, even if the user wants more (i.e. never less).
92 BIO_SANITIZE_AT_SAFETY_LEVEL_2(ReactantsMeetRequirements(reactants),
93 return Process(reactants),
94 return code::FailedReaction());
95}
96
97} //chemical namespace
98} //bio namespace
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)
#define BIO_SANITIZE_WITH_CACHE(test, success, failure)
bool HasAll(const Container *contents) const
Code FailedReaction()
Filter Chemical()
SymmetryType Operation()
Definition: Cell.h:31
const char * Name
Definition: Types.h:46