Rogue Wave Views
Foundation Package API Reference Guide
Product Documentation:

Rogue Wave Views
Documentation Home
List of all members | Public Member Functions
IlvRefCountPtr< LOCKABLE > Class Template Reference

Non-intrusive Reference Counter smart pointer. More...

#include <ilviews/util/refcount.h>

Inherited by IlvInitializedRefCountPtr< LOCKABLE >.

Public Member Functions

ILVEXPLICIT IlvRefCountPtr (LOCKABLE *ptr=0)
 The default constructor. More...
 
 IlvRefCountPtr (const IlvRefCountPtr &src)
 The copy constructor. More...
 
 ~IlvRefCountPtr ()
 The destructor. More...
 
LOCKABLE * get () const
 This function returns a pointer to the object pointed to by this instance. More...
 
LOCKABLE & operator* () const
 The dereference operator. More...
 
LOCKABLE * operator-> () const
 The structure pointer dereference operator. More...
 
IlvRefCountPtroperator= (const IlvRefCountPtr &src)
 The assignment operator from another IlvRefCountPtr. More...
 
IlvRefCountPtroperator= (LOCKABLE *ptr)
 The assignment operator from a pointer to an object. More...
 

Detailed Description

template<class LOCKABLE>
class IlvRefCountPtr< LOCKABLE >

Non-intrusive Reference Counter smart pointer.

Library: xviews or winviews or mviews (mutually exclusive)

This template class is adapted from the class shared_ptr of Boost. A counter keeps the number of references to this object. As soon as the counter is decreased to 0, the object is deleted. Of course the only way to reference this object must be by means of an IlvRefCountPtr, otherwise dangling pointers could exist.

Constructor & Destructor Documentation

§ IlvRefCountPtr() [1/2]

template<class LOCKABLE>
ILVEXPLICIT IlvRefCountPtr< LOCKABLE >::IlvRefCountPtr ( LOCKABLE *  ptr = 0)

The default constructor.

This constructor should be called only once for an object. Other instances must be built by the copy constructor.

Parameters
ptrA pointer to an object of type LOCKABLE given as parameter of the template.
See also
IlvRefCountPtr::IlvRefCountPtr(const IlvRefCountPtr&).

§ IlvRefCountPtr() [2/2]

template<class LOCKABLE>
IlvRefCountPtr< LOCKABLE >::IlvRefCountPtr ( const IlvRefCountPtr< LOCKABLE > &  src)

The copy constructor.

This constructor is called to create a new instance that will share the same object as src. The counter is incremented.

Parameters
srcA const reference to an IlvRefCountPtr of the same type LOCKABLE given as parameter of the template.
See also
IlvRefCountPtr::IlvRefCountPtr(LOCKABLE* ptr = 0).

§ ~IlvRefCountPtr()

template<class LOCKABLE>
IlvRefCountPtr< LOCKABLE >::~IlvRefCountPtr ( )

The destructor.

The destructor first decrements the counter. If the count reaches 0, the object pointed to by this instance is deleted.

Member Function Documentation

§ get()

template<class LOCKABLE>
LOCKABLE* IlvRefCountPtr< LOCKABLE >::get ( ) const

This function returns a pointer to the object pointed to by this instance.

Returns
A pointer to a LOCKABLE that is to the object pointed to by this instance.

§ operator*()

template<class LOCKABLE>
LOCKABLE& IlvRefCountPtr< LOCKABLE >::operator* ( ) const

The dereference operator.

This operator returns a reference to the object pointed to by this instance. It lets this class behave as if it were a pointer.

Returns
A reference to the object pointed to by this instance.

§ operator->()

template<class LOCKABLE>
LOCKABLE* IlvRefCountPtr< LOCKABLE >::operator-> ( ) const

The structure pointer dereference operator.

This operator returns a pointer to the object pointed to by this instance. It lets this class behave as if it was a pointer.

Returns
A pointer to the object pointed to by this instance.

§ operator=() [1/2]

template<class LOCKABLE>
IlvRefCountPtr& IlvRefCountPtr< LOCKABLE >::operator= ( const IlvRefCountPtr< LOCKABLE > &  src)

The assignment operator from another IlvRefCountPtr.

This operator stores the pointer to the object and the counter of src. The counter is incremented. If a previous object was already pointed to, then its counter is decremented, and the object is deleted in case the counter reaches 0.

Parameters
srcA const reference to this IlvRefCountPtr.

§ operator=() [2/2]

template<class LOCKABLE>
IlvRefCountPtr& IlvRefCountPtr< LOCKABLE >::operator= ( LOCKABLE *  ptr)

The assignment operator from a pointer to an object.

This operator stores a pointer to the object with a counter set to 1. If a previous object was already pointed to, then its counter is decremented, and the object is deleted in case the counter reaches 0.
WARNINGAn object already associated with an instance of IlvRefCountPtr must never be assigned to another instance of IlvRefCountPtr with this operator. It must be done through the other form of the operator=.

Parameters
ptrA pointer to a LOCKABLE object to be pointed to.

© Copyright 2018, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.