00001 //---------------------------------------------------------------------------- 00002 /** @file SgPointIterator.h 00003 Class SgPointIterator. 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #ifndef SG_POINTITERATOR_H 00008 #define SG_POINTITERATOR_H 00009 00010 #include "SgPoint.h" 00011 00012 //---------------------------------------------------------------------------- 00013 00014 /** Iterate through an array of points 00015 terminated by END_POINT (defined to be zero for performance). 00016 */ 00017 class SgPointIterator 00018 { 00019 public: 00020 SgPointIterator(const SgPoint* first); 00021 00022 virtual ~SgPointIterator(); 00023 00024 /** Advance the state of the iteration to the next element. */ 00025 void operator++(); 00026 00027 /** Return the value of the current element. */ 00028 SgPoint operator*() const; 00029 00030 /** Return true if iteration is valid, otherwise false. */ 00031 operator bool() const; 00032 00033 private: 00034 const SgPoint* m_point; 00035 00036 /** Not implemented. */ 00037 SgPointIterator(const SgPointIterator&); 00038 00039 /** Not implemented. */ 00040 SgPointIterator& operator=(const SgPointIterator&); 00041 }; 00042 00043 inline SgPointIterator::SgPointIterator(const SgPoint* first) 00044 : m_point(first) 00045 { 00046 } 00047 00048 inline SgPointIterator::~SgPointIterator() 00049 { 00050 } 00051 00052 inline void SgPointIterator::operator++() 00053 { 00054 ++m_point; 00055 } 00056 00057 inline SgPoint SgPointIterator::operator*() const 00058 { 00059 return *m_point; 00060 } 00061 00062 inline SgPointIterator::operator bool() const 00063 { 00064 return *m_point != SG_ENDPOINT; 00065 } 00066 00067 //---------------------------------------------------------------------------- 00068 00069 /** Iterate through an array of points with the range defined by pointers. */ 00070 class SgPointRangeIterator 00071 { 00072 public: 00073 /** Constructor. 00074 @param first Pointer to first element. 00075 @param end Pointer to last element + 1. 00076 */ 00077 SgPointRangeIterator(const SgPoint* first, const SgPoint* end); 00078 00079 virtual ~SgPointRangeIterator(); 00080 00081 /** Advance the state of the iteration to the next element. */ 00082 void operator++(); 00083 00084 /** Return the value of the current element. */ 00085 SgPoint operator*() const; 00086 00087 /** Return true if iteration is valid, otherwise false. */ 00088 operator bool() const; 00089 00090 private: 00091 const SgPoint* m_point; 00092 00093 const SgPoint* m_end; 00094 00095 /** Not implemented. */ 00096 SgPointRangeIterator(const SgPointRangeIterator&); 00097 00098 /** Not implemented. */ 00099 SgPointRangeIterator& operator=(const SgPointRangeIterator&); 00100 }; 00101 00102 inline SgPointRangeIterator::SgPointRangeIterator(const SgPoint* first, 00103 const SgPoint* end) 00104 : m_point(first), 00105 m_end(end) 00106 { 00107 } 00108 00109 inline SgPointRangeIterator::~SgPointRangeIterator() 00110 { 00111 } 00112 00113 inline void SgPointRangeIterator::operator++() 00114 { 00115 ++m_point; 00116 } 00117 00118 inline SgPoint SgPointRangeIterator::operator*() const 00119 { 00120 return *m_point; 00121 } 00122 00123 inline SgPointRangeIterator::operator bool() const 00124 { 00125 return m_point != m_end; 00126 } 00127 00128 //---------------------------------------------------------------------------- 00129 00130 #endif // SG_POINTITERATOR_H