libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd/cvd image.h [subimage2]


From: Edward Rosten
Subject: [libcvd-members] libcvd/cvd image.h [subimage2]
Date: Thu, 29 Jun 2006 17:26:37 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Branch:         subimage2
Changes by:     Edward Rosten <edrosten>        06/06/29 17:26:37

Modified files:
        cvd            : image.h 

Log message:
        Better implementation of const_iterator, so const_iterator is a base 
class
        of iterator (allows iterators to turn in to const_iterators, but 
requires a
        const_cast). Can anyone suggest a better method?

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/image.h?cvsroot=libcvd&only_with_tag=subimage2&r1=1.20.2.3&r2=1.20.2.4

Patches:
Index: image.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/image.h,v
retrieving revision 1.20.2.3
retrieving revision 1.20.2.4
diff -u -b -r1.20.2.3 -r1.20.2.4
--- image.h     29 Jun 2006 00:34:34 -0000      1.20.2.3
+++ image.h     29 Jun 2006 17:26:37 -0000      1.20.2.4
@@ -209,11 +209,11 @@
 
 template<class T> class SubImageIteratorEnd;
 template<class T> class SubImage;
-
 template<class T> class ConstSubImageIteratorEnd;
 template<class T> class ConstSubImage;
 
-template<class T> class SubImageIterator
+
+template<class T> class ConstSubImageIterator
 {
        public:
                void operator++()
@@ -234,46 +234,57 @@
                        operator++();
                }
        
-               T* operator->() { return ptr; }
                const T* operator->() const { return ptr; }
-
-               T& operator*(){ return *ptr;}
                const T& operator*() const { return *ptr;}
 
-               bool operator<(const SubImageIterator& s) const { return ptr < 
s.ptr; }
-               bool operator==(const SubImageIterator& s) const { return ptr 
== s.ptr; }
-               bool operator!=(const SubImageIterator& s) const { return ptr 
!= s.ptr; }
-
+               bool operator<(const ConstSubImageIterator& s) const { return 
ptr < s.ptr; }
+               bool operator==(const ConstSubImageIterator& s) const { return 
ptr == s.ptr; }
+               bool operator!=(const ConstSubImageIterator& s) const { return 
ptr != s.ptr; }
 
-               bool operator!=(const SubImageIteratorEnd<T>& s) const
-               {
-                       return end != NULL;
-               }
 
-               bool operator<(const SubImageIteratorEnd<T>& s) const
-               {
+               bool operator!=(const ConstSubImageIteratorEnd<T>&) const { 
return end != NULL; }
+               bool operator!=(const SubImageIteratorEnd<T>&) const { return 
end != NULL; }
                        //It's illegal to iterate _past_ end(), so < is 
equivalent to !=
-                       return end != NULL;
-               }
+               bool operator<(const ConstSubImageIteratorEnd<T>&) const { 
return end != NULL; }
+               bool operator<(const SubImageIteratorEnd<T>&) const { return 
end != NULL; }
+
 
-               SubImageIterator()
+
+               ConstSubImageIterator()
                {}
 
-               SubImageIterator(T* start, int image_width, int row_stride, T* 
off_end)
-               :ptr(start),
+               ConstSubImageIterator(const T* start, int image_width, int 
row_stride, const T* off_end)
+               :ptr(const_cast<T*>(start)),
                 row_end(start + image_width), 
                 end(off_end), 
                 row_increment(row_stride-image_width), 
                 total_width(row_stride)
                { }
 
-               SubImageIterator(T* end) :ptr(end){ }
+               ConstSubImageIterator(const T* end) 
+               :ptr(const_cast<T*>(end))
+               { }
 
-       private:
-               T* ptr, *row_end, *end;
+       protected:
+               T* ptr;
+               const T *row_end, *end;
                int row_increment, total_width;
 };
 
+template<class T> class SubImageIterator: public ConstSubImageIterator<T>
+{
+       public:
+               SubImageIterator(T* start, int image_width, int row_stride, 
const T* off_end)
+               :ConstSubImageIterator<T>(start, image_width, row_stride, 
off_end)
+               {}
+               
+               SubImageIterator(T* end) 
+               :ConstSubImageIteratorEnd<T>::ptr(end)
+               { }
+
+               T* operator->() { return ConstSubImageIteratorEnd<T>::ptr; }
+               T& operator*() { return *ConstSubImageIteratorEnd<T>::ptr;}
+};
 
 template<class T> class SubImageIteratorEnd
 {
@@ -290,69 +301,11 @@
                SubImage<T>* i;
 };
 
-template<class T> class ConstSubImageIterator
-{
-       public:
-               void operator++()
-               {
-                       ptr++;
-                       if(ptr == row_end)
-                       {
-                               ptr += row_increment;
-                               row_end += total_width;
-
-                               if(ptr >= end)
-                                       end = NULL;
-                       }
-               }
-
-               void operator++(int)
-               {
-                       operator++();
-               }
-       
-               const T* operator->() const { return ptr; }
-               const T& operator*() const { return *ptr;}
-
-               bool operator<(const ConstSubImageIterator& s) const { return 
ptr < s.ptr; }
-               bool operator==(const ConstSubImageIterator& s) const { return 
ptr == s.ptr; }
-               bool operator!=(const ConstSubImageIterator& s) const { return 
ptr != s.ptr; }
-
-
-               bool operator!=(const ConstSubImageIteratorEnd<T>& s) const
-               {
-                       return end != NULL;
-               }
-
-               bool operator<(const ConstSubImageIteratorEnd<T>& s) const
-               {
-                       //It's illegal to iterate _past_ end(), so < is 
equivalent to !=
-                       return end != NULL;
-               }
-
-               ConstSubImageIterator()
-               {}
-
-               ConstSubImageIterator(const T* start, int image_width, int 
row_stride, const T* off_end)
-               :ptr(start),
-                row_end(start + image_width), 
-                end(off_end), 
-                row_increment(row_stride-image_width), 
-                total_width(row_stride)
-               { }
-
-               ConstSubImageIterator(const T* end) :ptr(end){ }
-
-       private:
-               const T* ptr, *row_end, *end;
-               int row_increment, total_width;
-};
-
 
 template<class T> class ConstSubImageIteratorEnd
 {
        public:
-               ConstSubImageIteratorEnd(SubImage<T>* p)
+               ConstSubImageIteratorEnd(const SubImage<T>* p)
                :i(p){}
 
                operator ConstSubImageIterator<T>()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]