csRef< T > Class Template Reference
A smart pointer. More...
#include <csutil/ref.h>
| Public Member Functions | |
| void | AttachNew (csPtr< T > newObj) | 
| Assign an object reference created with the new operator to this smart pointer. | |
| csRef (csRef const &other) | |
| Smart pointer copy constructor. | |
| template<class T2> | |
| csRef (csRef< T2 > const &other) | |
| Smart pointer copy constructor from assignment-compatible csRef<T2>. | |
| template<class T2> | |
| csRef (T2 *newobj) | |
| Construct a smart pointer from a raw object reference with a compatible type. | |
| csRef (T *newobj) | |
| Construct a smart pointer from a raw object reference. | |
| csRef (const csPtr< T > &newobj) | |
| Construct a smart pointer from a csPtr. | |
| csRef () | |
| Construct an invalid smart pointer (that is, one pointing at nothing). | |
| uint | GetHash () const | 
| Return a hash value for this smart pointer. | |
| void | Invalidate () | 
| Invalidate the smart pointer by setting it to null. | |
| bool | IsValid () const | 
| Smart pointer validity check. | |
| T & | operator * () const | 
| Dereference underlying object. | |
| operator T * () const | |
| Cast smart pointer to a pointer to the underlying object. | |
| T * | operator-> () const | 
| Dereference underlying object. | |
| csRef & | operator= (csRef const &other) | 
| Assign another csRef<> of the same type to this one. | |
| template<class T2> | |
| csRef & | operator= (csRef< T2 > const &other) | 
| Assign another assignment-compatible csRef<T2> to this one. | |
| csRef & | operator= (T *newobj) | 
| Assign a raw object reference to this smart pointer. | |
| csRef & | operator= (const csPtr< T > &newobj) | 
| Assign a csPtr to a smart pointer. | |
| ~csRef () | |
| Smart pointer destructor. | |
| Friends | |
| bool | operator!= (T *obj, const csRef &r1) | 
| Test if object pointed to by reference is different from obj. | |
| bool | operator!= (const csRef &r1, T *obj) | 
| Test if object pointed to by reference is different from obj. | |
| bool | operator!= (const csRef &r1, const csRef &r2) | 
| Test if the two references point to different object. | |
| bool | operator< (const csRef &r1, const csRef &r2) | 
| Test the relationship of the addresses of two objects. | |
| bool | operator== (T *obj, const csRef &r1) | 
| Test if object pointed to by reference is same as obj. | |
| bool | operator== (const csRef &r1, T *obj) | 
| Test if object pointed to by reference is same as obj. | |
| bool | operator== (const csRef &r1, const csRef &r2) | 
| Test if the two references point to same object. | |
Detailed Description
template<class T>
 class csRef< T >
A smart pointer. 
Maintains and correctly manages a reference to a reference-counted object. This template requires only that the object type T implement the methods IncRef() and DecRef(). No other requirements are placed upon T.
Definition at line 123 of file ref.h.
Constructor & Destructor Documentation
Member Function Documentation
Assign an object reference created with the new operator to this smart pointer.
- Remarks:
- This function allows you to assign an object pointer created with the newoperator to the csRef object. Proper usage would be:While not recommended, you can also use this function to assign a csPtr object or csRef object to the csRef. In both of these cases, using AttachNew is equivalent to performing a simple assignment using thecsRef<iEvent> event; event.AttachNew (new csEvent); =operator.
- Note:
- Calling this function is equivalent to casting an object to a csPtr<T> and then assigning the csPtr<T> to the csRef, as follows: // Same effect as above code. csRef<iEvent> event = csPtr<iEvent> (new csEvent); 
Definition at line 272 of file ref.h.
Referenced by CS::ImageAutoConvert::ImageAutoConvert().
| void csRef< T >::Invalidate | ( | ) |  [inline] | 
| bool csRef< T >::IsValid | ( | ) | const  [inline] | 
Smart pointer validity check.
Returns true if smart pointer is pointing at an actual object, otherwise returns false.
Definition at line 354 of file ref.h.
Referenced by csG2DDrawText< Tpixel, Tpixmixer1, Tpixmixer2, Tpixmixer3 >::DrawText(), csShaderProgram::GetParamFloatVal(), csShaderProgram::GetParamTransformVal(), csShaderProgram::GetParamVectorVal(), and CS::DocumentHelper::Implementation::FilterDocumentNodeIterator< T >::HasNext().
| T& csRef< T >::operator * | ( | ) | const  [inline] | 
| csRef< T >::operator T * | ( | ) | const  [inline] | 
| T* csRef< T >::operator-> | ( | ) | const  [inline] | 
Assign a raw object reference to this smart pointer.
- Remarks:
- This function calls the object's IncRef() method. Because of this you should not assign a reference created with the new operator to a csRef object driectly. The following code will produce a memory leak: If you are assigning a new object to a csRef, use AttachNew(T* newObj) instead.csRef<iEvent> event = new csEvent; 
Assign a csPtr to a smart pointer.
Doesn't call IncRef() on the object since it is assumed that the object in csPtr is already IncRef()'ed.
- Remarks:
- After this assignment, the csPtr<T> object is invalidated and cannot be used. You should not (and in fact cannot) decref the csPtr<T> after this assignment has been made.
Definition at line 206 of file ref.h.
Referenced by csRef< iGraphics2D >::operator=().
Friends And Related Function Documentation
| bool operator!= | ( | T * | obj, | |
| const csRef< T > & | r1 | |||
| ) |  [friend] | 
| bool operator!= | ( | const csRef< T > & | r1, | |
| T * | obj | |||
| ) |  [friend] | 
| bool operator== | ( | T * | obj, | |
| const csRef< T > & | r1 | |||
| ) |  [friend] | 
| bool operator== | ( | const csRef< T > & | r1, | |
| T * | obj | |||
| ) |  [friend] | 
The documentation for this class was generated from the following file:
- csutil/ref.h
Generated for Crystal Space by doxygen 1.4.7

