00001 // -*- C++ -*- 00002 00008 #if !defined(__ads_TrivialOutputIterator_h__) 00009 #define __ads_TrivialOutputIterator_h__ 00010 00011 #include "../defs.h" 00012 00013 #include <iterator> 00014 00015 BEGIN_NAMESPACE_ADS 00016 00018 00023 class TrivialOutputIterator : 00024 public std::iterator<std::output_iterator_tag,void,void,void,void> { 00025 private: 00026 00027 // 00028 // Private types. 00029 // 00030 00031 typedef std::iterator<std::output_iterator_tag,void,void,void,void> 00032 Base; 00033 00034 public: 00035 00036 // 00037 // Public types. 00038 // 00039 00040 // The following five types are required to be defined for any iterator. 00041 00043 typedef Base::iterator_category iterator_category; 00045 typedef Base::value_type value_type; 00047 typedef Base::difference_type difference_type; 00049 typedef Base::pointer pointer; 00051 typedef Base::reference reference; 00052 00053 //-------------------------------------------------------------------------- 00055 00056 00058 TrivialOutputIterator() 00059 {} 00060 00062 TrivialOutputIterator(const TrivialOutputIterator&) 00063 {} 00064 00066 TrivialOutputIterator& 00067 operator=(const TrivialOutputIterator&) { 00068 return *this; 00069 } 00070 00072 //-------------------------------------------------------------------------- 00074 00075 00077 template<typename Value> 00078 TrivialOutputIterator& 00079 operator=(const Value&) { 00080 return *this; 00081 } 00082 00084 TrivialOutputIterator& 00085 operator*() { 00086 return *this; 00087 } 00088 00090 TrivialOutputIterator& 00091 operator++() { 00092 return *this; 00093 } 00094 00096 TrivialOutputIterator 00097 operator++(int) { 00098 return *this; 00099 } 00100 00102 00103 }; 00104 00105 00107 inline 00108 TrivialOutputIterator 00109 constructTrivialOutputIterator() { 00110 TrivialOutputIterator x; 00111 return x; 00112 } 00113 00114 00116 00121 class TrivialOutputIteratorCount : 00122 public TrivialOutputIterator { 00123 // 00124 // Private types. 00125 // 00126 private: 00127 00128 typedef TrivialOutputIterator Base; 00129 00130 // 00131 // Public types. 00132 // 00133 public: 00134 00135 // The following five types are required to be defined for any iterator. 00136 00138 typedef Base::iterator_category iterator_category; 00140 typedef Base::value_type value_type; 00142 typedef Base::difference_type difference_type; 00144 typedef Base::pointer pointer; 00146 typedef Base::reference reference; 00147 00148 // 00149 // Member data. 00150 // 00151 private: 00152 00153 int& _count; 00154 00155 // 00156 // Not implemented. 00157 // 00158 private: 00159 00160 // Default constructor not implemented. 00161 TrivialOutputIteratorCount(); 00162 // Assignment operator not implemented. 00163 TrivialOutputIteratorCount& 00164 operator=(const TrivialOutputIteratorCount&); 00165 00166 //-------------------------------------------------------------------------- 00168 00169 public: 00170 00172 TrivialOutputIteratorCount(int& count) : 00173 _count(count) { 00174 } 00175 00177 TrivialOutputIteratorCount(const TrivialOutputIteratorCount& other) : 00178 _count(other._count) { 00179 } 00180 00182 //-------------------------------------------------------------------------- 00184 00185 public: 00186 00188 template<typename Value> 00189 TrivialOutputIteratorCount& 00190 operator=(const Value&) { 00191 ++_count; 00192 return *this; 00193 } 00194 00196 int 00197 get() const { 00198 return _count; 00199 } 00200 00202 void 00203 reset() { 00204 _count = 0; 00205 } 00206 00208 TrivialOutputIteratorCount& 00209 operator*() { 00210 return *this; 00211 } 00212 00214 TrivialOutputIteratorCount& 00215 operator++() { 00216 return *this; 00217 } 00218 00220 00224 TrivialOutputIteratorCount& 00225 operator++(int) { 00226 return *this; 00227 } 00228 00230 00231 }; 00232 00233 00235 inline 00236 TrivialOutputIteratorCount 00237 constructTrivialOutputIteratorCount(int& count) { 00238 TrivialOutputIteratorCount x(count); 00239 return x; 00240 } 00241 00242 00243 END_NAMESPACE_ADS 00244 00245 #endif