【www.gdgbn.com--linux】

///通用库动态对象数组模板类
/**
 * 通用库4.0版

 * 这里定义了一个动态对象数组模板类。这个数组适合不能移动的对象或含有指针或被引用的对象。
 * 特点就是,不会像XArray中一样,调整数组容量,会造所有数组元素地址都发生变化。
 * @author zdhsoft(祝冬华)
 * @version 4.0
 * @date 2008-03-01
 * @file xobjectarray.h
 */
#ifndef _X_OBJECT_ARRAY_H_
#define _X_OBJECT_ARRAY_H_
#include
namespace zdh
{
 ///动态对象数组
 template
 class XObjectArray
 {
 public:
  typedef T ElementType;
  typedef ElementType * PElementType;
  ///默认构造函数
  XObjectArray()
  {}
  ///指定初始元素个数的构造函数
  /**
   @param [in] aInitLength 初始化数组的大小
  */
  XObjectArray(XInt aInitLength)
  {
   if( aInitLength > 0)
   {
    InitLength(aInitLength);
   }
  }
  ///指定初始元素个数以及缺省元素值的构造函数
  /**
    @param [in] aInitLength 初始化数组的大小
    @param [in] aDefault 初始化数组元素的默认值
  */
  XObjectArray(XInt aInitLength,const T & aDefault)
  {
   if( aInitLength > 0)
   {
    InitLength(aInitLength,aDefault);
   }
  }
  ///缺省拷贝构造函数
  XObjectArray(const XObjectArray & v);
  ///指定大小以及初始元素指针的构造函数
  XObjectArray(const T * pData,XInt aSize,XInt aStartIndex = 0);
  ///指定大小以及初始元素数组的构造函数
  XObjectArray(const XObjectArray & v,XInt aSize,XInt aStartIndex = 0);

  ///默认析构函数
  ~XObjectArray()
  {
   Clear();
  }
  ///清除数组
  void Clear();
  ///取数组的最大容量
  XInt getMaxCapacity() const
  {
   return 0x7ffffff0 / sizeof(T);
  }

本文来源:http://www.gdgbn.com/caozuoxitong/13147/