ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_STORAGE_VIEW_HPP 00002 #define VIENNAGRID_STORAGE_VIEW_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 <iterator> 00017 #include <algorithm> 00018 00019 #include "viennagrid/forwards.hpp" 00020 #include "viennagrid/meta/typemap.hpp" 00021 00022 #include "viennagrid/storage/container.hpp" 00023 #include "viennagrid/storage/container_collection.hpp" 00024 #include "viennagrid/storage/handle.hpp" 00025 #include "viennagrid/storage/id.hpp" 00026 00027 00032 namespace viennagrid 00033 { 00039 template<typename base_container_type_, typename container_tag> 00040 class view 00041 { 00042 public: 00043 00044 template<typename A, typename B> 00045 friend class view; 00046 00047 typedef base_container_type_ base_container_type; 00048 00049 typedef typename base_container_type::handle_tag handle_tag; 00050 typedef typename detail::result_of::handle_type<base_container_type, handle_tag>::type handle_type; 00051 typedef typename detail::result_of::const_handle_type<base_container_type, handle_tag>::type const_handle_type; 00052 00053 00054 private: 00055 typedef typename viennagrid::result_of::container<handle_type, container_tag>::type handle_container_type; 00056 00057 00058 public: 00059 typedef typename handle_container_type::size_type size_type; 00060 typedef typename base_container_type::value_type value_type; 00061 typedef value_type & reference; 00062 typedef const value_type & const_reference; 00063 typedef value_type * pointer; 00064 typedef const value_type * const_pointer; 00065 00066 00067 00068 class iterator : public handle_container_type::iterator 00069 { 00070 typedef typename handle_container_type::iterator base; 00071 public: 00072 iterator(view & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00073 iterator(const iterator & it) : base(it), view_(it.view_) {} 00074 00075 typedef typename std::iterator_traits<base>::difference_type difference_type; 00076 typedef typename view::value_type value_type; 00077 typedef typename view::reference reference; 00078 typedef typename view::const_reference const_reference; 00079 typedef typename view::pointer pointer; 00080 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00081 00082 handle_type & handle() { return base::operator*(); } 00083 const_handle_type handle() const { return base::operator*(); } 00084 00085 reference operator* () { return view_->dereference_handle( handle() ); } 00086 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00087 00088 pointer operator->() { return &(operator* ()); } 00089 pointer operator->() const { return &(operator* ()); } 00090 00091 iterator & operator++() { base::operator++(); return *this; } 00092 iterator operator++(int) { base::operator++(int()); return *this; } 00093 00094 iterator & operator--() { base::operator--(); return *this; } 00095 iterator operator--(int) { base::operator--(int()); return *this; } 00096 00097 private: 00098 view * view_; 00099 }; 00100 00101 00102 class const_iterator : public handle_container_type::const_iterator 00103 { 00104 typedef typename handle_container_type::const_iterator base; 00105 public: 00106 const_iterator(view const & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00107 const_iterator(const const_iterator & it) : base(it), view_(it.view_) {} 00108 const_iterator(const iterator & it) : base(it), view_(it.view_) {} 00109 00110 typedef typename std::iterator_traits<base>::difference_type difference_type; 00111 typedef typename view::value_type value_type; 00112 typedef typename view::const_reference reference; 00113 typedef typename view::const_reference const_reference; 00114 typedef typename view::const_pointer pointer; 00115 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00116 00117 const_handle_type handle() { return base::operator*(); } 00118 const_handle_type handle() const { return base::operator*(); } 00119 00120 reference operator* () { return view_->dereference_handle( handle() ); } 00121 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00122 00123 pointer operator->() const { return &(operator* ()); } 00124 00125 const_iterator & operator++() { base::operator++(); return *this; } 00126 const_iterator operator++(int) { base::operator++(int()); return *this; } 00127 00128 const_iterator & operator--() { base::operator--(); return *this; } 00129 const_iterator operator--(int) { base::operator--(int()); return *this; } 00130 00131 private: 00132 view const * view_; 00133 }; 00134 00135 class reverse_iterator : public handle_container_type::reverse_iterator 00136 { 00137 typedef typename handle_container_type::reverse_iterator base; 00138 public: 00139 reverse_iterator(view & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00140 reverse_iterator(const reverse_iterator & it) : base(it), view_(it.view_) {} 00141 00142 typedef typename std::iterator_traits<base>::difference_type difference_type; 00143 typedef typename view::value_type value_type; 00144 typedef typename view::reference reference; 00145 typedef typename view::const_reference const_reference; 00146 typedef typename view::pointer pointer; 00147 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00148 00149 handle_type & handle() { return base::operator*(); } 00150 const_handle_type handle() const { return base::operator*(); } 00151 00152 reference operator* () { return view_->dereference_handle( handle() ); } 00153 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00154 00155 pointer operator->() { return &(operator* ()); } 00156 pointer operator->() const { return &(operator* ()); } 00157 00158 reverse_iterator & operator++() { base::operator++(); return *this; } 00159 reverse_iterator operator++(int) { base::operator++(int()); return *this; } 00160 00161 reverse_iterator & operator--() { base::operator--(); return *this; } 00162 reverse_iterator operator--(int) { base::operator--(int()); return *this; } 00163 00164 private: 00165 view * view_; 00166 }; 00167 00168 00169 class const_reverse_iterator : public handle_container_type::const_reverse_iterator 00170 { 00171 typedef typename handle_container_type::const_reverse_iterator base; 00172 public: 00173 const_reverse_iterator(view const & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00174 const_reverse_iterator(const const_reverse_iterator & it) : base(it), view_(it.view_) {} 00175 const_reverse_iterator(const iterator & it) : base(it), view_(it.view_) {} 00176 00177 typedef typename std::iterator_traits<base>::difference_type difference_type; 00178 typedef typename view::value_type value_type; 00179 typedef typename view::const_reference reference; 00180 typedef typename view::const_reference const_reference; 00181 typedef typename view::const_pointer pointer; 00182 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00183 00184 const_handle_type handle() { return base::operator*(); } 00185 const_handle_type handle() const { return base::operator*(); } 00186 00187 reference operator* () { return view_->dereference_handle( handle() ); } 00188 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00189 00190 pointer operator->() const { return &(operator* ()); } 00191 00192 const_reverse_iterator & operator++() { base::operator++(); return *this; } 00193 const_reverse_iterator operator++(int) { base::operator++(int()); return *this; } 00194 00195 const_reverse_iterator & operator--() { base::operator--(); return *this; } 00196 const_reverse_iterator operator--(int) { base::operator--(int()); return *this; } 00197 00198 private: 00199 view const * view_; 00200 }; 00201 00202 00203 view() {} 00204 00205 void set_base_container( base_container_type & base_container_ ) 00206 { base_container = &base_container_; } 00207 00208 template<typename other_container_tag> 00209 void set_base_container( view<base_container_type, other_container_tag> & base_view ) 00210 { base_container = base_view.base_container; } 00211 00212 template<typename other_container_tag> 00213 void set_base_container( view<base_container_type, other_container_tag> const & base_view ) 00214 { base_container = base_view.base_container; } 00215 00216 00217 iterator begin() { return iterator(*this, handle_container.begin()); } 00218 iterator end() { return iterator(*this, handle_container.end()); } 00219 00220 const_iterator cbegin() { return const_iterator(*this, handle_container.begin()); } 00221 const_iterator cend() { return const_iterator(*this, handle_container.end()); } 00222 00223 const_iterator begin() const { return const_iterator(*this, handle_container.begin()); } 00224 const_iterator end() const { return const_iterator(*this, handle_container.end()); } 00225 00226 reference dereference_handle( handle_type handle ) { return viennagrid::detail::dereference_handle( *base_container, handle ); } 00227 const_reference dereference_handle( const_handle_type handle ) const { return viennagrid::detail::dereference_handle_const( *base_container, handle ); } 00228 00229 handle_type handle( reference element ) { return &element; } 00230 const_handle_type handle( const_reference element ) const { return &element; } 00231 00232 iterator find( const_reference element ) 00233 { return std::find( begin(), end(), handle(element)); } 00234 const_iterator find( const_reference element ) const 00235 { return std::find( begin(), end(), handle(element)); } 00236 00237 00238 reference front() { return dereference_handle(handle_container.front()); } 00239 const_reference front() const { return dereference_handle(handle_container.front()); } 00240 00241 reference back() { return dereference_handle(handle_container.back()); } 00242 const_reference back() const { return dereference_handle(handle_container.back()); } 00243 00244 reference operator[]( size_type index ) { iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00245 const_reference operator[]( size_type index ) const { const_iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00246 00247 00248 size_type size() const { return handle_container.size(); } 00249 void resize(size_type size_) { handle_container.resize(size_); } 00250 void increment_size() { resize( size()+1 ); } 00251 00252 bool empty() const { return handle_container.empty(); } 00253 void clear() { handle_container.clear(); } 00254 00255 00256 void insert_unique_handle(handle_type handle) 00257 { 00258 for (iterator it = begin(); it != end(); ++it) 00259 if (handle == it.handle()) return; 00260 00261 insert_handle(handle); 00262 } 00263 00264 void insert_handle(handle_type handle) { viennagrid::detail::insert(handle_container, handle); } 00265 void set_handle( handle_type element, size_type pos ) 00266 { 00267 if (size() <= pos+1) resize(pos+1); 00268 handle_container[pos] = element; 00269 } 00270 void erase_handle(handle_type handle) 00271 { 00272 for (iterator it = begin(); it != end(); ++it) 00273 if (it.handle() == handle) 00274 { 00275 handle_container.erase( it ); 00276 return; 00277 } 00278 } 00279 00280 handle_type handle_at(std::size_t pos) { return viennagrid::advance(begin(), pos).handle(); } 00281 const_handle_type handle_at(std::size_t pos) const { return viennagrid::advance(begin(), pos).handle(); } 00282 00283 private: 00284 handle_container_type handle_container; 00285 base_container_type * base_container; 00286 }; 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 // specialization for std::set 00301 template<typename base_container_type_, typename CompareTagT> 00302 class view<base_container_type_, std_set_tag<CompareTagT> > 00303 { 00304 public: 00305 00306 template<typename A, typename B> 00307 friend class view; 00308 00309 typedef base_container_type_ base_container_type; 00310 00311 typedef std_set_tag<CompareTagT> container_tag; 00312 00313 typedef typename base_container_type::handle_tag handle_tag; 00314 typedef typename detail::result_of::handle_type<base_container_type, handle_tag>::type handle_type; 00315 typedef typename detail::result_of::const_handle_type<base_container_type, handle_tag>::type const_handle_type; 00316 00317 00318 private: 00319 typedef typename viennagrid::result_of::container<handle_type, container_tag>::type handle_container_type; 00320 00321 00322 public: 00323 typedef typename handle_container_type::size_type size_type; 00324 typedef typename base_container_type::value_type value_type; 00325 typedef value_type & reference; 00326 typedef const value_type & const_reference; 00327 typedef value_type * pointer; 00328 typedef const value_type * const_pointer; 00329 00330 00331 00332 class iterator : public handle_container_type::iterator 00333 { 00334 typedef typename handle_container_type::iterator base; 00335 public: 00336 iterator(view & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00337 iterator(const iterator & it) : base(it), view_(it.view_) {} 00338 00339 typedef typename std::iterator_traits<base>::difference_type difference_type; 00340 typedef typename view::value_type value_type; 00341 typedef typename view::reference reference; 00342 typedef typename view::const_reference const_reference; 00343 typedef typename view::pointer pointer; 00344 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00345 00346 handle_type handle() { return base::operator*(); } 00347 const_handle_type handle() const { return base::operator*(); } 00348 00349 reference operator* () { return view_->dereference_handle( handle() ); } 00350 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00351 00352 pointer operator->() { return &(operator* ()); } 00353 pointer operator->() const { return &(operator* ()); } 00354 00355 iterator & operator++() { base::operator++(); return *this; } 00356 iterator operator++(int) { base::operator++(int()); return *this; } 00357 00358 iterator & operator--() { base::operator--(); return *this; } 00359 iterator operator--(int) { base::operator--(int()); return *this; } 00360 00361 private: 00362 view * view_; 00363 }; 00364 00365 00366 class const_iterator : public handle_container_type::const_iterator 00367 { 00368 typedef typename handle_container_type::const_iterator base; 00369 public: 00370 const_iterator(view const & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00371 const_iterator(const const_iterator & it) : base(it), view_(it.view_) {} 00372 const_iterator(const iterator & it) : base(it), view_(it.view_) {} 00373 00374 typedef typename std::iterator_traits<base>::difference_type difference_type; 00375 typedef typename view::value_type value_type; 00376 typedef typename view::const_reference reference; 00377 typedef typename view::const_reference const_reference; 00378 typedef typename view::const_pointer pointer; 00379 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00380 00381 const_handle_type handle() { return base::operator*(); } 00382 const_handle_type handle() const { return base::operator*(); } 00383 00384 reference operator* () { return view_->dereference_handle( handle() ); } 00385 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00386 00387 pointer operator->() const { return &(operator* ()); } 00388 00389 const_iterator & operator++() { base::operator++(); return *this; } 00390 const_iterator operator++(int) { base::operator++(int()); return *this; } 00391 00392 const_iterator & operator--() { base::operator--(); return *this; } 00393 const_iterator operator--(int) { base::operator--(int()); return *this; } 00394 00395 private: 00396 view const * view_; 00397 }; 00398 00399 class reverse_iterator : public handle_container_type::reverse_iterator 00400 { 00401 typedef typename handle_container_type::reverse_iterator base; 00402 public: 00403 reverse_iterator(view & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00404 reverse_iterator(const reverse_iterator & it) : base(it), view_(it.view_) {} 00405 00406 typedef typename std::iterator_traits<base>::difference_type difference_type; 00407 typedef typename view::value_type value_type; 00408 typedef typename view::reference reference; 00409 typedef typename view::const_reference const_reference; 00410 typedef typename view::pointer pointer; 00411 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00412 00413 handle_type & handle() { return base::operator*(); } 00414 const_handle_type handle() const { return base::operator*(); } 00415 00416 reference operator* () { return view_->dereference_handle( handle() ); } 00417 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00418 00419 pointer operator->() { return &(operator* ()); } 00420 pointer operator->() const { return &(operator* ()); } 00421 00422 reverse_iterator & operator++() { base::operator++(); return *this; } 00423 reverse_iterator operator++(int) { base::operator++(int()); return *this; } 00424 00425 reverse_iterator & operator--() { base::operator--(); return *this; } 00426 reverse_iterator operator--(int) { base::operator--(int()); return *this; } 00427 00428 private: 00429 view * view_; 00430 }; 00431 00432 00433 class const_reverse_iterator : public handle_container_type::const_reverse_iterator 00434 { 00435 typedef typename handle_container_type::const_reverse_iterator base; 00436 public: 00437 const_reverse_iterator(view const & view_obj, const base & foo) : base(foo), view_(&view_obj) {} 00438 const_reverse_iterator(const const_reverse_iterator & it) : base(it), view_(it.view_) {} 00439 const_reverse_iterator(const iterator & it) : base(it), view_(it.view) {} 00440 00441 typedef typename std::iterator_traits<base>::difference_type difference_type; 00442 typedef typename view::value_type value_type; 00443 typedef typename view::const_reference reference; 00444 typedef typename view::const_reference const_reference; 00445 typedef typename view::const_pointer pointer; 00446 typedef typename std::iterator_traits<base>::iterator_category iterator_category; 00447 00448 const_handle_type handle() { return base::operator*(); } 00449 const_handle_type handle() const { return base::operator*(); } 00450 00451 reference operator* () { return view_->dereference_handle( handle() ); } 00452 const_reference operator* () const { return view_->dereference_handle( handle() ); } 00453 00454 pointer operator->() const { return &(operator* ()); } 00455 00456 const_reverse_iterator & operator++() { base::operator++(); return *this; } 00457 const_reverse_iterator operator++(int) { base::operator++(int()); return *this; } 00458 00459 const_reverse_iterator & operator--() { base::operator--(); return *this; } 00460 const_reverse_iterator operator--(int) { base::operator--(int()); return *this; } 00461 00462 private: 00463 view const * view_; 00464 }; 00465 00466 00467 00468 view() {} 00469 00470 void set_base_container( base_container_type & base_container_ ) 00471 { base_container = &base_container_; } 00472 00473 template<typename other_container_tag> 00474 void set_base_container( view<base_container_type, other_container_tag> & base_view ) 00475 { base_container = base_view.base_container; } 00476 00477 template<typename other_container_tag> 00478 void set_base_container( view<base_container_type, other_container_tag> const & base_view ) 00479 { base_container = base_view.base_container; } 00480 00481 00482 iterator begin() { return iterator(*this, handle_container.begin()); } 00483 iterator end() { return iterator(*this, handle_container.end()); } 00484 00485 const_iterator cbegin() { return const_iterator(*this, handle_container.begin()); } 00486 const_iterator cend() { return const_iterator(*this, handle_container.end()); } 00487 00488 const_iterator begin() const { return const_iterator(*this, handle_container.begin()); } 00489 const_iterator end() const { return const_iterator(*this, handle_container.end()); } 00490 00491 00492 reference dereference_handle( handle_type handle ) { return viennagrid::detail::dereference_handle( *base_container, handle ); } 00493 const_reference dereference_handle( const_handle_type handle ) const { return viennagrid::detail::dereference_handle_const( *base_container, handle ); } 00494 00495 handle_type handle( reference element ) { return &element; } 00496 const_handle_type handle( const_reference element ) const { return &element; } 00497 00498 iterator find( const_reference element ) 00499 { return iterator(*this, handle_container.find(const_cast<handle_type>(handle(element)))); } 00500 const_iterator find( const_reference element ) const 00501 { return const_iterator(*this, handle_container.find(const_cast<handle_type>(handle(element)))); } 00502 00503 reference front() { return dereference_handle(handle_container.front()); } 00504 const_reference front() const { return dereference_handle(handle_container.front()); } 00505 00506 reference back() { return dereference_handle(handle_container.back()); } 00507 const_reference back() const { return dereference_handle(handle_container.back()); } 00508 00509 reference operator[]( size_type index ) { iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00510 const_reference operator[]( size_type index ) const { const_iterator it = begin(); std::advance(it, static_cast<long>(index)); return *it; } 00511 00512 00513 size_type size() const { return handle_container.size(); } 00514 void resize(size_type size_) { handle_container.resize(size_); } 00515 void increment_size() { resize( size()+1 ); } 00516 00517 bool empty() const { return handle_container.empty(); } 00518 void clear() { handle_container.clear(); } 00519 00520 00521 void insert_unique_handle(handle_type handle) 00522 { 00523 insert_handle(handle); 00524 } 00525 00526 void insert_handle(handle_type handle) 00527 { 00528 viennagrid::detail::insert(handle_container, handle); 00529 } 00530 void set_handle( handle_type element, size_type pos ); // not supported 00531 void erase_handle(handle_type handle) 00532 { 00533 for (iterator it = begin(); it != end(); ++it) 00534 if (it.handle() == handle) 00535 { 00536 handle_container.erase( it ); 00537 return; 00538 } 00539 } 00540 00541 handle_type handle_at(std::size_t pos) { return viennagrid::advance(begin(), pos).handle(); } 00542 const_handle_type handle_at(std::size_t pos) const { return viennagrid::advance(begin(), pos).handle(); } 00543 00544 private: 00545 handle_container_type handle_container; 00546 base_container_type * base_container; 00547 }; 00555 namespace result_of 00556 { 00562 template<typename base_container_type, typename view_container_tag> 00563 struct view 00564 { 00565 typedef viennagrid::view<base_container_type, view_container_tag> type; 00566 }; 00567 00569 template<typename base_container_type, typename base_view_container_tag, typename view_container_tag> 00570 struct view< viennagrid::view<base_container_type, base_view_container_tag>, view_container_tag> 00571 { 00572 typedef viennagrid::view<base_container_type, view_container_tag> type; 00573 }; 00574 00575 template<typename base_container_type, typename base_view_container_tag, typename view_container_tag> 00576 struct view< const viennagrid::view<base_container_type, base_view_container_tag>, view_container_tag> 00577 { 00578 typedef viennagrid::view<const base_container_type, view_container_tag> type; 00579 }; 00580 00581 template<typename base_container_type, typename base_view_container_tag, typename view_container_tag> 00582 struct view< const viennagrid::view<const base_container_type, base_view_container_tag>, view_container_tag> 00583 { 00584 typedef viennagrid::view<const base_container_type, view_container_tag> type; 00585 }; 00586 00587 template<typename base_container_type, typename base_view_container_tag, typename view_container_tag> 00588 struct view< viennagrid::view<const base_container_type, base_view_container_tag>, view_container_tag> 00589 { 00590 typedef viennagrid::view<const base_container_type, view_container_tag> type; 00591 }; 00592 00593 template<typename base_container_type, typename view_container_config> 00594 typename view<base_container_type, view_container_config>::type view_of( base_container_type & base_container ) 00595 { 00596 typename view<base_container_type, view_container_config>::type tmp; 00597 tmp.set_base_container(base_container); 00598 return tmp; 00599 } 00601 } 00602 00603 00604 00605 namespace detail 00606 { 00607 00608 template<typename base_container_type, typename view_base_container_type, typename handle_container_tag, typename predicate> 00609 void handle_if(base_container_type & src_container, viennagrid::view<view_base_container_type, handle_container_tag> & dst_view, predicate pred) 00610 { 00611 for (typename base_container_type::iterator it = src_container.begin(); it != src_container.end(); ++it) 00612 if (pred(*it)) 00613 dst_view.insert_handle( it.handle() ); 00614 } 00615 00616 template<typename base_container_type, typename view_base_container_type, typename view_container_tag> 00617 void handle(base_container_type & src_container, viennagrid::view<view_base_container_type, view_container_tag> & dst_view) 00618 { 00619 handle_if(src_container, dst_view, viennagrid::detail::true_predicate()); 00620 } 00621 00622 } 00623 00624 00625 namespace result_of 00626 { 00627 00629 template<typename container_type, typename view_container_config> 00630 struct view_container_tag 00631 { 00632 typedef typename container_type::value_type value_type; 00633 typedef typename viennagrid::detail::result_of::find<view_container_config, value_type>::type search_result; 00634 typedef typename viennagrid::detail::result_of::find<view_container_config, viennagrid::default_tag>::type default_container; 00635 00636 typedef typename viennagrid::detail::IF< 00637 !viennagrid::detail::EQUAL<search_result, viennagrid::not_found>::value, 00638 search_result, 00639 default_container 00640 >::type::second type; 00641 }; 00642 00643 00644 template<typename container_typemap, typename view_container_config> 00645 struct view_container_typemap; 00646 00647 template<typename view_container_config> 00648 struct view_container_typemap<viennagrid::null_type, view_container_config> 00649 { 00650 typedef viennagrid::null_type type; 00651 }; 00652 00653 template<typename value_type, typename container_type, typename tail, typename view_container_config> 00654 struct view_container_typemap<viennagrid::typelist< viennagrid::static_pair<value_type, container_type>, tail>, view_container_config> 00655 { 00656 typedef viennagrid::typelist< 00657 viennagrid::static_pair< 00658 value_type, 00659 typename viennagrid::result_of::view< 00660 container_type, 00661 typename view_container_tag<container_type, view_container_config>::type 00662 >::type 00663 >, 00664 typename view_container_typemap<tail, view_container_config>::type 00665 > type; 00666 }; 00667 00668 template<typename container_typemap, typename view_container_config> 00669 struct view_collection 00670 { 00671 typedef collection< 00672 typename viennagrid::result_of::view_container_typemap< 00673 container_typemap, 00674 view_container_config 00675 >::type 00676 > type; 00677 }; 00678 00679 template<typename container_typelist, typename view_container_config> 00680 struct view_collection< viennagrid::collection<container_typelist>, view_container_config> 00681 { 00682 typedef viennagrid::collection<container_typelist> container_collection_type; 00683 00684 typedef collection< 00685 typename viennagrid::result_of::view_container_typemap< 00686 container_typelist, 00687 view_container_config 00688 >::type 00689 > type; 00690 }; 00692 } 00693 00694 00695 namespace detail 00696 { 00697 template<typename BaseContainerT> 00698 typename view< BaseContainerT, std_set_tag<id_compare_tag> >::iterator find(view< BaseContainerT, std_set_tag<id_compare_tag> > & container, typename view< BaseContainerT, std_set_tag<id_compare_tag> >::value_type const & element) 00699 { 00700 return container.find(element); 00701 // typename view< BaseContainerT, std_set_tag<id_compare_tag> >::value_type tmp(); 00702 // return typename view< BaseContainerT, std_set_tag<id_compare_tag> >::iterator(container, container.base_container->find(element)); 00703 00704 00705 // return std::find_if( 00706 // container.begin(), 00707 // container.end(), 00708 // viennagrid::detail::id_compare<typename view< BaseContainerT, std_set_tag<id_compare_tag> >::value_type::id_type>(id) 00709 // ); 00710 } 00711 00712 template<typename BaseContainerT> 00713 typename view< BaseContainerT, std_set_tag<id_compare_tag> >::const_iterator find(view< BaseContainerT, std_set_tag<id_compare_tag> > const & container, typename view< BaseContainerT, std_set_tag<id_compare_tag> >::value_type const & element) 00714 { 00715 return container.find(element); 00716 // return typename view< BaseContainerT, std_set_tag<id_compare_tag> >::const_iterator(container, container.base_container->find(element)); 00717 // return std::find_if( 00718 // container.begin(), 00719 // container.end(), 00720 // viennagrid::detail::id_compare<typename view< BaseContainerT, std_set_tag<id_compare_tag> >::value_type::id_type>(element) 00721 // ); 00722 } 00723 00724 00725 00726 00728 template<typename container_collection_typemap> 00729 struct set_base_container_helper; 00730 00732 template<> 00733 struct set_base_container_helper<viennagrid::null_type> 00734 { 00735 template<typename base_container_collection_type, typename view_container_collection_type> 00736 static void exec( base_container_collection_type &, view_container_collection_type & ) {} 00737 }; 00738 00739 template<typename value_type, typename container_type, typename tail> 00740 struct set_base_container_helper< viennagrid::typelist< viennagrid::static_pair<value_type, container_type>, tail > > 00741 { 00742 template<typename base_container_collection_type, typename view_container_collection_type> 00743 static void exec( base_container_collection_type & base_container_collection, view_container_collection_type & view_container_collection ) 00744 { 00745 get<value_type>(view_container_collection).set_base_container( get<value_type>(base_container_collection) ); 00746 00747 set_base_container_helper<tail>::exec(base_container_collection, view_container_collection); 00748 } 00749 }; 00751 } 00752 00754 template<typename base_container_collection_type, typename view_container_collection_type> 00755 void set_base_container( base_container_collection_type & base_container_collection, view_container_collection_type & view_container_collection ) 00756 { 00757 detail::set_base_container_helper< typename view_container_collection_type::typemap >::exec(base_container_collection, view_container_collection); 00758 } 00759 00760 00761 } 00762 00763 #endif