SOFA API  1a4bb3e7
Open source framework for multi-physics simuation
sofa::core::DataTrackerCallback Class Reference

#include <DataTrackerCallback.h>

Inheritance diagram for sofa::core::DataTrackerCallback:

Detailed Description

a DDGNode that automatically triggers its update function when asking for an output and any input changed. Similar behavior than a DataEngine, but this is NOT a component and can be used everywhere.

Note that it contains a DataTracker (m_dataTracker) to be able to check precisly which input changed if needed.

**** Implementation good rules: (similar to DataEngine)

//init addInput // indicate all inputs addOutput // indicate all outputs setDirtyValue(); // the engine must start dirty (of course, no output are up-to-date)

DataTrackerCallback is usually created using the "addUpdateCallback()" method from Base. Thus the context is usually passed to the lambda making all public & private attributes & methods of the component accessible within the callback function. example:

addUpdateCallback("name", {&name}, [this](DataTracker& tracker){ // Increment the state counter but without changing the state. return d_componentState.getValue(); }, {&d_componentState});

A member function with the same signature - core::objectmodel::ComponentState(DataTracker&) - can also be used.

The update of the inputs is done for you before calling the callback, and they are also cleaned for you after the call. Thus there's no need to manually call updateAllInputsIfDirty() or cleanDirty() (see implementation of update()

Protected Attributes

std::function< sofa::core::objectmodel::ComponentState(const DataTracker &)> m_callback
 
sofa::core::objectmodel::Basem_owner {nullptr}
 
- Protected Attributes inherited from sofa::core::DataTrackerDDGNode
DataTracker m_dataTracker
 
- Protected Attributes inherited from sofa::core::objectmodel::DDGNode
DDGLinkContainer inputs
 
DDGLinkContainer outputs
 

Public Member Functions

void setCallback (std::function< sofa::core::objectmodel::ComponentState(const DataTracker &)> f)
 
void update () override
 Calls the callback when one of the data has changed. More...
 
void setOwner (sofa::core::objectmodel::Base *owner)
 
- Public Member Functions inherited from sofa::core::DataTrackerDDGNode
 DataTrackerDDGNode ()
 
void addInputs (std::initializer_list< sofa::core::objectmodel::BaseData * > datas)
 Create a DataCallback object associated with multiple Data fields. More...
 
void addOutputs (std::initializer_list< sofa::core::objectmodel::BaseData * > datas)
 
virtual void cleanDirty (const core::ExecParams *params=nullptr)
 
void updateAllInputsIfDirty ()
 
- Public Member Functions inherited from sofa::core::objectmodel::DDGNode
 DDGNode ()
 Constructor. More...
 
virtual ~DDGNode ()
 Destructor. Automatically remove remaining links. More...
 
void addInput (DDGNode *n)
 Add a new input to this node. More...
 
void delInput (DDGNode *n)
 Remove an input from this node. More...
 
void addOutput (DDGNode *n)
 Add a new output to this node. More...
 
void delOutput (DDGNode *n)
 Remove an output from this node. More...
 
const DDGLinkContainergetInputs ()
 Get the list of inputs for this DDGNode. More...
 
const DDGLinkContainergetOutputs ()
 Get the list of outputs for this DDGNode. More...
 
bool isDirty () const
 Returns true if the DDGNode needs to be updated. More...
 
virtual void setDirtyValue ()
 Indicate the value needs to be updated. More...
 
virtual void setDirtyOutputs ()
 Indicate the outputs needs to be updated. This method must be called after changing the value of this node. More...
 
void cleanDirty ()
 Set dirty flag to false. More...
 
virtual void notifyEndEdit ()
 Notify links that the DGNode has been modified. More...
 
void updateIfDirty () const
 Utility method to call update if necessary. This method should be called before reading of writing the value of this node. More...
 

Additional Inherited Members

- Protected Member Functions inherited from sofa::core::objectmodel::DDGNode
virtual void doAddInput (DDGNode *n)
 
virtual void doDelInput (DDGNode *n)
 
virtual void doAddOutput (DDGNode *n)
 
virtual void doDelOutput (DDGNode *n)
 
void cleanDirtyOutputsOfInputs ()
 the dirtyOutputs flags of all the inputs will be set to false More...
 

Attribute details

◆ m_callback

std::function<sofa::core::objectmodel::ComponentState(const DataTracker&)> sofa::core::DataTrackerCallback::m_callback
protected

◆ m_owner

sofa::core::objectmodel::Base* sofa::core::DataTrackerCallback::m_owner {nullptr}
protected

Function details

◆ setCallback()

void sofa::core::DataTrackerCallback::setCallback ( std::function< sofa::core::objectmodel::ComponentState(const DataTracker &)>  f)

set the update function to call when asking for an output and any input changed.

◆ setOwner()

void sofa::core::DataTrackerCallback::setOwner ( sofa::core::objectmodel::Base owner)
inline

◆ update()

void sofa::core::DataTrackerCallback::update ( )
overridevirtual

Calls the callback when one of the data has changed.

Implements sofa::core::objectmodel::DDGNode.