IlsSmartPointer
 
IlsSmartPointer
Category 
Smart pointer class template
Inheritance Path 
IlsSmartPointer
Related Pattern 
Proxy, flyweight
Description 
The class template IlsSmartPointer lets you declare smart pointers to objects of a given type. Objects referenced by smart pointers are automatically destroyed when their reference counter drops to zero.
PointedType must derive from IlsRefCounted. In case of multiple inheritance, we recommend that you make the derivation virtual to avoid the creation of multiple reference counters to the same object.
Libraries 
<server> and <mvcomp>
Header File 
#include <ilserver/refcount.h>
Synopsis 
template <class PointedType>
class IlsSmartPointer:
{
public:
IlsSmartPointer(PointedType* pointer=0);
IlsSmartPointer(const IlsSmartPointer<PointedType>& rhs);
 
~IlsSmartPointer();
 
IlsSmartPointer<PointedType>& operator=
(const IlsSmartPointer<PointedType>& rhs);
IlsSmartPointer<PointedType>& operator=(PointedType*rhs);
IlsSmartPointer<PointedType>& set(PointedType* rhs);
PointedType* getValue() const;
PointedType* operator->() const;
operator PointedType*() const;
PointedType& operator*() const;
IlsBoolean operator!() const;
IlsBoolean operator==(PointedType* rhs) const;
IlsBoolean operator!=(PointedType* rhs) const;
IlsBoolean operator==
(const IlsSmartPointer<PointedType>&) const;
IlsBoolean operator!=
(const IlsSmartPointer<PointedType>&) const;
};
Constructors 
IlsSmartPointer(PointedType* pointer=0);
This constructor increments the reference counter of the object to which the smart pointer points.
IlsSmartPointer(const IlsSmartPointer<PointedType>& rhs);
This is the copy constructor of IlsSmartPointer.
Destructor 
~IlsSmartPointer();
This destructor decrements the reference counter of the object to which the smart pointer points.
Member Functions 
IlsSmartPointer<PointedType>& set(PointedType* rhs);
This member function assigns a new value to the smart pointer.
PointedType* getValue() const;
This member function returns the value of the smart pointer. It is useful especially when the conversion operator, described below, cannot be used or when the compiler is likely to encounter multiple user-defined conversions.
Operators 
The operators below let you handle a smart pointer as if it were an ordinary pointer.
Note: IlsSmartPointer operators insure that the reference counter of an object remains equal to the number of smart pointers to the object at any time.
IlsSmartPointer<PointedType>& operator=
(const IlsSmartPointer<PointedType>& rhs);
This operator assigns a new smart pointer to the smart pointer.
IlsSmartPointer<PointedType>& operator=(PointedType* rhs);
This operator assigns an ordinary pointer to the smart pointer.
PointedType* operator->() const;
This operator returns the value of the smart pointer. If the smart pointer is null, the exception IlsNullPointerDereferencing is thrown.
operator PointedType*() const;
This operator converts a smart pointer to an ordinary pointer. If the smart pointer is null, then the exception IlsNullPointerEncountered is thrown.
PointedType& operator*() const;
This operator returns a reference to the pointed object. If the smart pointer is null, the exception IlsNullPointerDereferencing is thrown.
IlsBoolean operator!() const;
This operator returns IlsTrue if the smart pointer is null.
IlsBoolean operator==(PointedType* rhs) const;
This operator compares two pointers and returns IlsTrue if they are equal.
IlsBoolean operator!=(PointedType* rhs) const;
This operator compares two pointers and returns IlsTrue if they are not equal.
IlsBoolean operator==(const IlsSmartPointer<PointedType>&) const;
This operator compares two smart pointers and returns IlsTrue if they are equal.
IlsBoolean operator!=(const IlsSmartPointer<PointedType>&) const;
This operator compares two smart pointers and returns IlsTrue if they are not equal.
See Also 
Exceptions, IlsEntity, IlsObject, IlsRefCounted

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.