contrib/tbl/vipl/section/vipl_section_iterator.txx
Go to the documentation of this file.
00001 // This is tbl/vipl/section/vipl_section_iterator.txx
00002 #ifndef vipl_section_iterator_txx_
00003 #define vipl_section_iterator_txx_
00004 //:
00005 //  \file
00006 
00007 #include "vipl_section_iterator.h"
00008 #include <vipl/section/vipl_section_container.h>
00009 #include <vipl/section/vipl_section_descriptor.h>
00010 #include <vipl/filter/vipl_filter_abs.h> // for default def of FILTER_IMPTR_INC_REFCOUNT
00011 #if 0
00012 #include <vcl_iostream.h> // for error message stuff
00013 #endif
00014 
00015 #ifdef VCL_VC
00016 // Disable complaints about empty controlled statements (from blank macro expansion)
00017 # pragma warning( push )
00018 # pragma warning( disable : 4390 )
00019 #endif
00020 
00021 // Assigns the pointer directly. Does not deep copy them.
00022 template < class DataType >
00023   vipl_section_iterator< DataType > ::vipl_section_iterator(
00024                    vipl_section_descriptor< DataType >* desc ,
00025                  vipl_section_container< DataType >* containr)
00026   : hsreal_descriptor(desc),
00027     hscontainer(containr),
00028     hsincr_count(0)
00029 {
00030   if (desc) { FILTER_IMPTR_INC_REFCOUNT(desc); }
00031   if (containr) { FILTER_IMPTR_INC_REFCOUNT(containr); }
00032 #if 0
00033   vcl_cerr << "Warning: called unimplemented constructor with signature "
00034            << "vipl_section_descriptor< DataType >* desc, vipl_section_container< DataType >* containr\n";
00035 #endif
00036 }
00037 
00038 #ifdef VCL_VC
00039 // Disable complaints about empty controlled statements (from blank macro expansion)
00040 # pragma warning( pop )
00041 # pragma warning( disable : 4390 )
00042 #endif
00043 
00044 
00045 // Deep copies the pointers.
00046 template < class DataType >
00047 vipl_section_iterator< DataType > ::vipl_section_iterator(
00048                  vipl_section_descriptor< DataType >* desc ,
00049                  vipl_section_container< DataType >* containr ,
00050                 int t)
00051   : hsreal_descriptor(0),
00052     hscontainer(0),
00053     hsincr_count(0)
00054 {
00055   hsreal_descriptor = desc->virtual_copy();
00056   hscontainer = containr->virtual_copy();
00057 }
00058 
00059 template < class DataType >
00060   vipl_section_iterator< DataType > ::~vipl_section_iterator()
00061 {
00062   if (ref_container()) FILTER_IMPTR_DEC_REFCOUNT(ref_container());
00063   if (ref_real_descriptor()) FILTER_IMPTR_DEC_REFCOUNT(ref_real_descriptor());
00064 #if 0
00065   vcl_cerr << "Warning: called unimplemented vipl_section_iterator destructor\n";
00066 #endif
00067 }
00068 
00069 template < class DataType >
00070   vipl_section_iterator< DataType > ::vipl_section_iterator()
00071   : hsreal_descriptor(0),
00072     hscontainer(0),
00073     hsincr_count(0)
00074 // C++ auto-generated low-level constructor
00075 {
00076 }
00077 
00078 template < class DataType >
00079   vipl_section_iterator< DataType > ::vipl_section_iterator(const vipl_section_iterator< DataType > &t)
00080   : hsreal_descriptor(0),
00081     hscontainer(0),
00082     hsincr_count(t.hsincr_count)
00083 // C++ auto-generated low-level copy constructor
00084 {
00085   // you can fill special ``copy constructor'' stuff here.
00086   // All dynamic/soft attributes are copied. Thus your
00087   //want to change it here is should be hard because it
00088   //is always changed! So don't change things without
00089   //knowing their form.
00090   if (t.hsreal_descriptor)
00091     hsreal_descriptor = t.hsreal_descriptor->virtual_copy();
00092   if (t.hscontainer)
00093     hscontainer = t.hscontainer->virtual_copy();
00094 }
00095 
00096 template < class DataType >
00097    vipl_section_iterator< DataType >& vipl_section_iterator< DataType > ::operator++()
00098 {
00099   // for the time being, since section-size is the same as the image-size
00100   if (ref_container()->next_section(*ref_real_descriptor()))
00101     ++ref_incr_count();
00102   else {
00103     // delete the real_descriptor and set that slot to zero so that it will
00104     // equal the end iterator
00105     FILTER_IMPTR_DEC_REFCOUNT(ref_real_descriptor());
00106   }
00107   return *this;
00108 }
00109 
00110 // postfix
00111 template < class DataType >
00112 vipl_section_iterator< DataType > vipl_section_iterator< DataType > ::operator++(int )
00113 {
00114   vipl_section_iterator<DataType> rtn(*this);
00115   ++(*this);
00116   return rtn;
00117 }
00118 
00119 // Get the descriptor for the current section
00120 template < class DataType >
00121    vipl_section_descriptor< DataType > vipl_section_iterator< DataType > ::operator*()
00122 {
00123   return *real_descriptor();
00124 }
00125 
00126 //:
00127 // The equality test is true if this and p have the same address, or
00128 // if this and p both have null descriptors. If this XOR p have null descriptor
00129 // it is false. Finally, if this and p have linked containers which are equal,
00130 // AND the iterator's ++ counts are the same, it is true, otherwise false.
00131 template < class DataType >
00132   bool vipl_section_iterator< DataType > ::operator==( const vipl_section_iterator< DataType >& p) const
00133 {
00134   if (this == &p) return true;
00135   // the following is equivalent to testing for NULL, as that is the only time
00136   // that the descriptor pointers will have the same value.
00137   if (real_descriptor() == p.real_descriptor()) return true;
00138   else if ((! real_descriptor()) ^ (! p.real_descriptor()))
00139     return false;
00140   if (*p.container() == *container() &&
00141       p.incr_count() == incr_count()) return true;
00142   return false;
00143 }
00144 
00145 template < class DataType >
00146   bool vipl_section_iterator< DataType > ::operator!=( const vipl_section_iterator< DataType >& p) const
00147 {
00148   return !(*this == p);
00149 }
00150 
00151 template < class DataType >
00152    vipl_section_iterator< DataType >& vipl_section_iterator< DataType > ::operator=(
00153                    const
00154   vipl_section_iterator< DataType >& p)
00155 {
00156   if (&p != this) {
00157     if (hscontainer) FILTER_IMPTR_DEC_REFCOUNT(hscontainer);
00158     if (hsreal_descriptor) FILTER_IMPTR_DEC_REFCOUNT(hsreal_descriptor);
00159     if (p.hsreal_descriptor) // end itr has 0 as real_descriptor
00160       hsreal_descriptor = p.hsreal_descriptor->virtual_copy();
00161     hscontainer = p.hscontainer->virtual_copy();
00162   }
00163   return *this;
00164 }
00165 
00166 #endif // vipl_section_iterator_txx_