Common Library dynamic array template class

Source: Internet
Author: User

/// 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.