The Sparta Modeling Framework
Loading...
Searching...
No Matches
StatInstCalculator.hpp
Go to the documentation of this file.
1// <StatInstCalculator> -*- C++ -*-
2
8#pragma once
9
12
13namespace sparta {
14
15class TreeNode;
16
17/*
18 * \brief This class is a wrapper around user-implemented
19 * code (SpartaHandler's) that calculate the value of a SPARTA
20 * statistic on demand. There are cases where expressing
21 * a statistic equation in a single std::string is not
22 * very easy to do - if it were easily written out in
23 * a single string, you could use StatisticDef's to get
24 * the statistic values in reports as usual.
25 *
26 * StatisticInstance's have a constructor overload which
27 * takes one of these StatInstCalculator objects, and
28 * when the reporting infrastructure calls 'SI::getValue()'
29 * it will invoke the user's SpartaHandler to retrieve the
30 * value.
31 */
33public:
60 StatInstCalculator(const SpartaHandler & handler,
61 const double & aggregated_value) :
62 handler_(handler),
63 aggregated_value_(aggregated_value)
64 {}
65
68 double getCurrentValue() const {
69 handler_();
70 return aggregated_value_;
71 }
72
77 void setNode(const TreeNode * node) {
78 sparta_assert(node_ == nullptr || node_ == node);
79 sparta_assert(node != nullptr);
80 node_ = node;
81 }
82
85 const TreeNode * getNode() const {
86 return node_;
87 }
88
89private:
90 SpartaHandler handler_;
91 const double & aggregated_value_;
92 const TreeNode * node_ = nullptr;
93};
94
95}
96
Set of macros for Sparta assertions. Caught by the framework.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
File that contains the macro used to generate the class callbacks.
void setNode(const TreeNode *node)
StatInstCalculator(const SpartaHandler &handler, const double &aggregated_value)
const TreeNode * getNode() const
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
Macros for handling exponential backoff.