Develop Biology
The language of life
bio::physical::Periodic Class Reference

#include <Periodic.h>

+ Inheritance diagram for bio::physical::Periodic:
+ Collaboration diagram for bio::physical::Periodic:

Public Member Functions

 Periodic (TimeUS interval=GetDefaultInterval())
 
virtual ~Periodic ()
 
 BIO_DISAMBIGUATE_ALL_CLASS_METHODS (physical, Periodic) static TimeUS GetDefaultInterval()
 
virtual void CheckIn ()
 
TimeUS GetInterval () const
 
float GetIntervalInSeconds () const
 
virtual Properties GetProperties () const
 
Timestamp GetTimeLastPeaked () const
 
virtual void InitializeImplementation (ByteStreams args)
 
virtual Code Peak ()
 
virtual Code Reify (Symmetry *symmetry)
 
virtual void SetInterval (TimeUS interval)
 
virtual void SetLastPeakTimestamp (Timestamp lastPeak)
 
virtual SymmetrySpin () const
 
- Public Member Functions inherited from bio::physical::Class< Periodic >
 Class (Periodic *object, Symmetry *symmetry=NULL)
 
virtual ~Class ()
 
virtual WaveAsWave ()
 
virtual const WaveAsWave () const
 
virtual WaveClone () const
 
PeriodicConvert (Wave *wave)
 
virtual operator Periodic * ()
 
virtual operator Wave * ()
 
- Public Member Functions inherited from bio::physical::Wave
 Wave (Symmetry *symmetry=NULL)
 
virtual ~Wave ()
 
virtual chemical::AtomAsAtom ()
 
virtual const chemical::AtomAsAtom () const
 
virtual WaveAsWave ()
 
virtual const WaveAsWave () const
 
virtual Code Attenuate (const Wave *other)
 
virtual WaveClone () const
 
virtual WaveDemodulate ()
 
virtual const WaveDemodulate () const
 
virtual Code Disattenuate (const Wave *other)
 
virtual Properties GetProperties () const
 
virtual WaveModulate (Wave *signal)
 
virtual Waveoperator* ()
 
virtual const Waveoperator* () const
 
virtual Waveoperator* (Wave *signal)
 
virtual void operator+ (const Wave *other)
 
virtual void operator- (const Wave *other)
 
virtual void operator| (Symmetry *symmetry)
 
virtual Code Reify (Symmetry *symmetry)
 
virtual SymmetrySpin () const
 

Static Public Member Functions

static Properties GetClassProperties ()
 
- Static Public Member Functions inherited from bio::physical::Wave
static Properties GetResonanceBetween (const Wave *wave, const Properties &properties)
 
static Properties GetResonanceBetween (const Wave *wave1, const Wave *wave2)
 
static Properties GetResonanceBetween (ConstWaves waves)
 

Protected Attributes

TimeUS m_interval
 
Timestamp m_lastPeakTimestamp
 
- Protected Attributes inherited from bio::physical::Class< Periodic >
Periodicm_object
 
- Protected Attributes inherited from bio::physical::Wave
Wavem_signal
 
Symmetrym_symmetry
 
- Protected Attributes inherited from bio::VirtualBase
bool m_hasBeenInitialized
 

Additional Inherited Members

- Protected Member Functions inherited from bio::VirtualBase
 VirtualBase ()
 
virtual ~VirtualBase ()
 
void Initialize (ByteStream arg1)
 
void Initialize (ByteStream arg1, ByteStream arg2)
 
void Initialize (ByteStream arg1, ByteStream arg2, ByteStream arg3)
 
void Initialize (ByteStreams args)
 
virtual void InitializeImplementation (ByteStreams args)=0
 

Detailed Description

Periodic objects do work at regular intervals.

Definition at line 34 of file Periodic.h.

Constructor & Destructor Documentation

◆ Periodic()

bio::physical::Periodic::Periodic ( TimeUS  interval = GetDefaultInterval())
Parameters
intervalthe period that Peak() wants to be called in microseconds.

Definition at line 44 of file Periodic.cpp.

45 :
46 Class(
47 this,
48 new Symmetry(
49 "m_interval",
52 interval
53 ),
55 0
56 )
57{
58}
Class(Periodic *object, Symmetry *symmetry=NULL)
Definition: Class.h:46
Timestamp m_lastPeakTimestamp
Definition: Periodic.h:147
SymmetryType DefineVariable()

◆ ~Periodic()

bio::physical::Periodic::~Periodic ( )
virtual

Definition at line 60 of file Periodic.cpp.

61{
62}

Member Function Documentation

◆ BIO_DISAMBIGUATE_ALL_CLASS_METHODS()

bio::physical::Periodic::BIO_DISAMBIGUATE_ALL_CLASS_METHODS ( physical  ,
Periodic   
)

Ensure virtual methods point to Class implementations. Currently default is set to 200 milliseconds (200000 microseconds).

Returns
a default value for Periodic constructors.

◆ CheckIn()

void bio::physical::Periodic::CheckIn ( )
virtual

Checks the current time & calls Peak, if a long enough interval has passed. Call this method regularly (i.e. on a clock).

Definition at line 119 of file Periodic.cpp.

120{
122 if (now - GetTimeLastPeaked() < GetInterval())
123 {
124 return;
125 }
126 Peak();
128 now
129 );
130}
virtual Code Peak()
Definition: Periodic.h:84
TimeUS GetInterval() const
Definition: Periodic.cpp:69
Timestamp GetTimeLastPeaked() const
Definition: Periodic.cpp:74
virtual void SetLastPeakTimestamp(Timestamp lastPeak)
Definition: Periodic.cpp:84
Timestamp GetCurrentTimestamp()
Definition: Time.cpp:41
uint32_t Timestamp
Definition: Types.h:68

References bio::physical::GetCurrentTimestamp(), GetInterval(), GetTimeLastPeaked(), Peak(), and SetLastPeakTimestamp().

◆ GetClassProperties()

Properties bio::physical::Periodic::GetClassProperties ( )
static

All Periodic objects share the "Periodic" Property.

Returns
{property::Periodic()}

Definition at line 36 of file Periodic.cpp.

37{
38 Properties ret;
39 ret.push_back(
41 return ret;
42}
Property Periodic()
uint8_t Properties
Definition: Types.h:58

References bio::property::Periodic(), and bio::Properties.

Referenced by GetProperties().

◆ GetInterval()

TimeUS bio::physical::Periodic::GetInterval ( ) const
Returns
the time interval between Peaks of *this, in microseconds.

Definition at line 69 of file Periodic.cpp.

70{
71 return m_interval;
72}

References m_interval.

Referenced by CheckIn().

◆ GetIntervalInSeconds()

float bio::physical::Periodic::GetIntervalInSeconds ( ) const
Returns
the time interval between Peaks of *this, in seconds.

Definition at line 79 of file Periodic.cpp.

80{
81 return (static_cast<float>(m_interval)) / 1000000.0f;
82}

References m_interval.

◆ GetProperties()

Properties bio::physical::Periodic::GetProperties ( ) const
virtual

Wave method. See that class for details.

Returns
Periodic::GetClassProperties()

Reimplemented from bio::physical::Wave.

Definition at line 114 of file Periodic.cpp.

115{
116 return GetClassProperties();
117}
static Properties GetClassProperties()
Definition: Periodic.cpp:36

References GetClassProperties().

◆ GetTimeLastPeaked()

Timestamp bio::physical::Periodic::GetTimeLastPeaked ( ) const
Returns
the last time *this Peaked.

Definition at line 74 of file Periodic.cpp.

75{
77}

References m_lastPeakTimestamp.

Referenced by CheckIn().

◆ InitializeImplementation()

void bio::physical::Periodic::InitializeImplementation ( ByteStreams  args)
virtual

VirtualBase required method. See that class for details (in common/)

Parameters
args

Implements bio::VirtualBase.

Definition at line 105 of file Periodic.cpp.

106{
107 BIO_SANITIZE(args.size() == 1 && args[0].Is(
109 ), ,
110 return);
111 m_interval = args[0];
112}
#define BIO_SANITIZE(test, success, failure)

References BIO_SANITIZE, and m_interval.

◆ Peak()

virtual Code bio::physical::Periodic::Peak ( )
inlinevirtual

Peak()s occur at Periodic::m_intervals. Define your main Periodic logic here. This method must be fast:

  • do not read slow hardware here
  • do not block for a long time
  • do not sleep If derived classes must do slow work to oscillate, that slow logic MUST BE placed in a separate thread. This method would then get the data stored by that thread and returns the data quickly. MAKE SURE that the thread never causes a long mutex wait as a side-effect in this Peak method.

Reimplemented in bio::cellular::Cell, and bio::cellular::Organelle.

Definition at line 84 of file Periodic.h.

85 {
86
87 // YOU CODE GOES HERE!
88
89 return code::NotImplemented();
90 }
Code NotImplemented()

References bio::code::NotImplemented().

Referenced by CheckIn(), bio::cellular::Cell::Peak(), and bio::cellular::Organelle::Peak().

◆ Reify()

Code bio::physical::Periodic::Reify ( Symmetry symmetry)
virtual

Required method from Wave. See that class for details. Reconstruct *this from the given Symmetry.

Parameters
symmetry

Reimplemented from bio::physical::Wave.

Definition at line 97 of file Periodic.cpp.

98{
99 BIO_SANITIZE(symmetry, ,
100 return code::BadArgument1());
101 m_interval = symmetry->GetValue();
102 return code::Success();
103}
Code BadArgument1()
Code Success()

References bio::code::BadArgument1(), BIO_SANITIZE, bio::physical::Symmetry::GetValue(), m_interval, and bio::code::Success().

◆ SetInterval()

void bio::physical::Periodic::SetInterval ( TimeUS  interval)
virtual

Set how quickly *this should Peak()

Parameters
interval

Definition at line 64 of file Periodic.cpp.

65{
66 m_interval = interval;
67}

References m_interval.

◆ SetLastPeakTimestamp()

void bio::physical::Periodic::SetLastPeakTimestamp ( Timestamp  lastPeak)
virtual

Sets the timestamp of the last time *this Peaked. USE WITH CAUTION!

Parameters
lastPeak

Definition at line 84 of file Periodic.cpp.

85{
86 m_lastPeakTimestamp = lastPeak;
87}

References m_lastPeakTimestamp.

Referenced by CheckIn().

◆ Spin()

Symmetry * bio::physical::Periodic::Spin ( ) const
virtual

Required method from Wave. See that class for details.

Returns
a Symmetrical image of *this

Reimplemented from bio::physical::Wave.

Definition at line 89 of file Periodic.cpp.

90{
93 );
94 return Wave::Spin();
95}
void Set(T in)
Definition: ByteStream.h:147
virtual ByteStream * AccessValue()
Definition: Symmetry.cpp:130
virtual Symmetry * Spin() const
Definition: Wave.cpp:59
Symmetry * m_symmetry
Definition: Wave.h:272

References bio::physical::Symmetry::AccessValue(), m_interval, bio::physical::Wave::m_symmetry, bio::ByteStream::Set(), and bio::physical::Wave::Spin().

Member Data Documentation

◆ m_interval

TimeUS bio::physical::Periodic::m_interval
protected

◆ m_lastPeakTimestamp

Timestamp bio::physical::Periodic::m_lastPeakTimestamp
protected

Definition at line 147 of file Periodic.h.

Referenced by GetTimeLastPeaked(), and SetLastPeakTimestamp().


The documentation for this class was generated from the following files: