Yan Lee has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/68017?usp=email )
Change subject: base: extensible: add example codes of extension
......................................................................
base: extensible: add example codes of extension
Change-Id: Iaab1f2998a3f621b86d63bed7274373ba433d71c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/68017
Maintainer: Jason Lowe-Power <power...@gmail.com>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/extensible.hh
1 file changed, 44 insertions(+), 0 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/base/extensible.hh b/src/base/extensible.hh
index eb79c71..e80103c 100644
--- a/src/base/extensible.hh
+++ b/src/base/extensible.hh
@@ -27,6 +27,10 @@
/* @file
* Extensible Object Base Class Declaration
+ *
+ * This class can be used to add an "extension" field to packet/request
which
+ * will be passed along with the original packet/request pointer. This
allows
+ * developers to extend packet/request without modifying the original
class.
*/
#ifndef __BASE_EXTENSIBLE_HH__
@@ -69,6 +73,33 @@
* This is the extension for carrying additional information.
* Each type of extension will have a unique extensionID.
* This extensionID will assign to base class for comparsion.
+ *
+ * Example usage:
+ *
+ * class MyTarget : Extensible<MyTarget> {};
+ *
+ * class MyExtension : public Extension<MyTarget, MyExtension>
+ * {
+ * public:
+ * MyExtension();
+ * std::unique_ptr<ExtensionBase> clone() const override;
+ * uint32_t getData();
+ *
+ * private:
+ * uint32_t data_;;
+ * };
+ *
+ * std::unique_ptr<MyTarget> mytarget(new MyTarget);
+ * std::shared_ptr<MyExtension> myext(new MyExtension);
+ * mytarget->setExtension(myext);
+ *
+ * std::shared_ptr<MyExtension> ext =
mytarget->getExtension<MyExtension>();
+ * uint32_t data = ext->getData();
+ * mytarget->removeExtension<MyExtension>();
+ *
+ * In the example above, MyTarget can carry an extension named
MyExtension,
+ * which contains an additional data field. This could be applicated to
any
+ * debug information or any data field in any protocol.
*/
template <typename Target, typename T>
class Extension : public ExtensionBase
--
To view, visit
https://gem5-review.googlesource.com/c/public/gem5/+/68017?usp=email
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: Iaab1f2998a3f621b86d63bed7274373ba433d71c
Gerrit-Change-Number: 68017
Gerrit-PatchSet: 3
Gerrit-Owner: Yan Lee <yan...@google.com>
Gerrit-Reviewer: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: Yan Lee <yan...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org