ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_STORAGE_RANGE_HPP 00002 #define VIENNAGRID_STORAGE_RANGE_HPP 00003 00004 /* ======================================================================= 00005 Copyright (c) 2011-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaGrid - The Vienna Grid Library 00011 ----------------- 00012 00013 License: MIT (X11), see file LICENSE in the base directory 00014 ======================================================================= */ 00015 00016 #include "viennagrid/forwards.hpp" 00017 #include "viennagrid/storage/container.hpp" 00018 00023 namespace viennagrid 00024 { 00025 00026 namespace detail 00027 { 00028 template<typename container_type> 00029 class container_range_wrapper 00030 { 00031 friend class container_range_wrapper<const container_type>; 00032 00033 public: 00034 00035 typedef container_type base_container_type; 00036 00037 typedef typename container_type::size_type size_type; 00038 typedef typename container_type::value_type value_type; 00039 typedef typename viennagrid::result_of::id<value_type>::type id_type; 00040 00041 typedef typename container_type::reference reference; 00042 typedef typename container_type::const_reference const_reference; 00043 00044 typedef typename container_type::pointer pointer; 00045 typedef typename container_type::const_pointer const_pointer; 00046 00047 typedef typename container_type::iterator iterator; 00048 typedef typename container_type::const_iterator const_iterator; 00049 00050 typedef typename container_type::reverse_iterator reverse_iterator; 00051 typedef typename container_type::const_reverse_iterator const_reverse_iterator; 00052 00053 00054 container_range_wrapper(container_type & container) : container_(&container) {} 00055 00056 00057 template<typename WrappedConfigT> 00058 container_range_wrapper( mesh<WrappedConfigT> & mesh_obj ) 00059 { *this = elements<value_type>(mesh_obj); } 00060 00061 template<typename WrappedConfigT> 00062 container_range_wrapper( segmentation<WrappedConfigT> & segmentation_obj ) 00063 { *this = elements<value_type>(segmentation_obj); } 00064 00065 template<typename SegmentationT> 00066 container_range_wrapper( segment_handle<SegmentationT> & segment_obj ) 00067 { *this = elements<value_type>(segment_obj); } 00068 00069 template<typename ElementTagT, typename WrappedConfigT> 00070 container_range_wrapper( element<ElementTagT, WrappedConfigT> & element_obj ) 00071 { *this = elements<value_type>(element_obj); } 00072 00073 iterator begin() { return container_->begin(); } 00074 const_iterator begin() const { return container_->begin(); } 00075 iterator end() { return container_->end(); } 00076 const_iterator end() const { return container_->end(); } 00077 00078 reverse_iterator rbegin() { return container_->rbegin(); } 00079 const_reverse_iterator rbegin() const { return container_->rbegin(); } 00080 reverse_iterator rend() { return container_->rend(); } 00081 const_reverse_iterator rend() const { return container_->rend(); } 00082 00083 00084 00085 reference front() { return container_->front(); } 00086 const_reference front() const { return container_->front(); } 00087 reference back() { return container_->back(); } 00088 const_reference back() const { return container_->back(); } 00089 00090 00091 00092 iterator find( id_type const & id ) 00093 { return viennagrid::detail::find(*container_, id); } 00094 const_iterator find( id_type const & id ) const 00095 { return viennagrid::detail::find(*container_, id); } 00096 00097 iterator find( value_type const & element ) 00098 { return viennagrid::detail::find(*container_, element); } 00099 const_iterator find( value_type const & element ) const 00100 { return viennagrid::detail::find(*container_, element); } 00101 00102 00103 00104 00105 00106 reference operator[] (size_type index) 00107 { iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00108 const_reference operator[] (size_type index) const 00109 { const_iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00110 00111 00112 00113 bool empty() const { return container_->empty(); } 00114 size_type size() const { return container_->size(); } 00115 00116 00117 typedef typename container_type::handle_type handle_type; 00118 typedef typename container_type::const_handle_type const_handle_type; 00119 00120 00121 iterator erase( iterator pos ) { return container_->erase( pos ); } 00122 00123 00124 00125 00126 handle_type handle_at(std::size_t pos) 00127 { return viennagrid::advance(begin(), pos).handle(); } 00128 const_handle_type handle_at(std::size_t pos) const 00129 { return viennagrid::advance(begin(), pos).handle(); } 00130 00131 00132 void erase_handle(handle_type handle) 00133 { container_->erase_handle(handle); } 00134 void insert_unique_handle(handle_type handle) 00135 { container_->insert_unique_handle(handle); } 00136 void insert_handle(handle_type handle) 00137 { container_->insert_handle(handle); } 00138 void set_handle_at(handle_type handle, std::size_t pos) 00139 { container_->set_handle(handle, pos); } 00140 00141 container_type * get_base_container() { return container_; } 00142 const container_type * get_base_container() const { return container_; } 00143 00144 private: 00145 00146 container_type * container_; 00147 }; 00148 00149 template<typename container_type> 00150 class container_range_wrapper<const container_type> 00151 { 00152 public: 00153 00154 typedef const container_type base_container_type; 00155 00156 typedef typename container_type::size_type size_type; 00157 typedef typename container_type::value_type value_type; 00158 typedef typename viennagrid::result_of::id<value_type>::type id_type; 00159 00160 typedef typename container_type::const_reference reference; 00161 typedef typename container_type::const_reference const_reference; 00162 00163 typedef typename container_type::const_pointer pointer; 00164 typedef typename container_type::const_pointer const_pointer; 00165 00166 typedef typename container_type::const_iterator iterator; 00167 typedef typename container_type::const_iterator const_iterator; 00168 00169 typedef typename container_type::const_reverse_iterator reverse_iterator; 00170 typedef typename container_type::const_reverse_iterator const_reverse_iterator; 00171 00172 00173 container_range_wrapper(const container_type & container) : container_(&container) {} 00174 container_range_wrapper(const container_range_wrapper<container_type> & rhs) : container_(rhs.container_) {} 00175 00176 template<typename WrappedConfigT> 00177 container_range_wrapper( mesh<WrappedConfigT> & mesh_obj ) 00178 { *this = elements<value_type>(mesh_obj); } 00179 00180 template<typename WrappedConfigT> 00181 container_range_wrapper( segmentation<WrappedConfigT> & segmentation_obj ) 00182 { *this = elements<value_type>(segmentation_obj); } 00183 00184 template<typename SegmentationT> 00185 container_range_wrapper( segment_handle<SegmentationT> & segment_obj ) 00186 { *this = elements<value_type>(segment_obj); } 00187 00188 template<typename ElementTagT, typename WrappedConfigT> 00189 container_range_wrapper( element<ElementTagT, WrappedConfigT> & element_obj ) 00190 { *this = elements<value_type>(element_obj); } 00191 00192 00193 00194 template<typename WrappedConfigT> 00195 container_range_wrapper( mesh<WrappedConfigT> const & mesh_obj ) 00196 { *this = elements<value_type>(mesh_obj); } 00197 00198 template<typename WrappedConfigT> 00199 container_range_wrapper( segmentation<WrappedConfigT> const & segmentation_obj ) 00200 { *this = elements<value_type>(segmentation_obj); } 00201 00202 template<typename SegmentationT> 00203 container_range_wrapper( segment_handle<SegmentationT> const & segment_obj ) 00204 { *this = elements<value_type>(segment_obj); } 00205 00206 template<typename ElementTagT, typename WrappedConfigT> 00207 container_range_wrapper( element<ElementTagT, WrappedConfigT> const & element_obj ) 00208 { *this = elements<value_type>(element_obj); } 00209 00210 00211 iterator begin() { return container_->begin(); } 00212 const_iterator begin() const { return container_->begin(); } 00213 iterator end() { return container_->end(); } 00214 const_iterator end() const { return container_->end(); } 00215 00216 reverse_iterator rbegin() { return container_->rbegin(); } 00217 const_reverse_iterator rbegin() const { return container_->rbegin(); } 00218 reverse_iterator rend() { return container_->rend(); } 00219 const_reverse_iterator rend() const { return container_->rend(); } 00220 00221 00222 00223 reference front() { return container_->front(); } 00224 const_reference front() const { return container_->front(); } 00225 reference back() { return container_->back(); } 00226 const_reference back() const { return container_->back(); } 00227 00228 00229 00230 const_iterator find( id_type const & id ) const 00231 { return viennagrid::detail::find(*container_, id); } 00232 00233 const_iterator find( value_type const & element ) const 00234 { return viennagrid::detail::find(*container_, element); } 00235 00236 00237 00238 reference operator[] (size_type index) 00239 { iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00240 const_reference operator[] (size_type index) const 00241 { const_iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00242 00243 00244 00245 bool empty() const { return container_->empty(); } 00246 size_type size() const { return container_->size(); } 00247 00248 00249 00250 typedef typename container_type::const_handle_type handle_type; 00251 typedef typename container_type::const_handle_type const_handle_type; 00252 00253 handle_type handle_at(std::size_t pos) 00254 { return viennagrid::advance(begin(), pos).handle(); } 00255 const_handle_type handle_at(std::size_t pos) const 00256 { return viennagrid::advance(begin(), pos).handle(); } 00257 00258 const container_type * get_base_container() const { return container_; } 00259 00260 private: 00261 00262 const container_type * container_; 00263 }; 00264 00265 00266 00267 template<typename iterator_type> 00268 class forward_iterator_range 00269 { 00270 public: 00271 00272 forward_iterator_range(iterator_type first, iterator_type last) : first_(first), last_(last) {} 00273 00274 typedef typename iterator_type::T value_type; 00275 00276 typedef typename iterator_type::Reference reference; 00277 typedef const typename iterator_type::Reference const_reference; 00278 00279 typedef typename iterator_type::Pointer pointer; 00280 typedef const typename iterator_type::Pointer const_pointer; 00281 00282 typedef iterator_type iterator; 00283 typedef const iterator_type const_iterator; 00284 00285 00286 00287 iterator begin() { return first_; } 00288 const_iterator begin() const { return first_; } 00289 iterator end() { return last_; } 00290 const_iterator end() const { return last_; } 00291 00292 00293 reference front() { return *first_; } 00294 const_reference front() const { return *first_; } 00295 reference back() { iterator_type tmp = last_; return *(--tmp); } 00296 const_reference back() const { iterator_type tmp = last_; return *(--tmp); } 00297 00298 bool empty() const { return first_ == last_; } 00299 00300 private: 00301 iterator_type first_; 00302 iterator_type last_; 00303 }; 00304 00305 } 00306 00307 } 00308 00309 #endif 00310