Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/32901 )
Change subject: base: Add a "callable" method to the Value stats class.
......................................................................
base: Add a "callable" method to the Value stats class.
This class can already accept a proxy variable and a "functor" which is
a pointer to either a function or an instance of a class with the ()
operator overloaded.
This new method accepts a "callable" which is similar to the functor,
except it keeps a copy of the object and not a pointer to something
external. This makes it much easier to use with lambdas which can be
defined inline as temporaries without having to set up a new class,
create and manage an instance, etc.
There is a lot of overlap between the existing "functor" and this new
"callable" interface which is not ideal. It wasn't clear how to add this
new functionality to the functor interface without breaking backwards
compatibility, and there wasn't an obvious other name to use which made
the distinction between them clearer. Suggestions are welcome.
Change-Id: Icb1b3682d51b721f6e16614490ed0fe289cee094
---
M src/base/statistics.hh
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index ee541fb..480139a 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -806,6 +806,19 @@
Result total() const { return (*functor)(); }
};
+template <class T>
+class CallableProxy : public ProxyInfo
+{
+ private:
+ T callable;
+
+ public:
+ CallableProxy(const T &c) : callable(c) {}
+ Counter value() const { return callable(); }
+ Result result() const { return callable(); }
+ Result total() const { return callable(); }
+};
+
/**
* A proxy similar to the FunctorProxy, but allows calling a method of a
bound
* object, instead of a global free-standing function.
@@ -858,6 +871,15 @@
return this->self();
}
+ template <class T>
+ Derived &
+ callable(const T &callable)
+ {
+ proxy = new CallableProxy<T>(callable);
+ this->setInit();
+ return this->self();
+ }
+
/**
* Extended functor that calls the specified method of the provided
object.
*
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/32901
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Icb1b3682d51b721f6e16614490ed0fe289cee094
Gerrit-Change-Number: 32901
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s