Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Boost.Wave: A Standard compliant C++ preprocessor library
|
Chris@16
|
3
|
Chris@16
|
4 http://www.boost.org/
|
Chris@16
|
5
|
Chris@16
|
6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
|
Chris@16
|
7 Software License, Version 1.0. (See accompanying file
|
Chris@16
|
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 =============================================================================*/
|
Chris@16
|
10
|
Chris@16
|
11 #if !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)
|
Chris@16
|
12 #define TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/config.hpp>
|
Chris@16
|
15 #include <boost/iterator_adaptors.hpp>
|
Chris@16
|
16 #include <boost/iterator/transform_iterator.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/assert.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 // this must occur after all of the includes and before any code appears
|
Chris@16
|
21 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
22 #include BOOST_ABI_PREFIX
|
Chris@16
|
23 #endif
|
Chris@16
|
24
|
Chris@16
|
25 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
26 namespace boost {
|
Chris@16
|
27 namespace wave {
|
Chris@16
|
28 namespace impl {
|
Chris@16
|
29
|
Chris@16
|
30 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
31 //
|
Chris@16
|
32 // The new Boost.Iterator library already conatins a transform_iterator usable
|
Chris@16
|
33 // for our needs. The code below wraps this up.
|
Chris@16
|
34 //
|
Chris@16
|
35 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
36 template <class AdaptableUnaryFunctionT, class IteratorT>
|
Chris@16
|
37 class ref_transform_iterator_generator
|
Chris@16
|
38 {
|
Chris@16
|
39 typedef typename AdaptableUnaryFunctionT::result_type return_type;
|
Chris@16
|
40 typedef typename AdaptableUnaryFunctionT::argument_type argument_type;
|
Chris@16
|
41
|
Chris@16
|
42 public:
|
Chris@16
|
43 typedef boost::transform_iterator<
|
Chris@16
|
44 return_type (*)(argument_type), IteratorT, return_type>
|
Chris@16
|
45 type;
|
Chris@16
|
46 };
|
Chris@16
|
47
|
Chris@16
|
48 template <class AdaptableUnaryFunctionT, class IteratorT>
|
Chris@16
|
49 inline
|
Chris@16
|
50 typename ref_transform_iterator_generator<
|
Chris@16
|
51 AdaptableUnaryFunctionT, IteratorT>::type
|
Chris@16
|
52 make_ref_transform_iterator(
|
Chris@16
|
53 IteratorT base, AdaptableUnaryFunctionT const &f)
|
Chris@16
|
54 {
|
Chris@16
|
55 typedef typename ref_transform_iterator_generator<
|
Chris@16
|
56 AdaptableUnaryFunctionT, IteratorT>::type
|
Chris@16
|
57 iterator_type;
|
Chris@16
|
58 return iterator_type(base, f.transform);
|
Chris@16
|
59 }
|
Chris@16
|
60
|
Chris@16
|
61 // Retrieve the token value given a parse node
|
Chris@16
|
62 // This is used in conjunction with the ref_transform_iterator above, to
|
Chris@16
|
63 // get the token values while iterating directly over the parse tree.
|
Chris@16
|
64 template <typename TokenT, typename ParseTreeNodeT>
|
Chris@16
|
65 struct get_token_value {
|
Chris@16
|
66
|
Chris@16
|
67 typedef TokenT const &result_type;
|
Chris@16
|
68 typedef ParseTreeNodeT const &argument_type;
|
Chris@16
|
69
|
Chris@16
|
70 static result_type
|
Chris@16
|
71 transform (argument_type node)
|
Chris@16
|
72 {
|
Chris@16
|
73 BOOST_ASSERT(1 == std::distance(node.value.begin(),
|
Chris@16
|
74 node.value.end()));
|
Chris@16
|
75 return *node.value.begin();
|
Chris@16
|
76 }
|
Chris@16
|
77 };
|
Chris@16
|
78
|
Chris@16
|
79 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
80 } // namespace impl
|
Chris@16
|
81 } // namespace wave
|
Chris@16
|
82 } // namespace boost
|
Chris@16
|
83
|
Chris@16
|
84 // the suffix header occurs after all of the code
|
Chris@16
|
85 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
86 #include BOOST_ABI_SUFFIX
|
Chris@16
|
87 #endif
|
Chris@16
|
88
|
Chris@16
|
89 #endif // !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)
|