From 88b37e83bbbdb6840141a43e368ed8a4feabf553 Mon Sep 17 00:00:00 2001 From: Jonathan Protzenko Date: Mon, 2 Nov 2015 13:20:38 -0800 Subject: [PATCH] Add an operator overload for ManagedType. --- .gitignore | 4 ++++ inc/ManagedType.h | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..80152a5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +.yotta.json +yotta_modules +yotta_targets diff --git a/inc/ManagedType.h b/inc/ManagedType.h index b43a511..b15b293 100644 --- a/inc/ManagedType.h +++ b/inc/ManagedType.h @@ -80,10 +80,35 @@ public: */ int getReferences(); + /** + * De-reference operator overload. This makes modifying ref-counted POD + * easier. + * + * Example: + * @code + * ManagedType x = 0; + * *x = 1; // mutates the ref-counted integer + */ + T& operator*() { + return *object; + } + + /** + * Method call operator overload. This forwards the call to the underlying + * object. + * + * Example: + * @code + * ManagedType x = new T(); + * x->m(); // resolves to T::m + */ T* operator->() { return object; } + /** + * x.get() is shorthand for x.operator->() + */ T* get() { return object; }