Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*.
  • Loading branch information
kjbracey committed Sep 5, 2018
commit 390f6e7a7b74cca5e82af03a95d53d89b163c142
10 changes: 10 additions & 0 deletions platform/SingletonPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down