#ifndef SPTPLARR_H # Define SPTPLARR_H # include #include #include "spTexc.h" namespace spt {namespace tpl {/// template class array {public: array (); Array (array & array); virtual ~ array (); array & operator = (array & array); public: void create (long count); void setcount (long count) Void setsize; void release (); void Empty () {m_count = 0;} public: void setall (t elem); Void Addelem (t & elem); void setpelocsize (ize) {ix > 0) m_per_alloc_size = size;} public: long getSize () {return m_size;} long getCount () {return m_count;} t * getBuffer () {return m_data;} BOOL ISEMPTY ()}} BOOL ISEMPTY ()}} BOOL ISEMPTY ()} Bool isreleased () {return m_data == null;} Bool ISI NSIDE (LONG POS) {RETURN POS> = 0 && POS array :: array () {Init ();} template array :: array (array <
T> & array) {init (); * this = array;} template array :: array (long count) {init (); create (count);} template array :: ~ array () {release ();} template array & array :: operator = (array & array) {i (this == & array) return * this SetCount (array.m_count); for (long i = 0; i inline void array :: Init () {m_data = NULL; m_count = m_size = 0; m_per_alloc_size = sptDefaultPerAllocSize; assert (m_per_alloc_size> 0);} template inline void Array :: Release () {delete [] m_data Init ();} Template < Class T> Void Array :: Resize (length <0) return; if (size == 0) {release (); return;} size = getNeedallocSize (size); if (m_count = = 0) {release (); m_data = new t [size]; if (m_data == null) throw exception (fail_alloc); m_count = 0; m_size = size;
} Else {long count = spt_min (m_count, size); long tmp_size = count * sizeof (t); char * tmp = new char [tmp_size]; if (tmp == null) throw exception (fail_alloc); T * Data = New t [size]; if (data == null) THROW EXCEPTION (FAIL_ALLOC); Memcpy (TMP, M_DATA, TMP_SIZE); Memcpy (M_Data, DATA, TMP_SIZE); Memcpy (Data, TMP, TMP_SIZE); delete [] TMP Release (); m_data = data; m_count = count; m_size = size;}} template inline long array :: getneedallocsize (length> 0); assert (m_per_alloc_size> 0 ); RETURN (SIZE M_PER_ALLOC_SIZE 1) / m_per_alloc_size * m_per_alloc_size;} template in Line Void Array :: Create (long count) {release (); setcount (count);} template inline void array :: setCount (long count) {if (count> m_size) Resize (count); m_count = count;} template inline void array :: setsize (long size) {if (size> m_size) resize (size);} // Template Inline void Array :: setall (t elem) {for (long i = 0; i