Go to the documentation of this file.00001 #ifndef FACE_CONTOUR_DETECTOR_PARAMETERITERATOR_H_
00002 #define FACE_CONTOUR_DETECTOR_PARAMETERITERATOR_H_
00003
00004 #include <iostream>
00005 #include <vector>
00006
00007 namespace face_contour_detector {
00008
00011 class ParameterIteratorI {
00012 public:
00013 virtual void Next() = 0;
00014 virtual bool HasNext() = 0;
00015 virtual void Reset() = 0;
00016 virtual void PrintValue() = 0;
00017 };
00018
00019
00021 template<class T>
00022 class ParameterIterator : public ParameterIteratorI {
00023 public:
00029 ParameterIterator(T start, T end, T stepSize, T* target);
00031 ParameterIterator(const ParameterIterator& other);
00034 virtual void Next();
00037 virtual bool HasNext();
00039 virtual void Reset();
00041 virtual void PrintValue();
00042
00043 protected:
00044 T m_start;
00045 T m_end;
00046 T m_stepSize;
00047 T* m_target;
00048 };
00049
00052 template<class T>
00053 class ParallelParameterIterator : public ParameterIteratorI {
00054 public:
00059 ParallelParameterIterator(T start, T end, T stepSize);
00060 ParallelParameterIterator(const ParallelParameterIterator& other);
00062 virtual void Next();
00066 virtual bool HasNext();
00068 virtual void Reset();
00070 virtual void Add(T* target);
00072 virtual void PrintValue();
00073
00074 protected:
00075 T m_start;
00076 T m_end;
00077 T m_stepSize;
00078 std::vector<T*> m_targets;
00079 };
00080
00081
00082
00083 template <class T>
00084 ParameterIterator<T>::ParameterIterator(T start, T end, T stepSize, T* target) : m_start(start), m_end(end), m_stepSize(stepSize), m_target(target) {
00085 assert(start < end);
00086 }
00087 template <class T>
00088 ParameterIterator<T>::ParameterIterator(const ParameterIterator& other) : m_start(other.m_start), m_end(other.m_end), m_stepSize(other.m_stepSize), m_target(other.m_target) {
00089
00090 }
00091 template <class T>
00092 void ParameterIterator<T>::Next() {
00093 assert(m_target != 0 && HasNext());
00094 *m_target += m_stepSize;
00095 }
00096 template <class T>
00097 bool ParameterIterator<T>::HasNext() {
00098 assert(m_target != 0);
00099 return *m_target < m_end;
00100 }
00101 template <class T>
00102 void ParameterIterator<T>::Reset() {
00103 *m_target = m_start;
00104 }
00105 template <class T>
00106 void ParameterIterator<T>::PrintValue() {
00107 std::cout<<*m_target;
00108 }
00109
00110
00111
00112 template <class T>
00113 ParallelParameterIterator<T>::ParallelParameterIterator(T start, T end, T stepSize) : m_start(start), m_end(end), m_stepSize(stepSize) {
00114 assert(start < end);
00115 }
00116 template <class T>
00117 ParallelParameterIterator<T>::ParallelParameterIterator(const ParallelParameterIterator& other) : m_start(other.m_start), m_end(other.m_end), m_stepSize(other.m_stepSize), m_targets(other.m_targets) {
00118
00119 }
00120 template <class T>
00121 void ParallelParameterIterator<T>::Next() {
00122 assert(HasNext());
00123 typename std::vector<T* >::iterator it;
00124 for (it = m_targets.begin(); it != m_targets.end(); it++) {
00125 (*(*it)) += m_stepSize;
00126 }
00127 }
00128 template <class T>
00129 bool ParallelParameterIterator<T>::HasNext() {
00130 typename std::vector<T*>::iterator it;
00131 for (it = m_targets.begin(); it != m_targets.end(); it++) {
00132 if ((*(*it)) >= m_end) {
00133 return false;
00134 }
00135 }
00136 return true;
00137 }
00138 template <class T>
00139 void ParallelParameterIterator<T>::Reset() {
00140 typename std::vector<T*>::iterator it;
00141 for (it = m_targets.begin(); it != m_targets.end(); it++) {
00142 (*(*it)) = m_start;
00143 }
00144 }
00145 template <class T>
00146 void ParallelParameterIterator<T>::PrintValue() {
00147 typename std::vector<T*>::iterator it;
00148 for (it = m_targets.begin(); it != m_targets.end(); it++) {
00149 std::cout<<(*(*it))<<", ";
00150 }
00151 }
00152
00153 template <class T>
00154 void ParallelParameterIterator<T>::Add(T* target) {
00155 m_targets.push_back(target);
00156 }
00157
00158 }
00159
00160 #endif