00001 /* 00002 * $Id: Array.h,v 1.3 2003/06/30 00:18:06 mindstorm2600 Exp $ 00003 */ 00004 #ifndef __CLAW_ARRAY_H__ 00005 #define __CLAW_ARRAY_H__ 00006 #include<Container.h> 00007 #ifdef USE_MEMCPY 00008 #include<string.h> 00009 #endif 00010 00011 namespace clawsoft{ 00012 00016 template<class T> 00017 class Array:public Container{ 00018 protected: 00019 T *array; 00020 void copy(T *dst, T *src, unsigned int n){ 00021 unsigned int i; 00022 #ifdef USE_MEMCPY 00023 memcpy(dst, src, n * sizeof(T)); 00024 #else 00025 for(i = 0; i < n; i++){ 00026 dst[i] = src[i]; 00027 } 00028 #endif 00029 } 00030 public: 00031 Array():Container(clawsoft::_clawArray){ 00032 array = 0; 00033 } 00034 Array &add(T data){ 00035 T *tmp; 00036 num_data++; 00037 if(num_data){ 00038 tmp = new T[num_data]; 00039 copy(tmp, array); 00040 claw_delete_array(array); 00041 tmp[num_data - 1] = data; 00042 array = tmp; 00043 } 00044 else{ 00045 array = new T[num_data]; 00046 array[0] = data; 00047 } 00048 return *this; 00049 } 00050 }; 00051 }; 00052 00053 #endif
Authors:
Juan V. Guerrero
Jannette C. Mejia
Juan C. Guevara
Powered by: