Qt 4.8
Public Functions | Private Functions | List of all members
QScopedArrayPointer< T, Cleanup > Class Template Reference

The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects, and deletes it upon destruction. More...

#include <qscopedpointer.h>

Inheritance diagram for QScopedArrayPointer< T, Cleanup >:
QScopedPointer< T, Cleanup >

Public Functions

T & operator[] (int i)
 Provides access to entry i of the scoped pointer's array of objects. More...
 
const T & operator[] (int i) const
 Provides access to entry i of the scoped pointer's array of objects. More...
 
 QScopedArrayPointer ()
 Constructs a QScopedArrayPointer instance. More...
 
template<typename D >
 QScopedArrayPointer (D *p, typename QtPrivate::QScopedArrayEnsureSameType< T, D >::Type=0)
 
- Public Functions inherited from QScopedPointer< T, Cleanup >
T * data () const
 Returns the value of the pointer referenced by this object. More...
 
bool isNull () const
 Returns true if this object is holding a pointer that is null. More...
 
 operator bool () const
 Returns true if this object is not null. More...
 
bool operator! () const
 Returns true if the pointer referenced by this object is null, otherwise returns false. More...
 
T & operator* () const
 Provides access to the scoped pointer's object. More...
 
T * operator-> () const
 Provides access to the scoped pointer's object. More...
 
 QScopedPointer (T *p=0)
 Constructs this QScopedPointer instance and sets its pointer to p. More...
 
void reset (T *other=0)
 Deletes the existing object it is pointing to if any, and sets its pointer to other. More...
 
void swap (QScopedPointer< T, Cleanup > &other)
 Swap this pointer with other. More...
 
T * take ()
 Returns the value of the pointer referenced by this object. More...
 
 ~QScopedPointer ()
 Destroys this QScopedPointer object. More...
 

Private Functions

 QScopedArrayPointer (void *)
 

Additional Inherited Members

- Public Types inherited from QScopedPointer< T, Cleanup >
typedef T * pointer
 
- Protected Variables inherited from QScopedPointer< T, Cleanup >
T * d
 

Detailed Description

template<typename T, typename Cleanup = QScopedPointerArrayDeleter<T>>
class QScopedArrayPointer< T, Cleanup >

The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects, and deletes it upon destruction.

Since
4.6
Note
This class or function is reentrant.

A QScopedArrayPointer is a QScopedPointer that defaults to deleting the object it is pointing to with the delete[] operator. It also features operator[] for convenience, so we can write:

void foo()
{
QScopedArrayPointer<int> i(new int[10]);
i[2] = 42;
...
return; // our integer array is now deleted using delete[]
}

Definition at line 208 of file qscopedpointer.h.

Constructors and Destructors

◆ QScopedArrayPointer() [1/3]

template<typename T, typename Cleanup = QScopedPointerArrayDeleter<T>>
QScopedArrayPointer< T, Cleanup >::QScopedArrayPointer ( )
inline

Constructs a QScopedArrayPointer instance.

Definition at line 211 of file qscopedpointer.h.

The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...

◆ QScopedArrayPointer() [2/3]

template<typename T, typename Cleanup = QScopedPointerArrayDeleter<T>>
template<typename D >
QScopedArrayPointer< T, Cleanup >::QScopedArrayPointer ( D p,
typename QtPrivate::QScopedArrayEnsureSameType< T, D >::Type  = 0 
)
inlineexplicit

Definition at line 214 of file qscopedpointer.h.

216  {
217  }
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...

◆ QScopedArrayPointer() [3/3]

template<typename T, typename Cleanup = QScopedPointerArrayDeleter<T>>
QScopedArrayPointer< T, Cleanup >::QScopedArrayPointer ( void *  )
inlineexplicitprivate

Definition at line 230 of file qscopedpointer.h.

230  {
231  // Enforce the same type.
232 
233  // If you get a compile error here, make sure you declare
234  // QScopedArrayPointer with the same template type as you pass to the
235  // constructor. See also the QScopedPointer documentation.
236 
237  // Storing a scalar array as a pointer to a different type is not
238  // allowed and results in undefined behavior.
239  }

Functions

◆ operator[]() [1/2]

template<typename T, typename Cleanup = QScopedPointerArrayDeleter<T>>
T * QScopedArrayPointer< T, Cleanup >::operator[] ( int  i)
inline

Provides access to entry i of the scoped pointer's array of objects.

If the contained pointer is null, behavior is undefined.

See also
isNull()

Definition at line 219 of file qscopedpointer.h.

220  {
221  return this->d[i];
222  }

◆ operator[]() [2/2]

template<typename T, typename Cleanup = QScopedPointerArrayDeleter<T>>
T * QScopedArrayPointer< T, Cleanup >::operator[] ( int  i) const
inline

Provides access to entry i of the scoped pointer's array of objects.

If the contained pointer is null, behavior is undefined.

See also
isNull()

Definition at line 224 of file qscopedpointer.h.

225  {
226  return this->d[i];
227  }

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