Develop Biology
The language of life
Surface.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 molecular {
29
31 Name name,
32 Molecule* environment
33)
34 :
35 molecular::Class< Surface >(
36 this,
37 name,
38 environment,
39 filter::Molecular(),
40 symmetry_type::Variable()),
41 EnvironmentDependent< Molecule >(environment)
42{
43
44}
45
46Surface::Surface(const Surface& toCopy)
47 :
48 molecular::Class< Surface >(
49 this,
50 toCopy.GetName(),
51 toCopy.GetPerspective(),
52 toCopy.GetFilter(),
53 symmetry_type::Variable()),
54 chemical::LinearMotif< Molecule* >(toCopy),
56{
57 chemical::Bond* bondBuffer;
58 for (
59 SmartIterator bnd = toCopy.m_bonds.End();
60 !bnd.IsAtBeginning();
61 --bnd
62 )
63 {
64 bondBuffer = bnd;
65 if (bondBuffer->GetType() == bond_type::Manage())
66 {
67 //Calling FormBondImplementation directly saves us some work and should be safer than trying to do auto-template type determination from Clone().
69 bondBuffer->GetBonded()->Clone(),
70 bondBuffer->GetId(),
71 bondBuffer->GetType());
72 }
73 }
74}
75
77{
78 chemical::Bond* bondBuffer;
79 for (
81 !bnd.IsAtBeginning();
82 --bnd
83 )
84 {
85 bondBuffer = bnd;
86 if (bondBuffer->GetType() == bond_type::Manage())
87 {
88 //bypass BreakBondImplementation and just do it.
89 delete bondBuffer->GetBonded();
90 bondBuffer->Break();
91 }
92 }
93}
94
96{
98 SetId(0); //0 should always be invalid.
100}
101
103{
105}
106
108{
109 //TODO...
110 return code::NotImplemented();
111}
112
114{
115 //TODO...
116 return NULL;
117}
118
120 physical::Wave* toRelease,
121 BondType bondType
122)
123{
124 physical::Wave* ret = NULL;
125 chemical::Bond* bondBuffer;
126 for (
127 SmartIterator bnd = m_bonds.End();
128 !bnd.IsAtBeginning();
129 --bnd
130 )
131 {
132 bondBuffer = bnd;
133 if (bondBuffer->GetType() == bondType)
134 {
135 ret = ChemicalCast< physical::Wave* >(bondBuffer->GetBonded());
136 BIO_SANITIZE_AT_SAFETY_LEVEL_2(!ret || ret != toRelease,
137 continue,);
138 bondBuffer->Break();
139 break;
140 }
141 }
142 return ret;
143}
144
146 Name toRelease,
148 BondType bondType
149)
150{
151 chemical::Substance* ret = NULL;
152 chemical::Bond* bondBuffer;
153 for (
154 SmartIterator bnd = m_bonds.End();
155 !bnd.IsAtBeginning();
156 --bnd
157 )
158 {
159 bondBuffer = bnd;
160 if (bondBuffer->GetType() == bondType)
161 {
162 ret = ChemicalCast< chemical::Substance* >(bondBuffer->GetBonded());
164 continue);
165 BIO_SANITIZE_AT_SAFETY_LEVEL_2(ret->IsName(toRelease), ,
166 continue);
168 continue,);
169 bondBuffer->Break();
170 break;
171 }
172 }
173 return ret;
174}
175
177 StandardDimension toRelease,
179 BondType bondType
180)
181{
182 chemical::Substance* ret = NULL;
183 chemical::Bond* bondBuffer;
184 for (
185 SmartIterator bnd = m_bonds.End();
186 !bnd.IsAtBeginning();
187 --bnd
188 )
189 {
190 bondBuffer = bnd;
191 if (bondBuffer->GetType() == bondType)
192 {
193 ret = ChemicalCast< chemical::Substance* >(bondBuffer->GetBonded());
195 continue);
196 BIO_SANITIZE_AT_SAFETY_LEVEL_2(ret->IsId(toRelease), ,
197 continue);
199 continue,);
200 bondBuffer->Break();
201 break;
202 }
203 }
204 return ret;
205}
206
208{
209 physical::Waves ret;
210 chemical::Bond* bondBuffer;
211 for (
212 SmartIterator bnd = m_bonds.End();
213 !bnd.IsAtBeginning();
214 --bnd
215 )
216 {
217 bondBuffer = bnd;
218 if (bondBuffer->GetType() == bondType)
219 {
220 ret.push_back(ChemicalCast< physical::Wave* >(bondBuffer->GetBonded()));
221 bondBuffer->Break();
222 }
223 }
224 return ret;
225}
226
228{
229 return Release(toRelease);
230}
231
233{
234 return Release(toRelease);
235}
236
237chemical::Substance* Surface::operator-=(StandardDimension toRelease)
238{
239 return Release(toRelease);
240}
241
243{
244 return ReleaseAll();
245}
246
247
248} //molecular namespace
249} //bio namespace
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)
virtual SmartIterator End() const
Definition: Container.cpp:302
bool IsAtBeginning() const
virtual bool FormBondImplementation(Wave *toBond, AtomicNumber id, BondType type)
Definition: Atom.cpp:117
BondType GetType() const
Definition: Bond.cpp:84
AtomicNumber GetId() const
Definition: Bond.cpp:69
physical::Wave * GetBonded()
Definition: Bond.cpp:74
physical::Perspective< StandardDimension > * perspective
Definition: Class.h:56
virtual physical::Wave * operator-=(physical::Wave *toRelease)
Definition: Surface.cpp:227
virtual void SetEnvironment(Molecule *environment)
Definition: Surface.cpp:95
virtual void SetPerspective(Molecule *perspective)
Definition: Surface.cpp:102
virtual physical::Waves ReleaseAll(BondType bondType=bond_type::Temporary())
Definition: Surface.cpp:207
Molecule * environment
Definition: Surface.h:59
virtual physical::Wave * Release(physical::Wave *toRelease, BondType bondType=bond_type::Temporary())
Definition: Surface.cpp:119
Surface(const Surface &toCopy)
Definition: Surface.cpp:30
virtual physical::Waves operator--()
Definition: Surface.cpp:242
virtual physical::Symmetry * Spin() const
Definition: Surface.cpp:113
virtual Code Reify(physical::Symmetry *symmetry)
Definition: Surface.cpp:107
virtual Perspective * GetPerspective() const
Definition: Observer.h:82
virtual void SetPerspective(Perspective *perspective)
Definition: Observer.h:74
virtual Wave * Clone() const
Definition: Wave.cpp:52
BondType Manage()
Code NotImplemented()
Filter Molecular()
std::vector< Wave * > Waves
Definition: Wave.h:48
SymmetryType Variable()
Definition: Cell.h:31
const char * Name
Definition: Types.h:46