Chris@16: /*============================================================================= Chris@16: Boost.Wave: A Standard compliant C++ preprocessor library Chris@16: Chris@16: http://www.boost.org/ Chris@16: Chris@16: Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost Chris@16: Software License, Version 1.0. (See accompanying file Chris@16: LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: Chris@16: #if !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED) Chris@16: #define TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: // this must occur after all of the includes and before any code appears Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: namespace boost { Chris@16: namespace wave { Chris@16: namespace impl { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // The new Boost.Iterator library already conatins a transform_iterator usable Chris@16: // for our needs. The code below wraps this up. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: class ref_transform_iterator_generator Chris@16: { Chris@16: typedef typename AdaptableUnaryFunctionT::result_type return_type; Chris@16: typedef typename AdaptableUnaryFunctionT::argument_type argument_type; Chris@16: Chris@16: public: Chris@16: typedef boost::transform_iterator< Chris@16: return_type (*)(argument_type), IteratorT, return_type> Chris@16: type; Chris@16: }; Chris@16: Chris@16: template Chris@16: inline Chris@16: typename ref_transform_iterator_generator< Chris@16: AdaptableUnaryFunctionT, IteratorT>::type Chris@16: make_ref_transform_iterator( Chris@16: IteratorT base, AdaptableUnaryFunctionT const &f) Chris@16: { Chris@16: typedef typename ref_transform_iterator_generator< Chris@16: AdaptableUnaryFunctionT, IteratorT>::type Chris@16: iterator_type; Chris@16: return iterator_type(base, f.transform); Chris@16: } Chris@16: Chris@16: // Retrieve the token value given a parse node Chris@16: // This is used in conjunction with the ref_transform_iterator above, to Chris@16: // get the token values while iterating directly over the parse tree. Chris@16: template Chris@16: struct get_token_value { Chris@16: Chris@16: typedef TokenT const &result_type; Chris@16: typedef ParseTreeNodeT const &argument_type; Chris@16: Chris@16: static result_type Chris@16: transform (argument_type node) Chris@16: { Chris@16: BOOST_ASSERT(1 == std::distance(node.value.begin(), Chris@16: node.value.end())); Chris@16: return *node.value.begin(); Chris@16: } Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: } // namespace impl Chris@16: } // namespace wave Chris@16: } // namespace boost Chris@16: Chris@16: // the suffix header occurs after all of the code Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: Chris@16: #endif // !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)