mirror of https://github.com/ARMmbed/mbed-os.git
Add * operator to SingletonPtr
Sometimes you want don't want to directly call a method on your
SingletonPtr-wrapped object, but you want to pass it to something
else.
For example
SingletonPtr<PlatformMutex> mutex;
mutex->lock();
is fine, but what about
SingletonPtr<PlatformMutex> mutex;
ScopedLock<PlatformMutex> lock(*mutex.get());
Add an overload for operator* to make this more elegant:
SingletonPtr<PlatformMutex> mutex;
ScopedLock<PlatformMutex> lock(*mutex);
This addition is consistent with standard C++ classes such as
`unique_ptr` and `shared_ptr`, which likewise have
get, operator-> and operator*.
pull/8001/head
parent
dd91b90149
commit
390f6e7a7b
|
|
@ -113,6 +113,16 @@ struct SingletonPtr {
|
|||
return get();
|
||||
}
|
||||
|
||||
/** Get a reference to the underlying singleton
|
||||
*
|
||||
* @returns
|
||||
* A reference to the singleton
|
||||
*/
|
||||
T &operator*()
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
|
||||
// This is zero initialized when in global scope
|
||||
T *_ptr;
|
||||
// Force data to be 4 byte aligned
|
||||
|
|
|
|||
Loading…
Reference in New Issue