![]() |
Bayeux
3.4.1
Core Foundation library for SuperNEMO
|
Templatized handle class that wraps a Boost shared pointer and behaves like a reference. More...
#include <bayeux/datatools/handle.h>
Public Types | |
typedef T | value_type |
typedef value_type & | reference_type |
typedef handle_predicate< T > | predicate_type |
Public Member Functions | |
handle (T *held_=nullptr) | |
A constructor from a pointer to some on-the-fly allocated instance. More... | |
template<typename Q , typename = std::enable_if< std::is_same<const Q, T>::value && std::is_const<T>::value && !std::is_const<Q>::value>> | |
handle (Q *held=nullptr) | |
A constructor from a pointer to some on-the-fly allocated instance. More... | |
handle (const boost::shared_ptr< T > &sp_) | |
Constructor on a boost shared_ptr. More... | |
virtual | ~handle () |
Destructor. More... | |
bool | unique () const |
Check if the current handle holds an uniquely referenced object. More... | |
bool | has_data () const |
Return true if the internal shared pointer holds something. More... | |
operator bool () const | |
Return true if the internal shared pointer holds something. More... | |
void | swap (handle< T > &other_) |
const T & | get () const |
template<typename Q = T> | |
std::enable_if< std::is_same< Q, T >::value &&!std::is_const< Q >::value &&!std::is_const< T >::value, Q & >::type | grab () |
T * | operator-> () |
T const * | operator-> () const |
T & | operator * () |
T const & | operator * () const |
void | reset (T *elem_=nullptr) |
Reset the internal shared pointer with a new instance. More... | |
template<typename Q = T> | |
std::enable_if< std::is_same< Q, T >::value &&!std::is_const< Q >::value &&!std::is_const< T >::value, handle< const Q > >::type | to_const () const |
Return a handle instance that hosts the const instance. More... | |
Friends | |
class | boost::serialization::access |
Templatized handle class that wraps a Boost shared pointer and behaves like a reference.
A handle object is given the responsability to handle a class instance through its pointer using the shared pointer mechanism from Boost. The inner hidden pointer can be null, but accessors will throw exceptions if called when this is the case. The held instance must be initialized with the 'new' construction operator, or you can use the make_handle() free function.
Given handle
and held type T
(no additional qualifiers), an instance of handle<T>
has the following access behaviour in different const
contexts:
handle<T>
: all members of handle
and T
accessible
const handle<T>
: can only access const members of both
const handle<const T>
: can only access const members of both
handle<const T>
: can access all methods of handle, only const
members of T
Access attempts outside these contexts will give a compile-time error.
The handle class is copyable and can be used within STL containers.
Example:
typedef handle_predicate<T> datatools::handle< T >::predicate_type |
typedef value_type& datatools::handle< T >::reference_type |
typedef T datatools::handle< T >::value_type |
|
inline |
A constructor from a pointer to some on-the-fly allocated instance.
This constructor is given a pointer to some dynamically allocated instance and pass it to the internal shared pointer.
Example:
or
|
inline |
A constructor from a pointer to some on-the-fly allocated instance.
This constructor is given a pointer to some dynamically allocated instance and pass it to the internal shared const pointer. This means that the handle does not allow to modify the element it handles.
Example:
|
inline |
Constructor on a boost shared_ptr.
|
inlinevirtual |
Destructor.
|
inline |
Return a const reference to the hosted instance.
std::logic_error | when managed instance is null |
|
inline |
Return a non-const reference to the hosted instance.
std::logic_error | when managed instance is null |
|
inline |
Return true if the internal shared pointer holds something.
|
inline |
Dereferences the stored pointer
std::logic_error | when managed instance is null |
|
inline |
Dereferences the stored pointer in const context
std::logic_error | when managed instance is null |
|
inline |
Return true if the internal shared pointer holds something.
|
inline |
Dereferences the stored pointer
std::logic_error | when managed instance is null |
|
inline |
Dereferences the stored pointer in const context
std::logic_error | when managed instance is null |
|
inline |
Reset the internal shared pointer with a new instance.
|
inline |
|
inline |
Return a handle instance that hosts the const instance.
|
inline |
Check if the current handle holds an uniquely referenced object.
|
friend |