MPQC 2.3.1
sc::Ref< T > Class Template Reference

A template class that maintains references counts. More...

#include <ref.h>

Inheritance diagram for sc::Ref< T >:
Collaboration diagram for sc::Ref< T >:

Public Member Functions

 Ref ()
 Create a reference to a null object.
 Ref (T *a)
 Create a reference to the object a.
 Ref (const Ref< T > &a)
 Create a reference to the object referred to by a.
template<class A>
 Ref (const Ref< A > &a)
 Create a reference to the object referred to by a.
 ~Ref ()
 Delete this reference to the object.
T * operator-> () const
 Returns the reference counted object.
T * pointer () const
 Returns a pointer the reference counted object.
RefCount * parentpointer () const
 Implements the parentpointer pure virtual in the base class.
 operator T* () const
T & operator* () const
 Returns a C++ reference to the reference counted object.
int null () const
 Return 1 if this is a reference to a null object.
int nonnull () const
 Return !null().
template<class A>
int operator== (const Ref< A > &a) const
 A variety of ordering and equivalence operators are provided using the Identity class.
template<class A>
int operator>= (const Ref< A > &a) const
template<class A>
int operator<= (const Ref< A > &a) const
template<class A>
int operator> (const Ref< A > &a) const
template<class A>
int operator< (const Ref< A > &a) const
template<class A>
int operator!= (const Ref< A > &a) const
int compare (const Ref< T > &a) const
 Compare two objects returning -1, 0, or 1.
void clear ()
 Refer to the null object.
Ref< T > & operator= (const Ref< T > &c)
 Assignment to c.
template<class A>
Ref< T > & operator= (const Ref< A > &c)
 Assignment to c.
Ref< T > & operator<< (const RefBase &a)
 Assignment to the object that a references using dynamic_cast.
Ref< T > & operator<< (RefCount *a)
 Assigns to the given base class pointer using dynamic_cast.
Ref< T > & operator= (T *cr)
 Assignment to cr.
void assign_pointer (T *cr)
 Assignment to cr.
void check_pointer () const
 Check the validity of the pointer.
void ref_info (std::ostream &os) const
 Print information about the reference to os.
void warn (const char *s) const
 Print a warning concerning the reference.
Public Member Functions inherited from sc::RefBase
void require_nonnull () const
 Requires that a nonnull reference is held.

Additional Inherited Members

Protected Member Functions inherited from sc::RefBase
void warn (const char *msg) const
 Print a warning message.
void warn_ref_to_stack () const
 Called when stack data is referenced.
void warn_skip_stack_delete () const
 Called when the deletion of stack data is skipped.
void warn_bad_ref_count () const
 Called when the reference count is corrupted.
void ref_info (RefCount *p, std::ostream &os) const
 Print information about the reference.
void ref_info (std::ostream &os) const
void check_pointer () const
void reference (RefCount *)
int dereference (RefCount *)

Detailed Description

template<class T>
class sc::Ref< T >

A template class that maintains references counts.

Several of these operations can cause a reference to an object to be replaced by a reference to a different object. If a reference to a nonnull object is eliminated, the object's reference count is decremented and the object is deleted if the reference count becomes zero.

There also may be a to convert to T*, where T is the type of the object which Ref references. Some compilers have bugs that prevent the use of operator T*(). The pointer() member should be used instead.

Constructor & Destructor Documentation

◆ Ref() [1/3]

template<class T>
sc::Ref< T >::Ref ( )
inline

Create a reference to a null object.

Referenced by compare(), operator<<(), operator=(), operator=(), operator==(), Ref(), and Ref().

◆ Ref() [2/3]

template<class T>
sc::Ref< T >::Ref ( const Ref< T > & a)
inline

Create a reference to the object referred to by a.

References pointer(), and Ref().

◆ Ref() [3/3]

template<class T>
template<class A>
sc::Ref< T >::Ref ( const Ref< A > & a)
inline

Create a reference to the object referred to by a.

References pointer(), and Ref().

◆ ~Ref()

template<class T>
sc::Ref< T >::~Ref ( )
inline

Delete this reference to the object.

Decrement the object's reference count and delete the object if the count is zero.

References clear().

Member Function Documentation

◆ assign_pointer()

template<class T>
void sc::Ref< T >::assign_pointer ( T * cr)
inline

Assignment to cr.

References clear(), and sc::RefBase::warn_ref_to_stack().

Referenced by operator=().

◆ check_pointer()

template<class T>
void sc::Ref< T >::check_pointer ( ) const
inline

Check the validity of the pointer.

References sc::RefBase::warn_bad_ref_count().

◆ clear()

template<class T>
void sc::Ref< T >::clear ( )
inline

Refer to the null object.

Referenced by assign_pointer(), operator<<(), operator=(), and ~Ref().

◆ compare()

template<class T>
int sc::Ref< T >::compare ( const Ref< T > & a) const
inline

Compare two objects returning -1, 0, or 1.

Similar to the C library routine strcmp.

References Ref().

◆ null()

template<class T>
int sc::Ref< T >::null ( ) const
inline

Return 1 if this is a reference to a null object.

Otherwise return 0.

◆ operator*()

template<class T>
T & sc::Ref< T >::operator* ( ) const
inline

Returns a C++ reference to the reference counted object.

The behaviour is undefined if the object is null.

◆ operator->()

template<class T>
T * sc::Ref< T >::operator-> ( ) const
inline

Returns the reference counted object.

The behaviour is undefined if the object is null.

◆ operator<<() [1/2]

template<class T>
Ref< T > & sc::Ref< T >::operator<< ( const RefBase & a)
inline

Assignment to the object that a references using dynamic_cast.

References clear(), operator=(), pointer(), and Ref().

◆ operator<<() [2/2]

template<class T>
Ref< T > & sc::Ref< T >::operator<< ( RefCount * a)
inline

Assigns to the given base class pointer using dynamic_cast.

If the dynamic_cast fails and the argument is nonnull and has a reference count of zero, then it is deleted.

◆ operator=() [1/2]

template<class T>
Ref< T > & sc::Ref< T >::operator= ( const Ref< T > & c)
inline

Assignment to c.

References clear(), pointer(), and Ref().

Referenced by operator<<().

◆ operator=() [2/2]

template<class T>
Ref< T > & sc::Ref< T >::operator= ( T * cr)
inline

Assignment to cr.

References assign_pointer(), and Ref().

◆ operator==()

template<class T>
template<class A>
int sc::Ref< T >::operator== ( const Ref< A > & a) const
inline

A variety of ordering and equivalence operators are provided using the Identity class.

References pointer(), and Ref().

◆ parentpointer()

template<class T>
RefCount * sc::Ref< T >::parentpointer ( ) const
inlinevirtual

Implements the parentpointer pure virtual in the base class.

Implements sc::RefBase.

◆ pointer()

template<class T>
T * sc::Ref< T >::pointer ( ) const
inline

Returns a pointer the reference counted object.

Referenced by operator<<(), operator=(), operator==(), Ref(), and Ref().

◆ ref_info()

template<class T>
void sc::Ref< T >::ref_info ( std::ostream & os) const
inline

Print information about the reference to os.

References sc::RefBase::ref_info().

◆ warn()

template<class T>
void sc::Ref< T >::warn ( const char * s) const
inline

Print a warning concerning the reference.

References sc::RefBase::warn().


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

Generated at for MPQC 2.3.1 using the documentation package Doxygen 1.18.0.