template<typename YI_ARRAY_TYPE, typename YI_DELETE_FUNCTOR = CYICheckedArrayDeleteFunctor<YI_ARRAY_TYPE>>
class CYIScopedArray< YI_ARRAY_TYPE, YI_DELETE_FUNCTOR >
The CYIScopedArray is a smart pointer that takes sole ownership of a dynamically allocated array of objects, and destroys the array when going out of scope using the delete [] operator.
- Deprecated:
- This class has been deprecated and may be removed in a future release. The std::unique_ptr class should be used instead.
Very similar to the CYIScopedPtr while deleting its internal pointer with the delete[] operator. It also provides the operator[] for your convenience.
Usage example:
void Func()
{
fData[0] = 1.618f;
fData[1] = 3.141f;
fData[2] = -9.8f;
}
Like the CYIScopedPtr, the delete function object can be overridden
#define MAX_THREAD 100
class MyCustomDeleteFunctor
{
public:
void operator()(MyThread services[])
{
for (int32_t i = 0; i < MAX_THREAD; ++i)
{
if (services[i]->IsRunning())
{
services[i]->Stop();
}
}
delete [] services;
}
};
class MyClass
{
private:
public:
MyClass() : m_services(new MyThread[MAX_THREAD])
{
for (int32_t i = 0; i < MAX_THREAD; ++i)
{
services[i]->Start();
}
}
virtual ~MyClass
{
}
};
- Warning
- CYIScopedArray is not thread-safe
- See also
- CYIScopedPtr
-
CYISharedPtr
-
CYISharedArray
-
CYIWeakPtr
-
CYIWeakArray
template<typename YI_ARRAY_TYPE, typename YI_DELETE_FUNCTOR = CYICheckedArrayDeleteFunctor<YI_ARRAY_TYPE>>
| void CYIScopedArray< YI_ARRAY_TYPE, YI_DELETE_FUNCTOR >::operator= |
( |
YI_ARRAY_TYPE |
pPtr[] | ) |
|
|
inline |
This function deletes the currently assigned pointer using the default or provided delete function object, and then take ownership of the new pointer.
Can also be used to prematurely delete the internal pointer by assigning to nullptr.
Example:
void Func()
{
...
pData = new MyData();
if (pData.IsNull())
{
...
}
...
pData = nullptr;
if (pData.IsNull())
{
...
}
}
- Parameters
-
| pPtr | the new object to take ownership. pPtr will be deleted in CYIScopedPtr destructor using the default or provided delete function object. |
template<typename YI_ARRAY_TYPE, typename YI_DELETE_FUNCTOR = CYICheckedArrayDeleteFunctor<YI_ARRAY_TYPE>>
template<typename YI_PTR_OTHER_TYPE , typename YI_OTHER_DELETER >
This function deletes the currently assigned pointer using the default or provided delete function object, and then moves the pointer of other into this scoped pointer instance. The pointer type and deleter type of other must be convertible to the types of this CYIScopedPtr.
- Parameters
-
| other | the CYIScopedPtr to move (it will point to null after this function call completes) |
template<typename YI_ARRAY_TYPE, typename YI_DELETE_FUNCTOR = CYICheckedArrayDeleteFunctor<YI_ARRAY_TYPE>>
| void CYIScopedArray< YI_ARRAY_TYPE, YI_DELETE_FUNCTOR >::Reset |
( |
YI_ARRAY_TYPE |
pPtr[] = nullptr | ) |
|
|
inline |
Syntactic sugar for operator=(),
This function deletes the currently assigned pointer using the default or provided delete function object, and then take ownership of the new pointer.
Can also be used to prematurely delete the internal pointer by reseting to nullptr.
Example:
void Func()
{
...
pData.Reset(new MyData());
if (pData.IsNull())
{
...
}
...
pData.Reset();
if (pData.IsNull())
{
...
}
}
- Parameters
-
| pPtr | the new object to take ownership. pPtr will be deleted in CYIScopedPtr destructor using the default or provided delete function object. |