1 #ifndef DM_ITERATOR_HPP_INCLUDED
2 #define DM_ITERATOR_HPP_INCLUDED
8 #include "DM/config.hpp"
9 #include "DM/Handle.hpp"
10 #include "DM/ObjectBase.hpp"
32 imp() : RefCount(1) {}
35 virtual imp& operator++() = 0;
36 virtual imp& operator--() = 0;
38 virtual reference operator*()
const = 0;
39 virtual pointer operator->()
const = 0;
40 virtual handle operator()()
const = 0;
42 virtual bool operator==(
const imp &ref)
const=0;
43 virtual bool operator!=(
const imp &ref)
const {
return !operator==(ref); };
45 virtual imp* clone()
const=0;
57 typedef const T* const_pointer;
58 typedef const T& const_reference;
63 Iterator(iterator_imp *h) : _Handle(h) {}
64 Iterator(
const self& ref) : _Handle(ref._Handle) {
if (_Handle) (_Handle->RefCount)++; }
66 if (_Handle && _Handle->RefCount == 1)
70 self& operator++() { _Handle->operator++();
return *
this; };
71 self& operator--() { _Handle->operator--();
return *
this; };
73 reference operator*()
const {
return _Handle->operator*(); };
74 pointer operator->()
const {
return _Handle->operator->(); };
75 handle operator()()
const {
return _Handle->operator()(); };
77 self &operator=(
const self &ref) {
self tmp = ref;
swap(tmp);
return *
this; }
79 bool operator==(
const self &ref)
const {
return ( _Handle == ref._Handle || *_Handle == *(ref._Handle) ); };
80 bool operator!=(
const self &ref)
const {
return ( _Handle != ref._Handle && *_Handle != *(ref._Handle) ); };
82 operator bool()
const {
return (_Handle!=0); }
83 void reset() {
swap( this->ConstIterator() ); }
86 std::swap(_Handle, it._Handle);
89 self clone()
const {
return (_Handle) ?
self( (iterator_imp *)_Handle->clone() ) :
self(); }
96 friend struct IteratorAccess;
106 typedef T value_type;
107 typedef const T* const_pointer;
108 typedef const T& const_reference;
111 imp() : RefCount(1) {}
114 virtual imp& operator++() = 0;
115 virtual imp& operator--() = 0;
117 virtual const_reference operator*()
const = 0;
118 virtual const_pointer operator->()
const = 0;
121 virtual bool operator==(
const imp &ref)
const=0;
122 virtual bool operator!=(
const imp &ref)
const {
return !operator==(ref); };
124 virtual imp* clone()
const=0;
134 typedef T& reference;
135 typedef const T* const_pointer;
136 typedef const T& const_reference;
138 typedef T value_type;
142 ConstIterator(
const self& ref) : _Handle(ref._Handle) {
if (_Handle) (_Handle->RefCount)++; }
144 ConstIterator(
const Iterator<T>& ref) : _Handle(convert(ref._Handle)) {
if (_Handle) (_Handle->RefCount)++; }
145 ConstIterator(
typename Iterator<T>::iterator_imp *h) : _Handle(convert(h)) { }
147 virtual ~ConstIterator() {
150 if (--(_Handle->RefCount) == 0)
155 self& operator++() { _Handle->operator++();
return *
this; };
156 self& operator--() { _Handle->operator--();
return *
this; };
158 const_reference operator*()
const {
return _Handle->operator*(); };
159 const_pointer operator->()
const {
return _Handle->operator->(); };
160 const_handle operator()()
const {
return _Handle->operator()(); };
162 self &operator=(
const self &ref) {
self tmp = ref;
swap(tmp);
return *
this; }
164 bool operator==(
const self &ref)
const {
return ( _Handle == ref._Handle || *_Handle == *(ref._Handle) ); };
165 bool operator!=(
const self &ref)
const {
return ( _Handle != ref._Handle && *_Handle != *(ref._Handle) ); };
167 operator bool()
const {
return (_Handle!=0); }
168 void reset() {
swap( ConstIterator() ); }
170 void swap(
self &it) {
171 std::swap(_Handle, it._Handle);
174 self clone()
const {
return (_Handle) ?
self( _Handle->clone( ) ) :
self(); }
183 friend struct IteratorAccess;
192 typedef T& reference;
193 typedef const T* const_pointer;
194 typedef const T& const_reference;
195 typedef T value_type;
203 virtual self& operator=(const_reference value) = 0;
206 virtual self& operator*() {
return *
this; }
207 virtual self& operator++() {
return *
this; }
209 virtual void finished() {}
211 virtual void Delete() {
214 throw NG_exception(
"Overload function in the corresponding child class");
225 typedef typename base::pointer pointer;
226 typedef typename base::reference reference;
227 typedef typename base::const_pointer const_pointer;
228 typedef typename base::const_reference const_reference;
229 typedef typename base::value_type value_type;
237 virtual self& operator=(const_reference value) {
247 #endif //DM_ITERATOR_HPP_INCLUDED