template<typename T>
eckit::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>
eckit::ScopedPtr<T>::ScopedPtr(pointer_type ptr = 0) explicit

Exceptions
nothing

Constructor

template<typename T>
eckit::ScopedPtr<T>::~ScopedPtr()

Exceptions
nothing

Destructor

template<typename T>
eckit::ScopedPtr<T>::operator bool() const

Returns true if pointer is not null
Exceptions
nothing

template<typename T>
void eckit::ScopedPtr<T>::reset(pointer_type ptr = 0)

Exceptions
nothing

Resets the pointee

template<typename T>
pointer_type eckit::ScopedPtr<T>::release()

Exceptions
nothing

Releases the ownership of the pointee

template<typename T>
pointer_type eckit::ScopedPtr<T>::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

template<typename T>
void eckit::ScopedPtr<T>::swap(ScopedPtr<T>& other)

Exceptions
nothing

Swaps the pointee with another ScopedPtr