LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
misc::ref< T > Class Template Reference

#include <ref.hh>

Inheritance diagram for misc::ref< T >:
Collaboration diagram for misc::ref< T >:

Public Types

typedef std::shared_ptr< T > super_type
 The parent class.
typedef T element_type
 The type pointed to.

Public Member Functions

template<typename U >
bool is_a () const
 Test fellowship. Return true if the reference points to an object which is really of the specified type.
Constructors & Destructor.
template<typename U >
 ref (const ref< U > &other)
 Construct a new reference to the value pointed to by other. The new reference shares the property of the object with other.
 ref (const ref< T > &other)
 Copy constructor.
 ref (T *p=nullptr)
 Construct a counted reference to a newly allocated object. The new reference takes the property of the object pointed to by p. If p is null, then the reference is invalid and must be reset() before use.
 ~ref ()
 Destroy a reference. The object pointed to is destroyed iff it is not referenced anymore.
Equality operators.
bool operator== (const T *p) const
 Reference comparison. Returns true if this points to p.
bool operator!= (const T *p) const
 Reference comparison. Returns false if this points to p.
Casts.
template<typename U >
ref< U > cast () const
 Cast the reference. Return a new reference, possibly throwing an exception if the dynamic_cast is invalid.
template<typename U >
ref< U > unsafe_cast () const
 Cast the reference (unsafe). Return a new reference, possibly a null reference if the dynamic_cast is invalid.

Detailed Description

template<typename T>
class misc::ref< T >

A std::shared_ptr wrapper.

Compared to its super type, this implementation provides cast operators, and implicit constructors.

Member Typedef Documentation

template<typename T>
typedef T misc::ref< T >::element_type

The type pointed to.

template<typename T>
typedef std::shared_ptr<T> misc::ref< T >::super_type

The parent class.

Constructor & Destructor Documentation

template<typename T >
template<typename U >
misc::ref< T >::ref ( const ref< U > &  other)

Construct a new reference to the value pointed to by other. The new reference shares the property of the object with other.

template<typename T>
misc::ref< T >::ref ( const ref< T > &  other)

Copy constructor.

Although the implementation is subsumed by the previous, more generic one, the C++ standard still mandates this specific signature. Otherwise, the compiler will provide a default implementation, which is of course wrong. Note that the same applies for the assignment operator.

template<typename T>
misc::ref< T >::ref ( T *  p = nullptr)

Construct a counted reference to a newly allocated object. The new reference takes the property of the object pointed to by p. If p is null, then the reference is invalid and must be reset() before use.

template<typename T >
misc::ref< T >::~ref ( )

Destroy a reference. The object pointed to is destroyed iff it is not referenced anymore.

Member Function Documentation

template<typename T >
template<typename U >
ref< U > misc::ref< T >::cast ( ) const

Cast the reference. Return a new reference, possibly throwing an exception if the dynamic_cast is invalid.

template<typename T >
template<typename U >
bool misc::ref< T >::is_a ( ) const

Test fellowship. Return true if the reference points to an object which is really of the specified type.

template<typename T>
bool misc::ref< T >::operator!= ( const T *  p) const

Reference comparison. Returns false if this points to p.

template<typename T>
bool misc::ref< T >::operator== ( const T *  p) const

Reference comparison. Returns true if this points to p.

template<typename T >
template<typename U >
ref< U > misc::ref< T >::unsafe_cast ( ) const

Cast the reference (unsafe). Return a new reference, possibly a null reference if the dynamic_cast is invalid.


The documentation for this class was generated from the following files: