1 /*=============================================================================
2 Copyright (c) 2001-2003 Joel de Guzman
3 Copyright (c) 2001 Daniel Nuffer
4 http://spirit.sourceforge.net/
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_PARSER_ID_HPP)
10 #define BOOST_SPIRIT_PARSER_ID_HPP
12 #if defined(BOOST_SPIRIT_DEBUG)
15 #include <boost/spirit/home/classic/namespace.hpp>
17 ///////////////////////////////////////////////////////////////////////////////
18 namespace boost { namespace spirit {
20 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
22 ///////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////
31 explicit parser_id(void const* prule) : p(prule) {}
32 parser_id(std::size_t l_) : l(l_) {}
34 bool operator==(parser_id const& x) const { return p == x.p; }
35 bool operator!=(parser_id const& x) const { return !(*this == x); }
36 bool operator<(parser_id const& x) const { return p < x.p; }
37 std::size_t to_long() const { return l; }
48 #if defined(BOOST_SPIRIT_DEBUG)
50 operator<<(std::ostream& out, parser_id const& rid)
52 out << (unsigned int)rid.to_long();
57 ///////////////////////////////////////////////////////////////////////////
59 // parser_tag_base class: base class of all parser tags
61 ///////////////////////////////////////////////////////////////////////////
62 struct parser_tag_base {};
64 ///////////////////////////////////////////////////////////////////////////
66 // parser_address_tag class: tags a parser with its address
68 ///////////////////////////////////////////////////////////////////////////
69 struct parser_address_tag : parser_tag_base
72 { return parser_id(reinterpret_cast<std::size_t>(this)); }
75 ///////////////////////////////////////////////////////////////////////////
77 // parser_tag class: tags a parser with an integer ID
79 ///////////////////////////////////////////////////////////////////////////
81 struct parser_tag : parser_tag_base
84 { return parser_id(std::size_t(N)); }
87 ///////////////////////////////////////////////////////////////////////////
89 // dynamic_parser_tag class: tags a parser with a dynamically changeable
92 ///////////////////////////////////////////////////////////////////////////
93 class dynamic_parser_tag : public parser_tag_base
98 : tag(std::size_t(0)) {}
106 : parser_id(reinterpret_cast<std::size_t>(this));
109 void set_id(parser_id id_) { tag = id_; }
116 ///////////////////////////////////////////////////////////////////////////////
117 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
119 }} // namespace BOOST_SPIRIT_CLASSIC_NS