Changeset 2105 for trunk/source/container_classes.h
- Timestamp:
- 06/10/08 15:01:26 (5 months ago)
- Files:
-
- 1 modified
-
trunk/source/container_classes.h (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/container_classes.h
r1945 r2105 32 32 //! basic_pntr - base class for generalization of normal pointers that enables bounds checking 33 33 //! it comes with the full set of operators that you would expect for a random access pointer 34 template<class T, int d, mem_layout ALLOC,bool lgBC>34 template<class T, bool lgBC> 35 35 class basic_pntr 36 36 { … … 126 126 127 127 //! pntr - interface class to replace normal pointers 128 template<class T, int d, mem_layout ALLOC,bool lgBC>129 class pntr : public basic_pntr<T, d,ALLOC,lgBC>128 template<class T, bool lgBC> 129 class pntr : public basic_pntr<T,lgBC> 130 130 { 131 131 public: 132 132 // constructors are not inherited, so define them again 133 pntr( T* p0 ) : basic_pntr<T, d,ALLOC,lgBC>( p0 ) {}134 pntr( T* p0, T* p1, T* p2 ) : basic_pntr<T, d,ALLOC,lgBC>( p0, p1, p2 ) {}133 pntr( T* p0 ) : basic_pntr<T,lgBC>( p0 ) {} 134 pntr( T* p0, T* p1, T* p2 ) : basic_pntr<T,lgBC>( p0, p1, p2 ) {} 135 135 pntr() {} 136 136 // the increment / decrement operators need to be recast... 137 137 // otherwise expressions like p = ++q would be illegal for iterators... 138 pntr& operator++ () { return static_cast<pntr&>(basic_pntr<T, d,ALLOC,lgBC>::operator++()); }138 pntr& operator++ () { return static_cast<pntr&>(basic_pntr<T,lgBC>::operator++()); } 139 139 const pntr operator++ (int) { pntr t = *this; ++(*this); return t; } 140 pntr& operator-- () { return static_cast<pntr&>(basic_pntr<T, d,ALLOC,lgBC>::operator--()); }140 pntr& operator-- () { return static_cast<pntr&>(basic_pntr<T,lgBC>::operator--()); } 141 141 const pntr operator-- (int) { pntr t = *this; --(*this); return t; } 142 142 // define p+n, p-n, p-q … … 147 147 148 148 // this defines n+p 149 template<class T, int d, mem_layout ALLOC,bool lgBC>150 inline const pntr<T, d,ALLOC,lgBC> operator+ ( const ptrdiff_t n, const pntr<T,d,ALLOC,lgBC>& t )151 { 152 pntr<T, d,ALLOC,lgBC> s = t;149 template<class T, bool lgBC> 150 inline const pntr<T,lgBC> operator+ ( const ptrdiff_t n, const pntr<T,lgBC>& t ) 151 { 152 pntr<T,lgBC> s = t; 153 153 s += n; 154 154 return s; … … 156 156 157 157 //! const_pntr - same as pntr, except that it replaces const pointers rather than normal pointers 158 template<class T, int d, mem_layout ALLOC,bool lgBC>159 class const_pntr : public basic_pntr<T, d,ALLOC,lgBC>158 template<class T, bool lgBC> 159 class const_pntr : public basic_pntr<T,lgBC> 160 160 { 161 161 public: 162 162 // constructors are not inherited, so define them again 163 const_pntr( T* p0 ) : basic_pntr<T, d,ALLOC,lgBC>( p0 ) {}164 const_pntr( T* p0, T* p1, T* p2 ) : basic_pntr<T, d,ALLOC,lgBC>( p0, p1, p2 ) {}163 const_pntr( T* p0 ) : basic_pntr<T,lgBC>( p0 ) {} 164 const_pntr( T* p0, T* p1, T* p2 ) : basic_pntr<T,lgBC>( p0, p1, p2 ) {} 165 165 const_pntr() {} 166 166 // make sure we can assign a pntr to a const_pntr by creating an implicit conversion to const_pntr 167 const_pntr( const pntr<T, d,ALLOC,lgBC>& t ) : basic_pntr<T,d,ALLOC,lgBC>( t ) {}167 const_pntr( const pntr<T,lgBC>& t ) : basic_pntr<T,lgBC>( t ) {} 168 168 // the increment / decrement operators need to be recast... 169 169 // otherwise expressions like *p++ = 1. would be legal for const_iterators... 170 const_pntr& operator++ () { return static_cast<const_pntr&>(basic_pntr<T, d,ALLOC,lgBC>::operator++()); }170 const_pntr& operator++ () { return static_cast<const_pntr&>(basic_pntr<T,lgBC>::operator++()); } 171 171 const const_pntr operator++ (int) { const_pntr t = *this; ++(*this); return t; } 172 const_pntr& operator-- () { return static_cast<const_pntr&>(basic_pntr<T, d,ALLOC,lgBC>::operator--()); }172 const_pntr& operator-- () { return static_cast<const_pntr&>(basic_pntr<T,lgBC>::operator--()); } 173 173 const const_pntr operator-- (int) { const_pntr t = *this; --(*this); return t; } 174 174 const_pntr& operator+= ( const ptrdiff_t n ) 175 175 { 176 return static_cast<const_pntr&>(basic_pntr<T, d,ALLOC,lgBC>::operator+=(n));176 return static_cast<const_pntr&>(basic_pntr<T,lgBC>::operator+=(n)); 177 177 } 178 178 const_pntr& operator-= ( const ptrdiff_t n ) 179 179 { 180 return static_cast<const_pntr&>(basic_pntr<T, d,ALLOC,lgBC>::operator-=(n));180 return static_cast<const_pntr&>(basic_pntr<T,lgBC>::operator-=(n)); 181 181 } 182 182 // the dereference operators need to be recast... 183 const T& operator* () const { return static_cast<const T&>(basic_pntr<T, d,ALLOC,lgBC>::operator*()); }184 const T* operator-> () const { return static_cast<const T*>(basic_pntr<T, d,ALLOC,lgBC>::operator->()); }183 const T& operator* () const { return static_cast<const T&>(basic_pntr<T,lgBC>::operator*()); } 184 const T* operator-> () const { return static_cast<const T*>(basic_pntr<T,lgBC>::operator->()); } 185 185 const T& operator[] ( const ptrdiff_t n ) const 186 186 { 187 return static_cast<const T&>(basic_pntr<T, d,ALLOC,lgBC>::operator[](n));187 return static_cast<const T&>(basic_pntr<T,lgBC>::operator[](n)); 188 188 } 189 189 // define p+n, p-n, p-q … … 194 194 195 195 // this defines n+p 196 template<class T, int d, mem_layout ALLOC,bool lgBC>197 inline const const_pntr<T, d,ALLOC,lgBC> operator+ ( const ptrdiff_t n, const const_pntr<T,d,ALLOC,lgBC>& t )198 { 199 const_pntr<T, d,ALLOC,lgBC> s = t;196 template<class T, bool lgBC> 197 inline const const_pntr<T,lgBC> operator+ ( const ptrdiff_t n, const const_pntr<T,lgBC>& t ) 198 { 199 const_pntr<T,lgBC> s = t; 200 200 s += n; 201 201 return s; … … 921 921 typedef size_t size_type; 922 922 typedef ptrdiff_t difference_type; 923 typedef pntr<T, d,ALLOC,lgBC> iterator;924 typedef const_pntr<T, d,ALLOC,lgBC> const_iterator;923 typedef pntr<T,lgBC> iterator; 924 typedef const_pntr<T,lgBC> const_iterator; 925 925 926 926 private: … … 1719 1719 1720 1720 // on Mac systems these instantiations need to be extern in order to avoid duplicate symbols 1721 #define INSTANTIATE_MULTI_ARR( TYPE, LAYOUT, BC ) \ 1722 INST_EXTERN template class pntr<TYPE,2,LAYOUT,BC>; \ 1723 INST_EXTERN template class pntr<TYPE,3,LAYOUT,BC>; \ 1724 INST_EXTERN template class pntr<TYPE,4,LAYOUT,BC>; \ 1725 INST_EXTERN template class pntr<TYPE,5,LAYOUT,BC>; \ 1726 INST_EXTERN template class pntr<TYPE,6,LAYOUT,BC>; \ 1727 INST_EXTERN template class const_pntr<TYPE,2,LAYOUT,BC>; \ 1728 INST_EXTERN template class const_pntr<TYPE,3,LAYOUT,BC>; \ 1729 INST_EXTERN template class const_pntr<TYPE,4,LAYOUT,BC>; \ 1730 INST_EXTERN template class const_pntr<TYPE,5,LAYOUT,BC>; \ 1731 INST_EXTERN template class const_pntr<TYPE,6,LAYOUT,BC> 1732 1733 INSTANTIATE_MULTI_ARR( bool, MEM_LAYOUT_VAL, lgBOUNDSCHECKVAL ); 1734 INSTANTIATE_MULTI_ARR( long, MEM_LAYOUT_VAL, lgBOUNDSCHECKVAL ); 1735 INSTANTIATE_MULTI_ARR( realnum, MEM_LAYOUT_VAL, lgBOUNDSCHECKVAL ); 1736 INSTANTIATE_MULTI_ARR( double, MEM_LAYOUT_VAL, lgBOUNDSCHECKVAL ); 1737 INSTANTIATE_MULTI_ARR( double, C_TYPE, lgBOUNDSCHECKVAL ); 1721 #define INSTANTIATE_MULTI_ARR( TYPE, BC ) \ 1722 INST_EXTERN template class pntr<TYPE,BC>; \ 1723 INST_EXTERN template class const_pntr<TYPE,BC>; 1724 1725 INSTANTIATE_MULTI_ARR( bool, lgBOUNDSCHECKVAL ); 1726 INSTANTIATE_MULTI_ARR( long, lgBOUNDSCHECKVAL ); 1727 INSTANTIATE_MULTI_ARR( realnum,lgBOUNDSCHECKVAL ); 1728 INSTANTIATE_MULTI_ARR( double, lgBOUNDSCHECKVAL ); 1738 1729 1739 1730 … … 1758 1749 typedef long size_type; 1759 1750 typedef ptrdiff_t difference_type; 1760 typedef pntr<T, 1,FLX_TYPE,lgBC> iterator;1761 typedef const_pntr<T, 1,FLX_TYPE,lgBC> const_iterator;1751 typedef pntr<T,lgBC> iterator; 1752 typedef const_pntr<T,lgBC> const_iterator; 1762 1753 1763 1754 private:
