Develop Biology
The language of life
Wave.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
22#include "bio/physical/Wave.h"
27#include <algorithm>
28
29namespace bio {
30namespace physical {
31
33 Symmetry* symmetry
34)
35 :
36 m_symmetry(
37 symmetry
38 ),
39 m_signal(
40 NULL
41 )
42{
43}
44
46{
48 delete m_symmetry;
49 m_symmetry = NULL,);
50}
51
53{
54 return new Wave(
55 *this
56 );
57}
58
60{
61 return m_symmetry;
62}
63
65 Symmetry* symmetry
66)
67{
68 (*m_symmetry) = *symmetry;
69 return code::Success();
70}
71
73 Symmetry* symmetry
74)
75{
76 Reify(
77 symmetry
78 );
79}
80
81Code Wave::Attenuate(const Wave* other)
82{
83 return code::NotImplemented();
84}
85
86Code Wave::Disattenuate(const Wave* other)
87{
88 return code::NotImplemented();
89}
90
92 Wave* signal
93)
94{
95 m_signal = signal;
96 return this;
97}
98
100{
101 return m_signal;
102}
103
104const Wave* Wave::Demodulate() const
105{
106 return m_signal;
107}
108
110 Wave* signal
111)
112{
113 return Modulate(
114 signal
115 );
116}
117
119{
120 return Demodulate();
121}
122
123const Wave* Wave::operator*() const
124{
125 return Demodulate();
126}
127
129 const Wave* other
130)
131{
132 Attenuate(other);
133}
134
136 const Wave* other
137)
138{
139 Disattenuate(other);
140}
141
143{
144 Properties ret;
145 return ret;
146}
147
149 const Wave* wave,
150 const Properties& properties
151)
152{
153 class TempWave :
154 public Wave
155 {
156 public:
157 TempWave(Properties p)
158 :
159 m_properties(p)
160 {
161 }
162
163 ~TempWave()
164 {
165 }
166
167 virtual Properties GetProperties() const
168 {
169 return m_properties;
170 }
171
172 Properties m_properties;
173 };
174
175 ConstWaves waves;
176 waves.push_back(
177 wave
178 );
179 TempWave* twave = new TempWave(properties);
180 waves.push_back(
181 twave
182 );
183
185 waves
186 );
187
188 delete twave;
189 return ret;
190}
191
193 const Wave* wave1,
194 const Wave* wave2
195)
196{
197 ConstWaves waves;
198 waves.push_back(
199 wave1
200 );
201 waves.push_back(
202 wave2
203 );
204 return GetResonanceBetween(
205 waves
206 );
207}
208
210 ConstWaves waves
211)
212{
213 Properties overlap;
214 BIO_SANITIZE(waves.size() && waves[0], ,
215 return overlap);
216 overlap = waves[0]->GetProperties();
217 BIO_SANITIZE_AT_SAFETY_LEVEL_2(waves.size() > 1, ,
218 return overlap);
219 std::vector< Properties::iterator > remBuffer;
220
221 for (
222 ConstWaves::const_iterator wav = waves.begin()++;
223 wav != waves.end();
224 ++wav
225 )
226 {
227 BIO_SANITIZE(*wav, ,
228 continue);
229
230 Properties wavProperties = (*wav)->GetProperties();
231 remBuffer.clear();
232 for (
233 Properties::iterator prp = overlap.begin();
234 prp != overlap.end();
235 ++prp
236 )
237 {
238 if (std::find(
239 wavProperties.begin(),
240 wavProperties.end(),
241 *prp
242 ) != wavProperties.end())
243 {
244 remBuffer.push_back(
245 prp
246 );
247 }
248 }
249 for (
250 std::vector< Properties::iterator >::iterator rem = remBuffer.begin();
251 rem != remBuffer.end();
252 ++rem
253 )
254 {
255 overlap.erase(
256 *rem
257 );
258 }
259 }
260 return overlap;
261}
262
263} //physical namespace
264} //bio namespace
#define BIO_SANITIZE_AT_SAFETY_LEVEL_2(test, success, failure)
#define BIO_SANITIZE(test, success, failure)
virtual void operator+(const Wave *other)
Definition: Wave.cpp:128
virtual Code Attenuate(const Wave *other)
Definition: Wave.cpp:81
virtual Code Disattenuate(const Wave *other)
Definition: Wave.cpp:86
virtual Properties GetProperties() const
Definition: Wave.cpp:142
virtual Wave * Modulate(Wave *signal)
Definition: Wave.cpp:91
Wave * m_signal
Definition: Wave.h:277
virtual Wave * Clone() const
Definition: Wave.cpp:52
virtual ~Wave()
Definition: Wave.cpp:45
virtual Wave * Demodulate()
Definition: Wave.cpp:99
virtual Symmetry * Spin() const
Definition: Wave.cpp:59
virtual Code Reify(Symmetry *symmetry)
Definition: Wave.cpp:64
virtual Wave * operator*()
Definition: Wave.cpp:118
virtual void operator-(const Wave *other)
Definition: Wave.cpp:135
virtual void operator|(Symmetry *symmetry)
Definition: Wave.cpp:72
Wave(Symmetry *symmetry=NULL)
Definition: Wave.cpp:32
static Properties GetResonanceBetween(ConstWaves waves)
Definition: Wave.cpp:209
Symmetry * m_symmetry
Definition: Wave.h:272
Code Success()
Code NotImplemented()
std::vector< const Wave * > ConstWaves
Definition: Wave.h:51
Definition: Cell.h:31
uint8_t Properties
Definition: Types.h:58