Develop Biology
The language of life
Periodic.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#include "bio/physical/Time.h"
27
28namespace bio {
29namespace physical {
30
31/*static*/ TimeUS Periodic::GetDefaultInterval()
32{
33 return 200000;
34}
35
37{
38 Properties ret;
39 ret.push_back(
41 return ret;
42}
43
45 :
46 Class(
47 this,
48 new Symmetry(
49 "m_interval",
50 symmetry_type::DefineVariable())),
51 m_interval(
52 interval
53 ),
54 m_lastPeakTimestamp(
55 0
56 )
57{
58}
59
61{
62}
63
65{
66 m_interval = interval;
67}
68
70{
71 return m_interval;
72}
73
75{
77}
78
80{
81 return (static_cast<float>(m_interval)) / 1000000.0f;
82}
83
85{
86 m_lastPeakTimestamp = lastPeak;
87}
88
90{
93 );
94 return Wave::Spin();
95}
96
98{
99 BIO_SANITIZE(symmetry, ,
100 return code::BadArgument1());
101 m_interval = symmetry->GetValue();
102 return code::Success();
103}
104
106{
107 BIO_SANITIZE(args.size() == 1 && args[0].Is(
109 ), ,
110 return);
111 m_interval = args[0];
112}
113
115{
116 return GetClassProperties();
117}
118
120{
122 if (now - GetTimeLastPeaked() < GetInterval())
123 {
124 return;
125 }
126 Peak();
128 now
129 );
130}
131
132} //physical namespace
133} //bio namespace
#define BIO_SANITIZE(test, success, failure)
void Set(T in)
Definition: ByteStream.h:147
virtual void InitializeImplementation(ByteStreams args)
Definition: Periodic.cpp:105
virtual void SetInterval(TimeUS interval)
Definition: Periodic.cpp:64
virtual void CheckIn()
Definition: Periodic.cpp:119
virtual Code Reify(Symmetry *symmetry)
Definition: Periodic.cpp:97
virtual Symmetry * Spin() const
Definition: Periodic.cpp:89
virtual Code Peak()
Definition: Periodic.h:84
float GetIntervalInSeconds() const
Definition: Periodic.cpp:79
virtual Properties GetProperties() const
Definition: Periodic.cpp:114
TimeUS GetInterval() const
Definition: Periodic.cpp:69
static Properties GetClassProperties()
Definition: Periodic.cpp:36
Timestamp m_lastPeakTimestamp
Definition: Periodic.h:147
Timestamp GetTimeLastPeaked() const
Definition: Periodic.cpp:74
virtual void SetLastPeakTimestamp(Timestamp lastPeak)
Definition: Periodic.cpp:84
Periodic(TimeUS interval=GetDefaultInterval())
Definition: Periodic.cpp:44
virtual const ByteStream & GetValue() const
Definition: Symmetry.cpp:125
virtual ByteStream * AccessValue()
Definition: Symmetry.cpp:130
virtual Symmetry * Spin() const
Definition: Wave.cpp:59
Symmetry * m_symmetry
Definition: Wave.h:272
Code BadArgument1()
Code Success()
Timestamp GetCurrentTimestamp()
Definition: Time.cpp:41
Property Periodic()
SymmetryType DefineVariable()
Definition: Cell.h:31
std::vector< ByteStream > ByteStreams
Definition: Types.h:52
uint8_t Properties
Definition: Types.h:58
uint32_t TimeUS
Definition: Types.h:74
uint32_t Timestamp
Definition: Types.h:68