vrshoot

annotate libs/assimp/boost/foreach.hpp @ 2:334d17aed7de

visual studio project files
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Feb 2014 18:36:38 +0200
parents
children
rev   line source
nuclear@0 1
nuclear@0 2 #ifndef BOOST_FOREACH
nuclear@0 3
nuclear@0 4 ///////////////////////////////////////////////////////////////////////////////
nuclear@0 5 // A stripped down version of FOREACH for
nuclear@0 6 // illustration purposes. NOT FOR GENERAL USE.
nuclear@0 7 // For a complete implementation, see BOOST_FOREACH at
nuclear@0 8 // http://boost-sandbox.sourceforge.net/vault/index.php?directory=eric_niebler
nuclear@0 9 //
nuclear@0 10 // Copyright 2004 Eric Niebler.
nuclear@0 11 // Distributed under the Boost Software License, Version 1.0. (See
nuclear@0 12 // accompanying file LICENSE_1_0.txt or copy at
nuclear@0 13 // http://www.boost.org/LICENSE_1_0.txt)
nuclear@0 14 //
nuclear@0 15 // Adapted to Assimp November 29th, 2008 (Alexander Gessler).
nuclear@0 16 // Added code to handle both const and non-const iterators, simplified some
nuclear@0 17 // parts.
nuclear@0 18 ///////////////////////////////////////////////////////////////////////////////
nuclear@0 19
nuclear@0 20 namespace boost {
nuclear@0 21 namespace foreach_detail {
nuclear@0 22
nuclear@0 23 ///////////////////////////////////////////////////////////////////////////////
nuclear@0 24 // auto_any
nuclear@0 25
nuclear@0 26 struct auto_any_base
nuclear@0 27 {
nuclear@0 28 operator bool() const { return false; }
nuclear@0 29 };
nuclear@0 30
nuclear@0 31 template<typename T>
nuclear@0 32 struct auto_any : auto_any_base
nuclear@0 33 {
nuclear@0 34 auto_any(T const& t) : item(t) {}
nuclear@0 35 mutable T item;
nuclear@0 36 };
nuclear@0 37
nuclear@0 38 template<typename T>
nuclear@0 39 T& auto_any_cast(auto_any_base const& any)
nuclear@0 40 {
nuclear@0 41 return static_cast<auto_any<T> const&>(any).item;
nuclear@0 42 }
nuclear@0 43
nuclear@0 44 ///////////////////////////////////////////////////////////////////////////////
nuclear@0 45 // FOREACH helper function
nuclear@0 46
nuclear@0 47 template<typename T>
nuclear@0 48 auto_any<typename T::const_iterator> begin(T const& t)
nuclear@0 49 {
nuclear@0 50 return t.begin();
nuclear@0 51 }
nuclear@0 52
nuclear@0 53 template<typename T>
nuclear@0 54 auto_any<typename T::const_iterator> end(T const& t)
nuclear@0 55 {
nuclear@0 56 return t.end();
nuclear@0 57 }
nuclear@0 58
nuclear@0 59 // iterator
nuclear@0 60 template<typename T>
nuclear@0 61 bool done(auto_any_base const& cur, auto_any_base const& end, T&)
nuclear@0 62 {
nuclear@0 63 typedef typename T::iterator iter_type;
nuclear@0 64 return auto_any_cast<iter_type>(cur) == auto_any_cast<iter_type>(end);
nuclear@0 65 }
nuclear@0 66
nuclear@0 67 template<typename T>
nuclear@0 68 void next(auto_any_base const& cur, T&)
nuclear@0 69 {
nuclear@0 70 ++auto_any_cast<typename T::iterator>(cur);
nuclear@0 71 }
nuclear@0 72
nuclear@0 73 template<typename T>
nuclear@0 74 typename T::reference deref(auto_any_base const& cur, T&)
nuclear@0 75 {
nuclear@0 76 return *auto_any_cast<typename T::iterator>(cur);
nuclear@0 77 }
nuclear@0 78
nuclear@0 79 template<typename T>
nuclear@0 80 typename T::const_reference deref(auto_any_base const& cur, const T&)
nuclear@0 81 {
nuclear@0 82 return *auto_any_cast<typename T::iterator>(cur);
nuclear@0 83 }
nuclear@0 84
nuclear@0 85 } // end foreach_detail
nuclear@0 86
nuclear@0 87 ///////////////////////////////////////////////////////////////////////////////
nuclear@0 88 // FOREACH
nuclear@0 89
nuclear@0 90 #define BOOST_FOREACH(item, container) \
nuclear@0 91 if(boost::foreach_detail::auto_any_base const& foreach_magic_b = boost::foreach_detail::begin(container)) {} else \
nuclear@0 92 if(boost::foreach_detail::auto_any_base const& foreach_magic_e = boost::foreach_detail::end(container)) {} else \
nuclear@0 93 for(;!boost::foreach_detail::done(foreach_magic_b,foreach_magic_e,container); boost::foreach_detail::next(foreach_magic_b,container)) \
nuclear@0 94 if (bool ugly_and_unique_break = false) {} else \
nuclear@0 95 for(item = boost::foreach_detail::deref(foreach_magic_b,container); !ugly_and_unique_break; ugly_and_unique_break = true)
nuclear@0 96
nuclear@0 97 } // end boost
nuclear@0 98
nuclear@0 99 #endif