| 1 | // Copyright (c) 2001-2011 Hartmut Kaiser |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #if !defined(BOOST_SPIRIT_KARMA_AS_STRING_DEC_18_0644PM) |
| 7 | #define BOOST_SPIRIT_KARMA_AS_STRING_DEC_18_0644PM |
| 8 | |
| 9 | #if defined(_MSC_VER) |
| 10 | #pragma once |
| 11 | #endif |
| 12 | |
| 13 | #include <boost/spirit/home/support/unused.hpp> |
| 14 | #include <boost/spirit/home/support/attributes_fwd.hpp> |
| 15 | |
| 16 | /////////////////////////////////////////////////////////////////////////////// |
| 17 | namespace boost { namespace spirit { namespace traits |
| 18 | { |
| 19 | /////////////////////////////////////////////////////////////////////////// |
| 20 | // This file contains the attribute to string conversion utility. The |
| 21 | // utility provided also accept spirit's unused_type; all no-ops. Compiler |
| 22 | // optimization will easily strip these away. |
| 23 | /////////////////////////////////////////////////////////////////////////// |
| 24 | |
| 25 | /////////////////////////////////////////////////////////////////////////// |
| 26 | template <typename T, typename Attribute> |
| 27 | inline typename spirit::result_of::attribute_as<T, Attribute>::type |
| 28 | as(Attribute const& attr) |
| 29 | { |
| 30 | return attribute_as<T, Attribute>::call(attr); |
| 31 | } |
| 32 | |
| 33 | template <typename T> |
| 34 | inline unused_type as(unused_type) |
| 35 | { |
| 36 | return unused; |
| 37 | } |
| 38 | |
| 39 | /////////////////////////////////////////////////////////////////////////// |
| 40 | template <typename T, typename Attribute> |
| 41 | inline bool valid_as(Attribute const& attr) |
| 42 | { |
| 43 | return attribute_as<T, Attribute>::is_valid(attr); |
| 44 | } |
| 45 | |
| 46 | template <typename T> |
| 47 | inline bool valid_as(unused_type) |
| 48 | { |
| 49 | return true; |
| 50 | } |
| 51 | }}} |
| 52 | |
| 53 | /////////////////////////////////////////////////////////////////////////////// |
| 54 | namespace boost { namespace spirit { namespace result_of |
| 55 | { |
| 56 | template <typename T, typename Attribute> |
| 57 | struct attribute_as |
| 58 | : traits::attribute_as<T, Attribute> |
| 59 | {}; |
| 60 | |
| 61 | template <typename T> |
| 62 | struct attribute_as<T, unused_type> |
| 63 | { |
| 64 | typedef unused_type type; |
| 65 | }; |
| 66 | |
| 67 | template <typename T> |
| 68 | struct attribute_as<T, unused_type const> |
| 69 | { |
| 70 | typedef unused_type type; |
| 71 | }; |
| 72 | }}} |
| 73 | |
| 74 | #endif |
| 75 | |