Changeset 2291 for GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx
- Timestamp:
- 03/26/07 08:46:55 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Array.h
r1526 r2291 37 37 inline void array<T>::init(int l) 38 38 { 39 data =new T[l];40 len =l;39 data = new T[l]; 40 len = l; 41 41 } 42 42 … … 44 44 inline void array<T>::f_r_e_e() 45 45 { 46 if( data)46 if(data) 47 47 { 48 delete [] data;48 delete [] data; 49 49 data = NULL; 50 50 } … … 55 55 { 56 56 #ifdef SAFETY 57 assert( data);58 assert( i>=0 && i<len);57 assert(data); 58 assert(i >= 0 && i < len); 59 59 #endif 60 60 return data[i]; … … 65 65 { 66 66 #ifdef SAFETY 67 assert( data);68 assert( i>=0 && i<len);67 assert(data); 68 assert(i >= 0 && i < len); 69 69 #endif 70 70 return data[i]; … … 74 74 inline void array<T>::resize(int l) 75 75 { 76 T *old = data; 77 data = new T[l]; 78 data = (T *)memcpy(data,old,MIN(len,l)*sizeof(T)); 79 len = l; 80 delete[] old; 76 T *old = data; 77 data = new T[l]; 78 data = (T *)memcpy(data,old,MIN(len,l)*sizeof(T)); 79 len = l; 80 81 delete [] old; 81 82 } 82 83 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Buffer.h
r2090 r2291 7 7 { 8 8 template<class T> 9 class buffer : public array<T> { 10 protected: 11 int fill; 12 public: 13 buffer() { init(8); } 14 buffer(int l) { init(l); } 15 16 inline void init(int l) { array<T>::init(l); fill=0; } 9 class buffer : public array<T> { 10 protected: 11 int fill; 12 public: 13 buffer() { init(8); } 14 buffer(int l) { init(l); } 17 15 18 inline int add(const T& t); 19 inline void reset(); 20 inline int find(const T&); 21 inline T remove(int i); 22 inline int addAll(const buffer<T>& buf); 23 inline void removeDuplicates(); 16 inline void init(int l) { array<T>::init(l); fill=0; } 24 17 25 inline int length() const { return fill; } 26 inline int maxLength() const { return len; } 27 inline void setFill(int l){fill = l;} 28 }; 18 inline int add(const T& t); 19 inline void reset(); 20 inline int find(const T&); 21 inline T remove(int i); 22 inline int addAll(const buffer<T>& buf); 23 inline void removeDuplicates(); 24 25 inline int length() const { return fill; } 26 inline int maxLength() const { return len; } 27 inline void setFill(int l){fill = l;} 28 }; 29 29 30 30 template<class T> 31 inline int buffer<T>::add(const T& t) 32 { 33 if( fill == len ) 31 inline int buffer<T>::add(const T& t) 34 32 { 35 resize( len*2 ); 33 if(fill == len) 34 { 35 resize(len * 2); 36 } 37 38 data[fill] = t; 39 40 return fill++; 36 41 } 37 42 38 data[fill] = t; 39 40 return fill++; 41 } 43 template<class T> 44 inline void buffer<T>::reset() 45 { 46 fill = 0; 47 } 42 48 43 49 template<class T> 44 inline void buffer<T>::reset() 45 { 46 fill = 0; 47 } 50 inline int buffer<T>::find(const T& t) 51 { 52 for(int i=0;i<fill;i++) 53 if( data[i] == t ) 54 return i; 55 56 return -1; 57 } 48 58 49 59 template<class T> 50 inline int buffer<T>::find(const T& t) 51 { 52 for(int i=0;i<fill;i++) 53 if( data[i] == t ) 54 return i; 60 inline T buffer<T>::remove(int i) 61 { 62 #ifdef SAFETY 63 assert( i>=0 ); 64 assert( i<fill ); 65 #endif 55 66 56 return -1; 57 } 67 fill--; 68 T temp = data[i]; 69 data[i] = data[fill]; 70 71 return temp; 72 } 58 73 59 74 template<class T> 60 inline T buffer<T>::remove(int i) 61 { 62 #ifdef SAFETY 63 assert( i>=0 ); 64 assert( i<fill ); 65 #endif 75 inline int buffer<T>::addAll(const buffer<T>& buf) 76 { 77 for (int i=0; i<buf.fill; i++) 78 add(buf(i)); 66 79 67 fill--; 68 T temp = data[i]; 69 data[i] = data[fill]; 70 71 return temp; 72 } 80 return fill; 81 } 73 82 74 83 template<class T> 75 inline int buffer<T>::addAll(const buffer<T>& buf) 76 { 77 for(int i=0; i<buf.fill; i++) 78 add(buf(i)); 79 80 return fill; 81 } 82 83 template<class T> 84 inline void buffer<T>::removeDuplicates() 85 { 86 for(int i=0; i<fill; i++) 84 inline void buffer<T>::removeDuplicates() 87 85 { 88 for(int j=i+1; j<fill; ) 89 { 90 if( data[j] == data[i] ) 91 remove(j); 92 else 93 j++; 86 for (int i=0; i<fill; i++) 87 { 88 for (int j=i+1; j<fill; ) 89 { 90 if ( data[j] == data[i] ) 91 remove(j); 92 else 93 j++; 94 } 95 } 94 96 } 95 }96 }97 97 } 98 98 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/gfx/tools/Heap.h
r1600 r2291 33 33 { 34 34 public: 35 35 36 float import; 36 37 Heapable *obj;
Note: See TracChangeset
for help on using the changeset viewer.