1 /*=============================================================================
2 Copyright (c) 2011 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_QUICKBOOK_VALUES_TAGS_HPP)
10 #define BOOST_SPIRIT_QUICKBOOK_VALUES_TAGS_HPP
12 #include <boost/preprocessor/stringize.hpp>
13 #include <boost/preprocessor/seq/enum.hpp>
14 #include <boost/preprocessor/seq/for_each.hpp>
15 #include <boost/preprocessor/seq/elem.hpp>
16 #include <boost/range/irange.hpp>
19 #define QUICKBOOK_VALUE_TAGS(tags_name, start_index, values) \
21 enum tags_name##_enum { \
22 previous_index = start_index - 1, \
23 BOOST_PP_SEQ_ENUM(values), \
27 static char const* name(int value) { \
31 BOOST_PP_SEQ_FOR_EACH(QUICKBOOK_VALUE_CASE, _, values) \
33 assert(false); return ""; \
37 typedef boost::integer_range<int> range_type; \
38 static range_type tags() { return boost::irange(start_index, (int) end_index); } \
39 static bool is_tag(int value) { \
40 return value >= start_index && value < (int) end_index; \
44 #define QUICKBOOK_VALUE_CASE(r, _, value) \
45 case value: return BOOST_PP_STRINGIZE(value);
47 #define QUICKBOOK_VALUE_NAMED_TAGS(tags_name, start_index, values) \
49 enum tags_name##_enum { \
50 previous_index = start_index - 1 \
51 BOOST_PP_SEQ_FOR_EACH(QUICKBOOK_VALUE_NAMED_ENUM, _, values), \
55 static char const* name(int value) { \
59 BOOST_PP_SEQ_FOR_EACH(QUICKBOOK_VALUE_NAMED_CASE, _, values) \
61 assert(false); return ""; \
65 typedef boost::integer_range<int> range_type; \
66 static range_type tags() { return boost::irange(start_index, (int) end_index); } \
67 static bool is_tag(int value) { \
68 return value >= start_index && value < (int) end_index; \
72 #define QUICKBOOK_VALUE_NAMED_ENUM(r, _, value) \
73 , BOOST_PP_SEQ_ELEM(0, value)
75 #define QUICKBOOK_VALUE_NAMED_CASE(r, _, value) \
76 case BOOST_PP_SEQ_ELEM(0, value): return BOOST_PP_SEQ_ELEM(1, value);