00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef _xmlwrapp_nodes_view_h_
00041 #define _xmlwrapp_nodes_view_h_
00042
00043
00044 #include "xmlwrapp/init.h"
00045
00046
00047 #include <iterator>
00048
00049 namespace xml
00050 {
00051
00052 class node;
00053 class const_nodes_view;
00054
00055 namespace impl
00056 {
00057
00058 struct nipimpl;
00059 class iter_advance_functor;
00060
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 class nodes_view
00078 {
00079 public:
00080 nodes_view() : data_begin_(0), advance_func_(0) {}
00081 nodes_view(const nodes_view& other);
00082 ~nodes_view();
00083
00084 nodes_view& operator=(const nodes_view& other);
00085
00086 class const_iterator;
00087
00088
00089
00090
00091
00092
00093
00094 class iterator
00095 {
00096 public:
00097 typedef node value_type;
00098 typedef int difference_type;
00099 typedef value_type* pointer;
00100 typedef value_type& reference;
00101 typedef std::forward_iterator_tag iterator_category;
00102
00103 iterator() : pimpl_(0), advance_func_(0) {}
00104 iterator(const iterator& other);
00105 iterator& operator=(const iterator& other);
00106 ~iterator();
00107
00108 reference operator*() const;
00109 pointer operator->() const;
00110
00111 iterator& operator++();
00112 iterator operator++(int);
00113
00114 bool operator==(const iterator& other) const
00115 { return get_raw_node() == other.get_raw_node(); }
00116 bool operator!=(const iterator& other) const
00117 { return !(*this == other); }
00118
00119 private:
00120 explicit iterator(void *data, impl::iter_advance_functor *advance_func);
00121 void* get_raw_node() const;
00122 void swap(iterator& other);
00123
00124 impl::nipimpl *pimpl_;
00125
00126
00127
00128 impl::iter_advance_functor *advance_func_;
00129
00130 friend class nodes_view;
00131 friend class const_iterator;
00132 };
00133
00134
00135
00136
00137
00138
00139
00140
00141 class const_iterator
00142 {
00143 public:
00144 typedef const node value_type;
00145 typedef int difference_type;
00146 typedef value_type* pointer;
00147 typedef value_type& reference;
00148 typedef std::forward_iterator_tag iterator_category;
00149
00150 const_iterator() : pimpl_(0), advance_func_(0) {}
00151 const_iterator(const const_iterator& other);
00152 const_iterator(const iterator& other);
00153 const_iterator& operator=(const const_iterator& other);
00154 const_iterator& operator=(const iterator& other);
00155 ~const_iterator();
00156
00157 reference operator*() const;
00158 pointer operator->() const;
00159
00160 const_iterator& operator++();
00161 const_iterator operator++(int);
00162
00163 bool operator==(const const_iterator& other) const
00164 { return get_raw_node() == other.get_raw_node(); }
00165 bool operator!=(const const_iterator& other) const
00166 { return !(*this == other); }
00167
00168 private:
00169 explicit const_iterator(void *data, impl::iter_advance_functor *advance_func);
00170 void* get_raw_node() const;
00171 void swap(const_iterator& other);
00172
00173 impl::nipimpl *pimpl_;
00174
00175
00176
00177 impl::iter_advance_functor *advance_func_;
00178
00179 friend class const_nodes_view;
00180 friend class nodes_view;
00181 };
00182
00183
00184
00185
00186
00187
00188
00189 iterator begin() { return iterator(data_begin_, advance_func_); }
00190
00191
00192
00193
00194
00195
00196
00197 const_iterator begin() const { return const_iterator(data_begin_, advance_func_); }
00198
00199
00200
00201
00202
00203
00204 iterator end() { return iterator(); }
00205
00206
00207
00208
00209
00210
00211 const_iterator end() const { return const_iterator(); }
00212
00213
00214 bool empty() const { return !data_begin_; }
00215
00216 private:
00217 explicit nodes_view(void *data_begin, impl::iter_advance_functor *advance_func)
00218 : data_begin_(data_begin), advance_func_(advance_func) {}
00219
00220
00221 void *data_begin_;
00222
00223 impl::iter_advance_functor *advance_func_;
00224
00225 friend class node;
00226 friend class const_nodes_view;
00227 };
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240 class const_nodes_view
00241 {
00242 public:
00243 const_nodes_view() : data_begin_(0), advance_func_(0) {}
00244 const_nodes_view(const const_nodes_view& other);
00245 const_nodes_view(const nodes_view& other);
00246 ~const_nodes_view();
00247
00248 const_nodes_view& operator=(const const_nodes_view& other);
00249 const_nodes_view& operator=(const nodes_view& other);
00250
00251 typedef nodes_view::const_iterator iterator;
00252 typedef nodes_view::const_iterator const_iterator;
00253
00254
00255
00256
00257
00258
00259
00260 const_iterator begin() const
00261 { return const_iterator(data_begin_, advance_func_); }
00262
00263
00264
00265
00266
00267
00268 const_iterator end() const { return const_iterator(); }
00269
00270
00271 bool empty() const { return !data_begin_; }
00272
00273 private:
00274 explicit const_nodes_view(void *data_begin, impl::iter_advance_functor *advance_func)
00275 : data_begin_(data_begin), advance_func_(advance_func) {}
00276
00277
00278 void *data_begin_;
00279
00280 impl::iter_advance_functor *advance_func_;
00281
00282 friend class node;
00283 };
00284
00285 }
00286
00287 #endif // _xmlwrapp_nodes_view_h_