Public Member Functions | Private Member Functions | Private Attributes

AnyPtr Class Reference

A smart pointer to any type. More...

#include <keyvalue/util/AnyPtr.h>

List of all members.

Public Member Functions

 AnyPtr ()
 Default constructor builds a NULL AnyPtr.
template<typename T >
 AnyPtr (T *ptr)
 Constructor taking a generic (raw) pointer type.
template<typename T >
 AnyPtr (shared_ptr< T > ptr)
 Constructor taking a shared_ptr<T>.
template<typename T >
 operator shared_ptr< T > () const
 Automatic cast to shared_ptr<T>.
 operator bool () const
 Automatic conversion to bool.
void swap (AnyPtr &other)
 Non throwing swap.

Private Member Functions

template<typename T >
void thrower () const
 The thrower function.

Private Attributes

shared_ptr< void > ptr_
void(AnyPtr::* thr_ )() const

Detailed Description

A smart pointer to any type.

Reference:

[1] Neri, C, "Twisting the RTTI System for Safe Dynamic Casts of void* in C++", Dr.Dobb's Journal, April 05, 2011. http://drdobbs.com/cpp/229401004


Constructor & Destructor Documentation

AnyPtr (  ) 

Default constructor builds a NULL AnyPtr.

AnyPtr ( T *  ptr  )  [explicit]

Constructor taking a generic (raw) pointer type.

Parameters:
T : (template parameter) Defines the input pointer type.
ptr : The input pointer.
AnyPtr ( shared_ptr< T >  ptr  )  [explicit]

Constructor taking a shared_ptr<T>.

Parameters:
T : (template parameter) Defines the input pointer type.
ptr : The input pointer.

Member Function Documentation

operator shared_ptr< T > (  )  const

Automatic cast to shared_ptr<T>.

Parameters:
T : (template parameter) Defines the output type.
Returns:
If this pointer points to an object of type T, then this method returns this pointer cast to shared_ptr<T>. Otherwise, it returns a null shared_ptr<T>.
operator bool (  )  const

Automatic conversion to bool.

Returns:
This function returns true if the pointer is non NULL and false otherwise.
void swap ( AnyPtr other  ) 

Non throwing swap.

Parameters:
other : The other AnyPtr to be swapped.
void thrower (  )  const [private]

The thrower function.