Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Wave: a Standard conformant C++ preprocessor library

, 10 Jan 2004
Describes a free and fully Standard conformant C++ preprocessor library
wave_preprocessor_demo.zip
wave.exe
wave_preprocessor_demo1.zip
wave.exe
wave_preprocessor_src.zip
wave
doc
theme
bkd.gif
bkd2.gif
bullet.gif
l_arr.gif
l_arr_disabled.gif
r_arr.gif
r_arr_disabled.gif
uc.gif
u_arr.gif
wave.gif
test
boost-build.jam
cpp_tokens
Jamfile.v2
list_includes
project-root.jam
wave
Jamfile
Jamfile.v2
runtests.sh
test_files
wave
cpplexer
re2clex
cpp.re
test
lextest.in
lextest.output
run_tests.sh
test_lexer.in
test_lexer.output
slex
test
lextest.in
lextest.re2c.output
lextest.slex.output
run_tests.sh
grammars
idllexer
re2clex
idl.re
util
wave_preprocessor_src1.zip
bkd.gif
bkd2.gif
bullet.gif
l_arr.gif
l_arr_disabled.gif
r_arr.gif
r_arr_disabled.gif
u_arr.gif
uc.gif
wave.gif
boost-build.jam
Jamfile.v2
project-root.jam
Jamfile
Jamfile.v2
runtests.sh
cpp.re
lextest.in
lextest.output
run_tests.sh
test_lexer.in
test_lexer.output
lextest.in
lextest.re2c.output
lextest.slex.output
run_tests.sh
/*=============================================================================
    Wave: A Standard compliant C++ preprocessor

    Copyright (c) 2001-2003 Hartmut Kaiser
    http://spirit.sourceforge.net/

    Permission to copy, use, modify, sell and distribute this software
    is granted provided this copyright notice appears in all copies.
    This software is provided "as is" without express or implied
    warranty, and with no claim as to its suitability for any purpose.

    See Copyright.txt for full copyright notices and acknowledgements.
=============================================================================*/

#if !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)
#define TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED

#include <boost/iterator_adaptors.hpp>
#include <boost/spirit/core/assert.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace wave { 
namespace impl {

///////////////////////////////////////////////////////////////////////////////
// 
//  Transform Iterator Adaptor
//
//  Upon deference, apply some unary function object and return the
//  result by reference.
//
//  This class is adapted from the Boost.Iterator library, where a similar 
//  class exists, which returns the next item by value

    template <class AdaptableUnaryFunctionT>
    struct ref_transform_iterator_policies 
    :   public boost::default_iterator_policies
    {
        ref_transform_iterator_policies() 
        {}
        ref_transform_iterator_policies(const AdaptableUnaryFunctionT &f) 
        : m_f(f) {}

        template <class IteratorAdaptorT>
        typename IteratorAdaptorT::reference
        dereference(const IteratorAdaptorT &iter) const
        { return m_f(*iter.base()); }

        AdaptableUnaryFunctionT m_f;
    };

    template <class AdaptableUnaryFunctionT, class IteratorT>
    class ref_transform_iterator_generator
    {
        typedef typename AdaptableUnaryFunctionT::result_type value_type;
        
    public:
        typedef boost::iterator_adaptor<
                IteratorT,
                ref_transform_iterator_policies<AdaptableUnaryFunctionT>,
                value_type, value_type const &, value_type const *, 
                std::input_iterator_tag>
            type;
    };

    template <class AdaptableUnaryFunctionT, class IteratorT>
    inline 
    typename ref_transform_iterator_generator<
        AdaptableUnaryFunctionT, IteratorT>::type
    make_ref_transform_iterator(
        IteratorT base,
        const AdaptableUnaryFunctionT &f = AdaptableUnaryFunctionT())
    {
        typedef typename ref_transform_iterator_generator<
                    AdaptableUnaryFunctionT, IteratorT>::type 
            result_t;
        return result_t(base, f);
    }

    //  Retrieve the token value given a parse node
    //  This is used in conjunctione with the ref_transform_iterator above, to
    //  get the token values while iterating directly over the parse tree.
    template <typename TokenT, typename ParseTreeNodeT>
    struct get_token_value {

        typedef TokenT result_type;
        
        TokenT const &operator()(ParseTreeNodeT const &node) const
        {
            BOOST_SPIRIT_ASSERT(1 == std::distance(node.value.begin(), 
                node.value.end()));
            return *node.value.begin();
        }
    };
    
///////////////////////////////////////////////////////////////////////////////
}   // namespace impl
}   // namespace wave

#endif // !defined(TRANSFORM_ITERATOR_HPP_D492C659_88C7_4258_8C42_192F9AE80EC0_INCLUDED)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Hartmut Kaiser

United States United States
Actively involved in Boost and the development of the Spirit parser construction framework.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 11 Jan 2004
Article Copyright 2003 by Hartmut Kaiser
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid