Changeset 1598 for trunk/source/cddefines.h
- Timestamp:
- 12/01/07 10:29:50 (12 months ago)
- Files:
-
- 1 modified
-
trunk/source/cddefines.h (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/cddefines.h
r1596 r1598 837 837 static const int _nd = lgBC ? 3 : 1; 838 838 T* p[_nd]; // p[0] current pointer, p[1] lower bound, p[2] upper bound 839 void bounds_check(const T* t) const840 { 841 #ifdef _MSC_VER 842 /* disable warning that conditional expression is constant, true or false in if */ 843 # pragma warning( disable : 4127 )844 #endif 845 if (lgBC)839 void _bounds_check( const T* t ) const 840 { 841 #ifdef _MSC_VER 842 /* disable warning that conditional expression is constant, true or false in if */ 843 # pragma warning( disable : 4127 ) 844 #endif 845 if( lgBC ) 846 846 { 847 847 if( t < p[1] || t >= p[2] ) … … 850 850 fprintf( ioQQQ, " ptr = %#lx, valid region: %#lx <= ptr < %#lx\n", 851 851 #ifdef _MSC_VER 852 (size_t)t, (size_t)p[1], (size_t)p[2] );852 (size_t)t, (size_t)p[1], (size_t)p[2] ); 853 853 #else 854 (unsigned long)t, (unsigned long)p[1], (unsigned long)p[2] ); 855 #endif 856 TotalInsanity(); 857 } 858 } 859 } 860 T* index_checked ( const ptrdiff_t n) const 861 { 862 T* t; 863 t = p[0]+n; 864 bounds_check(t); 865 return t; 866 } 867 void set_vals(T* p0, T* p1, T* p2) 868 { 869 #ifdef _MSC_VER 870 /* disable warning that conditional expression is constant, true or false in if */ 871 # pragma warning( disable : 4127 ) 854 (unsigned long)t, (unsigned long)p[1], (unsigned long)p[2] ); 855 #endif 856 TotalInsanity(); 857 } 858 } 859 } 860 T* _index_checked ( const ptrdiff_t n ) const 861 { 862 T* t = p[0]+n; 863 _bounds_check(t); 864 return t; 865 } 866 void _set_vals( T* p0, T* p1, T* p2 ) 867 { 868 #ifdef _MSC_VER 869 /* disable warning that conditional expression is constant, true or false in if */ 870 # pragma warning( disable : 4127 ) 872 871 #endif 873 872 if( lgBC ) … … 882 881 basic_pntr( T* p0, T* p1, T* p2 ) 883 882 { 884 set_vals(p0,p1,p2);883 _set_vals( p0, p1, p2 ); 885 884 } 886 885 basic_pntr( T* p0 ) 887 886 { 888 set_vals(p0,NULL,NULL);887 _set_vals( p0, NULL, NULL ); 889 888 } 890 889 public: 891 890 basic_pntr() 892 891 { 893 set_vals(NULL,NULL,NULL);892 _set_vals( NULL, NULL, NULL ); 894 893 } 895 894 basic_pntr( const basic_pntr& t ) … … 897 896 *this = t; 898 897 } 899 // virtual destructor (in case of destruction via basic_pntr*, see Sutter EC++ p77)900 virtual ~basic_pntr() {};898 // virtual destructor (in case of destruction via basic_pntr*, see Sutter EC++ p77) 899 virtual ~basic_pntr() {}; 901 900 // pre-increment 902 basic_pntr& operator++ ()901 basic_pntr& operator++ () 903 902 { 904 903 ++p[0]; 905 904 return *this; 906 905 } 907 // post-increment908 const basic_pntr operator++ (int)909 { 910 basic_pntr t (*this);911 ++ *this;906 // post-increment 907 const basic_pntr operator++ (int) 908 { 909 basic_pntr t( *this ); 910 ++(*this); 912 911 return t; 913 912 } … … 919 918 } 920 919 // post-decrement 921 const basic_pntr operator-- (int)922 { 923 basic_pntr t (*this);924 -- *this;920 const basic_pntr operator-- (int) 921 { 922 basic_pntr t( *this ); 923 --(*this); 925 924 return t; 926 925 } … … 929 928 // conversion from basic_pntr -> pntr or const_pntr to work; this would also create 930 929 // an implicit and silent conversion from const_pntr -> pntr, which is illegal... 931 basic_pntr& operator+= ( const ptrdiff_t n ) { p[0] += n; return *this; }930 basic_pntr& operator+= ( const ptrdiff_t n ) { p[0] += n; return *this; } 932 931 basic_pntr& operator-= ( const ptrdiff_t n ) { p[0] -= n; return *this; } 933 932 // dereference 934 933 T& operator* () const 935 934 { 936 return *( index_checked(0));935 return *(_index_checked(0)); 937 936 } 938 937 T* operator-> () const 939 938 { 940 return index_checked(0);939 return _index_checked(0); 941 940 } 942 941 T& operator[] ( const ptrdiff_t n ) const 943 942 { 944 return *( index_checked(n));943 return *(_index_checked(n)); 945 944 } 946 945 // finally, define the boolean operators... … … 969 968 const pntr operator+ ( const ptrdiff_t n ) const { pntr s = *this; s += n; return s; } 970 969 const pntr operator- ( const ptrdiff_t n ) const { pntr s = *this; s -= n; return s; } 971 /* const */ptrdiff_t operator- ( const pntr& t ) const { return &(*this[0]) - &t[0]; }970 ptrdiff_t operator- ( const pntr& t ) const { return &(*this[0]) - &t[0]; } 972 971 }; 973 972 … … 1020 1019 const const_pntr operator+ ( const ptrdiff_t n ) const { const_pntr s = *this; s += n; return s; } 1021 1020 const const_pntr operator- ( const ptrdiff_t n ) const { const_pntr s = *this; s -= n; return s; } 1022 /* const */ptrdiff_t operator- ( const const_pntr& t ) const { return &(*this[0]) - &t[0]; }1021 ptrdiff_t operator- ( const const_pntr& t ) const { return &(*this[0]) - &t[0]; } 1023 1022 }; 1024 1023
