Develop Biology
The language of life
Molecule.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
27
28namespace bio {
29namespace molecular {
30
31Molecule::Molecule(const Molecule& toCopy)
32 :
33 molecular::Class< Molecule >(
34 this,
35 toCopy.GetId(),
36 toCopy.GetPerspective(),
37 toCopy.GetFilter()),
38 physical::Perspective< StandardDimension >(toCopy),
39 chemical::LinearMotif< Surface* >(toCopy)
40{
41 chemical::LinearMotif< Surface* >::m_perspective = this;
42}
43
44Molecule::~Molecule()
45{
46}
47
48Surface* Molecule::RotateTo(StandardDimension surfaceId)
49{
50 BIO_SANITIZE_WITH_CACHE(GetById< Surface* >(
51 surfaceId
52 ),
53 return *Cast< Surface** >(RESULT),
54 return NULL);
55}
56
57const Surface* Molecule::RotateTo(StandardDimension surfaceId) const
58{
59 BIO_SANITIZE_WITH_CACHE(GetById< Surface* >(
60 surfaceId
61 ),
62 return *Cast< const Surface** >(RESULT),
63 return NULL);
64}
65
66Surface* Molecule::RotateTo(Name surfaceName)
67{
68 BIO_SANITIZE_WITH_CACHE(GetByName< Surface* >(
69 surfaceName
70 ),
71 return *Cast< Surface** >(RESULT),
72 return NULL);
73}
74
75const Surface* Molecule::RotateTo(Name surfaceName) const
76{
77 BIO_SANITIZE_WITH_CACHE(GetByName< Surface* >(
78 surfaceName
79 ),
80 return *Cast< const Surface** >(RESULT),
81 return NULL);
82}
83
84bool Molecule::DuplicateFrom(
85 Molecule* source,
86 Name surface
87)
88{
89 BIO_SANITIZE(source, ,
90 return false);
91
92 BIO_SANITIZE(!RotateTo(surface), ,
93 return false);
94
95 Surface* toTransfer = NULL;
96
97 BIO_SANITIZE_WITH_CACHE(source->RotateTo(surface),
98 toTransfer = RESULT,
99 return false);
100
101 Add< Surface* >(CloneAndCast< Surface* >(toTransfer))->SetEnvironment(this);
102 return true;
103}
104
105bool Molecule::TransferFrom(
106 Molecule* source,
107 Name surface
108)
109{
110 BIO_SANITIZE(source, ,
111 return false);
112
113 BIO_SANITIZE(!RotateTo(surface), ,
114 return false);
115
116 Surface* toTransfer = NULL;
117
118 BIO_SANITIZE_WITH_CACHE(source->RotateTo(surface),
119 toTransfer = RESULT,
120 return false);
121
122 Add< Surface* >(toTransfer)->SetEnvironment(this);
123 source->Remove< Surface* >(toTransfer);
124 return true;
125}
126
127Surface* Molecule::operator()(StandardDimension surfaceId)
128{
129 return RotateTo(surfaceId);
130}
131
132const Surface* Molecule::operator()(StandardDimension surfaceId) const
133{
134 return RotateTo(surfaceId);
135}
136
137Surface* Molecule::operator()(Name name)
138{
139 return RotateTo(name);
140}
141
142const Surface* Molecule::operator()(Name name) const
143{
144 return RotateTo(name);
145}
146
147Molecule* Molecule::operator<<(Surface* source)
148{
149 BIO_SANITIZE(source, ,
150 return this);
151 Add< Surface* >(source)->SetEnvironment(this);
152 return this;
153}
154
155Surface* Molecule::operator>>(Surface* target)
156{
157 BIO_SANITIZE(target, ,
158 return target);
159 target->Add< Molecule* >(this);
160 return target;
161}
162
163Molecule* Molecule::operator<<(Molecule* source)
164{
165 BIO_SANITIZE(source, ,
166 return this);
167 Import< Surface* >(source);
168 return this;
169}
170
171Molecule* Molecule::operator>>(Molecule* target)
172{
173 BIO_SANITIZE(target, ,
174 return target);
175 target->Import< Surface* >(this);
176 Clear< Surface* >();
177 return target;
178}
179
180physical::Symmetry* Molecule::Spin() const
181{
182 //TODO...
183 return NULL;
184}
185
186Code Molecule::Reify(physical::Symmetry* symmetry)
187{
188 //TODO...
189 return code::NotImplemented();
190}
191
192} //molecular namespace
193} //bio namespace
#define BIO_SANITIZE(test, success, failure)
#define BIO_SANITIZE_WITH_CACHE(test, success, failure)
void Import(const UnorderedMotif< T > *other)
virtual Surface * RotateTo(StandardDimension surfaceId)
Definition: Molecule.cpp:48
Code NotImplemented()
Definition: Cell.h:31
const char * Name
Definition: Types.h:46