Develop Biology
The language of life
Excitation.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
28
29namespace bio {
30namespace chemical {
31
45 public physical::Class< ExcitationBase >
46{
47public:
53
54
58 :
59 physical::Class< ExcitationBase >(this)
60 {
61
62 }
63
65 {
66
67 }
68
74 {
75 Properties ret;
76 ret.push_back(property::Excitatory());
77 return ret;
78 }
79
85 virtual Properties GetProperties() const
86 {
87 return GetClassProperties();
88 }
89
95 virtual void EditArg(
96 uint8_t position,
97 ByteStream& newVal
98 )
99 {
100 //nop
101 }
102
109 virtual void CallDown(
110 physical::Wave* wave,
111 ByteStream* ret
112 ) const
113 {
114 //nop
115 }
116};
117
118#if BIO_CPP_VERSION >= 17
119
120 #include <tuple>
121 #include <functional>
122
129template< class WAVE, typename RETURN, typename... ARGUMENTS >
130class Excitation :
131 public ExcitationBase,
132 public physical::Class< Excitation< WAVE,RETURN,ARGUMENTS...> >
133{
134public:
135
139 BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, BIO_SINGLE_ARG(Excitation<WAVE,RETURN,ARGUMENTS...>))
140
141
144 Excitation(RETURN(WAVE::*function)(ARGUMENTS...), const ARGUMENTS&... args)
145 :
146 physical::Class< Excitation<WAVE,RETURN,ARGUMENTS...> >(this),
147 m_function(function),
148 m_args(args)
149 {
150 }
151
155 virtual Excitation()
156 {
157
158 }
159
165 virtual Properties GetProperties() const
166 {
167 Properties ret = PeriodicTable::Instance().GetPropertiesOf< WAVE >();
168 ret.insert(ret.end(), ExcitationBase::GetClassProperties().begin(), ExcitationBase::GetClassProperties().end());
169 return ret;
170 }
171
177 virtual void EditArg(uint8_t position, ByteStream& newVal)
178 {
179 //TODO...
180 }
181
187 RETURN operator()(WAVE* wave) const
188 {
189 std::tuple allArgs = std::tuple_cat(std::make_tuple(wave), m_args);
190 return std::apply(*m_function, allArgs);
191 }
192
196 virtual void CallDown(physical::Wave* wave, ByteStream* ret) const
197 {
198 ret->Set(this->operator()(ForceCast<WAVE*>(wave)));
199 }
200
201protected:
202 RETURN (WAVE::*m_function)(ARGUMENTS...)
203 std::tuple m_args;
204};
205
206#else
207
213template < class WAVE, typename RETURN >
215 public ExcitationBase,
216 public physical::Class< ExcitationWithoutArgument< WAVE, RETURN > >
217{
218public:
219
225
226
229 ExcitationWithoutArgument(RETURN(WAVE::*function)())
230 :
231 physical::Class< ExcitationWithoutArgument< WAVE, RETURN > >(this),
232 m_function(function)
233 {
234 }
235
240 {
241
242 }
243
249 virtual Properties GetProperties() const
250 {
251 Properties ret = PeriodicTable::Instance().GetPropertiesOf< WAVE >();
252 ret.insert(
253 ret.end(),
256 return ret;
257 }
258
259
264 RETURN operator()(WAVE* wave) const
265 {
266 return (wave->*m_function)();
267 }
268
272 virtual void CallDown(
273 physical::Wave* wave,
274 ByteStream* ret
275 ) const
276 {
277 ret->Set(this->operator()(ForceCast< WAVE* >(wave)));
278 }
279
280protected:
281 RETURN (WAVE::*m_function)();
282};
283
290template < class WAVE, typename RETURN, typename ARGUMENT >
292 public ExcitationBase,
293 public physical::Class< ExcitationWithArgument< WAVE, RETURN, ARGUMENT > >
294{
295public:
296
302
303
304
308 RETURN(WAVE::*function)(ARGUMENT),
309 ARGUMENT arg
310 )
311 :
312 physical::Class< ExcitationWithArgument< WAVE, RETURN, ARGUMENT > >(this),
313 m_function(function),
314 m_arg(arg)
315 {
316 }
317
322 {
323
324 }
325
331 virtual Properties GetProperties() const
332 {
333 Properties ret = PeriodicTable::Instance().GetPropertiesOf< WAVE >();
334 ret.insert(
335 ret.end(),
338 return ret;
339 }
340
346 virtual void EditArg(
347 uint8_t position,
348 ByteStream& newVal
349 )
350 {
351 BIO_SANITIZE(position,
352 return,);
353 m_arg = newVal;
354 }
355
360 RETURN operator()(WAVE* wave) const
361 {
362 return (wave->*m_function)(m_arg);
363 }
364
368 virtual void CallDown(
369 physical::Wave* wave,
370 ByteStream* ret
371 ) const
372 {
373 ret->Set(this->operator()(ForceCast< WAVE* >(wave)));
374 }
375
376protected:
377 RETURN (WAVE::*m_function)(ARGUMENT);
378
379 ARGUMENT m_arg;
380};
381
389template < class WAVE, typename RETURN, typename ARGUMENT1, typename ARGUMENT2 >
391 public ExcitationBase,
392 public physical::Class< ExcitationWithTwoArguments< WAVE, RETURN, ARGUMENT1, ARGUMENT2 > >
393{
394public:
395
401
402
403
407 RETURN(WAVE::*function)(
408 ARGUMENT1,
409 ARGUMENT2
410 ),
411 ARGUMENT1 arg1,
412 ARGUMENT2 arg2
413 )
414 :
415 physical::Class< ExcitationWithTwoArguments< WAVE, RETURN, ARGUMENT1, ARGUMENT2 > >(this),
416 m_function(function),
417 m_arg1(arg1),
418 m_arg2(arg2)
419 {
420 }
421
426 {
427
428 }
429
435 virtual Properties GetProperties() const
436 {
437 Properties ret = PeriodicTable::Instance().GetPropertiesOf< WAVE >();
438 ret.insert(
439 ret.end(),
442 return ret;
443 }
444
450 virtual void EditArg(
451 uint8_t position,
452 ByteStream& newVal
453 )
454 {
455 switch (position)
456 {
457 case 0:
458 m_arg1 = newVal;
459 break;
460 case 1:
461 m_arg2 = newVal;
462 break;
463 }
464 }
465
470 RETURN operator()(WAVE* wave) const
471 {
472 return (wave->*m_function)(
473 m_arg1,
474 m_arg2
475 );
476 }
477
481 virtual void CallDown(
482 physical::Wave* wave,
483 ByteStream* ret
484 ) const
485 {
486 ret->Set(this->operator()(ForceCast< WAVE* >(wave)));
487 }
488
489protected:
490 RETURN (WAVE::*m_function)(
491 ARGUMENT1,
492 ARGUMENT2
493 );
494
495 ARGUMENT1 m_arg1;
496 ARGUMENT2 m_arg2;
497};
498
499
500#endif
501} //chemical namespace
502} //bio namespace
#define BIO_DISAMBIGUATE_ALL_CLASS_METHODS(ns, caller)
#define BIO_SANITIZE(test, success, failure)
void Set(T in)
Definition: ByteStream.h:147
virtual Properties GetProperties() const
Definition: Excitation.h:85
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, ExcitationBase) ExcitationBase()
Definition: Excitation.h:51
virtual void EditArg(uint8_t position, ByteStream &newVal)
Definition: Excitation.h:95
virtual void CallDown(physical::Wave *wave, ByteStream *ret) const
Definition: Excitation.h:109
static Properties GetClassProperties()
Definition: Excitation.h:73
virtual void EditArg(uint8_t position, ByteStream &newVal)
Definition: Excitation.h:346
RETURN(WAVE::* m_function)(ARGUMENT)
Definition: Excitation.h:377
virtual Properties GetProperties() const
Definition: Excitation.h:331
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, BIO_SINGLE_ARG(ExcitationWithArgument< WAVE, RETURN, ARGUMENT >)) ExcitationWithArgument(RETURN(WAVE
Definition: Excitation.h:300
virtual void CallDown(physical::Wave *wave, ByteStream *ret) const
Definition: Excitation.h:368
RETURN operator()(WAVE *wave) const
Definition: Excitation.h:360
virtual void EditArg(uint8_t position, ByteStream &newVal)
Definition: Excitation.h:450
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, BIO_SINGLE_ARG(ExcitationWithTwoArguments< WAVE, RETURN, ARGUMENT1, ARGUMENT2 >)) ExcitationWithTwoArguments(RETURN(WAVE
Definition: Excitation.h:399
virtual void CallDown(physical::Wave *wave, ByteStream *ret) const
Definition: Excitation.h:481
RETURN(WAVE::* m_function)(ARGUMENT1, ARGUMENT2)
Definition: Excitation.h:490
virtual Properties GetProperties() const
Definition: Excitation.h:435
RETURN operator()(WAVE *wave) const
Definition: Excitation.h:470
RETURN operator()(WAVE *wave) const
Definition: Excitation.h:264
BIO_DISAMBIGUATE_ALL_CLASS_METHODS(physical, BIO_SINGLE_ARG(ExcitationWithoutArgument< WAVE, RETURN >)) ExcitationWithoutArgument(RETURN(WAVE
Definition: Excitation.h:223
virtual void CallDown(physical::Wave *wave, ByteStream *ret) const
Definition: Excitation.h:272
virtual Properties GetProperties() const
Definition: Excitation.h:249
#define BIO_SINGLE_ARG(...)
Definition: Macros.h:66
Property Excitatory()
Definition: Cell.h:31
uint8_t Properties
Definition: Types.h:58