The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::StatInstCalculator Class Reference

Public Member Functions

 StatInstCalculator (const SpartaHandler &handler, const double &aggregated_value)
 
double getCurrentValue () const
 
void setNode (const TreeNode *node)
 
const TreeNodegetNode () const
 

Detailed Description

Definition at line 32 of file StatInstCalculator.hpp.

Constructor & Destructor Documentation

◆ StatInstCalculator()

sparta::StatInstCalculator::StatInstCalculator ( const SpartaHandler &  handler,
const double &  aggregated_value 
)
inline

Give the calculator a SpartaHandler to your own code which performs the calculation, as well as a variable in your code which holds the calculated value. For example:

class MyFoo { public: MyFoo() { auto cb = CREATE_SPARTA_HANDLER(MyFoo, randomNum_); std::shared_ptr<StatInstCalculator> calc( new StatInstCalculator(cb, my_random_num_)); //Do whatever you want with this 'calc' object, //such as creating a StatisticInstance out of //it for evaluation (in reports, etc.) } private: void randomNum_() { my_random_num_ = (double)rand(); } double my_random_num_ = 0; };

Note
The SpartaHandler (callback) must have the function signature 'void fcnName(void)'
The member variable where you store the calculated value must be a double scalar

Definition at line 60 of file StatInstCalculator.hpp.

Member Function Documentation

◆ getCurrentValue()

double sparta::StatInstCalculator::getCurrentValue ( ) const
inline

Invoke the user's SpartaHandler to perform the calculation, and return the result.

Definition at line 68 of file StatInstCalculator.hpp.

◆ getNode()

const TreeNode * sparta::StatInstCalculator::getNode ( ) const
inline

Return the TreeNode to which this calculator belongs

Note
Will return null if 'setNode()' was never called

Definition at line 85 of file StatInstCalculator.hpp.

◆ setNode()

void sparta::StatInstCalculator::setNode ( const TreeNode node)
inline

If you want to give this StatInstCalculator to a StatisticInstance (for getting these calculated values into a SPARTA report for instance) then you need to give this object the TreeNode to which it belongs.

Definition at line 77 of file StatInstCalculator.hpp.


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