BioDynaMo  v1.03.58-27764645
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
bdm::StatelessBehavior Class Reference

Simplifies the creation of behaviors without attributes. Let's assume that we want to create a behavior that divides a cell agent in each iteration. The following code example uses the StatelessBehavior: More...

#include <stateless_behavior.h>

Inheritance diagram for bdm::StatelessBehavior:
[legend]
Collaboration diagram for bdm::StatelessBehavior:
[legend]

Public Types

using FPtr = void(*)(Agent *)
 

Public Member Functions

 StatelessBehavior ()
 
 StatelessBehavior (const FPtr fptr)
 
 StatelessBehavior (const StatelessBehavior &other)
 
virtual ~StatelessBehavior ()=default
 
void Initialize (const NewAgentEvent &event) override
 
void Run (Agent *agent) override
 
- Public Member Functions inherited from bdm::Behavior
 Behavior ()
 
virtual ~Behavior ()=default
 
virtual BehaviorNew () const =0
 Create a new instance of this object using the default constructor. More...
 
virtual BehaviorNewCopy () const =0
 Create a new copy of this behavior. More...
 
virtual void Update (const NewAgentEvent &event)
 
void AlwaysCopyToNew ()
 Always copy this behavior to new agents. More...
 
void NeverCopyToNew ()
 Never copy this behavior to new agents. More...
 
void CopyToNewIf (const std::initializer_list< NewAgentEventUid > &uids)
 
void AlwaysRemoveFromExisting ()
 
void NeverRemoveFromExisting ()
 
void RemoveFromExistingIf (const std::initializer_list< NewAgentEventUid > &uids)
 
bool WillBeCopied (NewAgentEventUid event) const
 
bool WillBeRemoved (NewAgentEventUid event) const
 
void * operator new (size_t size)
 
void operator delete (void *p)
 

Private Member Functions

 BDM_BEHAVIOR_HEADER (StatelessBehavior, Behavior, 1)
 

Private Attributes

FPtr fptr_
 

Detailed Description

Simplifies the creation of behaviors without attributes. Let's assume that we want to create a behavior that divides a cell agent in each iteration. The following code example uses the StatelessBehavior:

StatelessBehavior rapid_division([](Agent* agent) {
bdm_static_cast<Cell*>(agent)->Divide(0.5);
});

NB: The lambda expression is not allowed to use captures, because StatelessBehavior casts it to a function pointer. Without StatelessBehavior the following code would be required.

struct RapidDivision : public Behavior {
BDM_BEHAVIOR_HEADER(RapidDivision, Behavior, 1);
RapidDivision() = default;
virtual ~RapidDivision() = default;
void Run(Agent* agent) override {
bdm_static_cast<Cell*>(agent)->Divide(0.5);
}
};

Definition at line 46 of file stateless_behavior.h.

Member Typedef Documentation

◆ FPtr

using bdm::StatelessBehavior::FPtr = void (*)(Agent*)

Definition at line 50 of file stateless_behavior.h.

Constructor & Destructor Documentation

◆ StatelessBehavior() [1/3]

bdm::StatelessBehavior::StatelessBehavior ( )
inline

Definition at line 51 of file stateless_behavior.h.

◆ StatelessBehavior() [2/3]

bdm::StatelessBehavior::StatelessBehavior ( const FPtr  fptr)
inline

Definition at line 52 of file stateless_behavior.h.

◆ StatelessBehavior() [3/3]

bdm::StatelessBehavior::StatelessBehavior ( const StatelessBehavior other)
inline

Definition at line 53 of file stateless_behavior.h.

◆ ~StatelessBehavior()

virtual bdm::StatelessBehavior::~StatelessBehavior ( )
virtualdefault

Member Function Documentation

◆ BDM_BEHAVIOR_HEADER()

bdm::StatelessBehavior::BDM_BEHAVIOR_HEADER ( StatelessBehavior  ,
Behavior  ,
 
)
private

◆ Initialize()

void bdm::StatelessBehavior::Initialize ( const NewAgentEvent event)
inlineoverridevirtual

This method is called to initialize new behaviors that are created during a NewAgentEvent. Override this method to initialize attributes of your own Behavior subclasses. NB: Don't forget to call the implementation of the base class first. Base::Initialize(event); Failing to do so will result in errors.

Reimplemented from bdm::Behavior.

Definition at line 57 of file stateless_behavior.h.

◆ Run()

void bdm::StatelessBehavior::Run ( Agent agent)
inlineoverridevirtual

Implements bdm::Behavior.

Definition at line 62 of file stateless_behavior.h.

Member Data Documentation

◆ fptr_

FPtr bdm::StatelessBehavior::fptr_
private

Definition at line 70 of file stateless_behavior.h.


The documentation for this class was generated from the following file:
bdm::StatelessBehavior::Run
void Run(Agent *agent) override
Definition: stateless_behavior.h:62
bdm::StatelessBehavior::BDM_BEHAVIOR_HEADER
BDM_BEHAVIOR_HEADER(StatelessBehavior, Behavior, 1)
bdm::StatelessBehavior::StatelessBehavior
StatelessBehavior()
Definition: stateless_behavior.h:51
bdm::Behavior::Behavior
Behavior()
Definition: behavior.h:31