#include <eckit/memory/ScopedPtr.h>
template<typename T>
ScopedPtr class
A smart pointer that deletes the pointee object when going out of scope. This should have a very similar interface to boost scoped_ptr or std unique_ptr so that once C++11 is suported overall compilers we can switch easily. However due to lack of C++11 support, it does not support move semantics.
Public types
- using element_type = T
- using pointer_type = T*
- using reference_type = T&
Constructors, destructors, conversion operators
-
ScopedPtr(pointer_
type ptr = 0) explicit - ~ScopedPtr()
- operator bool() const
Public functions
-
void reset(pointer_
type ptr = 0) -
auto release() -> pointer_
type - auto operator=(ScopedPtr& other) -> const ScopedPtr&
- Assignement operator transfers ownership to another ScopedPtr.
-
auto operator*() const -> reference_
type - Dereferences the pointee.
-
auto operator->() const -> pointer_
type - Dereferences object member.
-
auto get() const -> pointer_
type - void swap(ScopedPtr<T>& other)
Function documentation
template<typename T _1>
eckit:: ScopedPtr<_1>:: ScopedPtr(pointer_ type ptr = 0) explicit
Exceptions | |
---|---|
nothing |
Constructor
template<typename T _1>
eckit:: ScopedPtr<_1>:: operator bool() const
Returns | true if pointer is not null |
---|---|
Exceptions | |
nothing |
template<typename T _1>
void eckit:: ScopedPtr<_1>:: reset(pointer_ type ptr = 0)
Exceptions | |
---|---|
nothing |
Resets the pointee
template<typename T _1>
pointer_ type eckit:: ScopedPtr<_1>:: release()
Exceptions | |
---|---|
nothing |
Releases the ownership of the pointee
template<typename T _1>
pointer_ type eckit:: ScopedPtr<_1>:: get() const
Returns | a pointer to the managed object or null if no object is owned. Should be used with caution, because of issues dealing with raw pointers. However, get makes it possible to explicitly test whether the stored point is NULL. The function never throws. get is typically used when calling functions that require a raw pointer. Note: previously this asserted ptr_ was not null, however this is inconsistent with the standard boost scoped_ptr or std unique_ptr |
---|