/// Common library dynamic array template class
/**
* General Library version 4.0 <br>
* A dynamic array template class is defined here. This time, the previous XDyanmicArray and XArray are merged into an XArray.
* In addition, the array element initialization operation is added to 0. At the same time, the default constructor and analysis function of the array element are executed.
* Similarly, this dynamic array is suitable for elements that do not contain pointer data members or elements that use additional resources in metadata.
* The XObjectArray template class can be used for arrays whose objects are array elements to effectively solve the problem.
* @ Author zdhsoft (Zhu Donghua)
* @ Version 4.0
* @ Date 2008-03-01
* @ File xarray. h
* @ Test has been tested
*/
# Ifndef _ X_ARRAY_H _
# Define _ X_ARRAY_H _
# Include <xcommon. h>
# Include <xexception. h>
Namespace zdh
{
Const XInt ARRAY_INVALID_INDEX =-1;
/// Array template class
Template <class T>
Class XArray
{
Public:
Typedef T ElementType;
Typedef ElementType * PElementType;
/// Default constructor
XArray ()
: M_Length (0), m_Capacity (0), m_Data (NULL)
{}
/// Constructor that specifies the number of initial elements
/**
@ Param [in] aInitLength initializes the size of the array
*/
XArray (XInt aInitLength)
: M_Length (0), m_Capacity (0), m_Data (NULL)
{
If (aInitLength> 0)
{
InitLength (aInitLength );
}
}
/// Constructor that specifies the number of initial elements and default element values
/**
@ Param [in] aInitLength initializes the size of the array
@ Param [in] aDefault initialize the default value of the array element
*/
XArray (XInt aInitLength, const T & aDefault)
: M_Length (0), m_Capacity (0), m_Data (NULL)
{
If (aInitLength> 0)
{
InitLength (aInitLength, aDefault );
}
}
/// Default copy constructor
XArray (const XArray <T> & v );
/// Constructor that specifies the size and initial element pointer
XArray (const T * pData, XInt aSize, XInt aStartIndex = 0 );
/// Specify the size and the constructor of the initial element array
XArray (const XArray <T> & v, XInt aSize, XInt aStartIndex = 0 );
/// Destructor
~ XArray