|
| 1 | + |
| 2 | +// Copyright Dean Michael Berris 2007. |
| 3 | +// Distributed under the Boost Software License, Version 1.0. |
| 4 | +// (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 6 | + |
| 7 | +#ifndef __NETWORK_MESSAGE_TRANSFORMERS_TO_LOWER_HPP__ |
| 8 | +#define __NETWORK_MESSAGE_TRANSFORMERS_TO_LOWER_HPP__ |
| 9 | + |
| 10 | +#include <boost/algorithm/string.hpp> |
| 11 | + |
| 12 | +/** to_lower.hpp |
| 13 | + * |
| 14 | + * Implements the to_lower transformer. This applies |
| 15 | + * the to_lower string algorithm to a string, which |
| 16 | + * is selected by the appropriate selector. |
| 17 | + * |
| 18 | + * This defines a type, to be applied using template |
| 19 | + * metaprogramming on the selected string target. |
| 20 | + */ |
| 21 | +namespace boost { namespace network { |
| 22 | + |
| 23 | + namespace impl { |
| 24 | + |
| 25 | + template <class Selector> |
| 26 | + struct to_lower_transformer { }; |
| 27 | + |
| 28 | + template <> |
| 29 | + struct to_lower_transformer<selectors::source_selector> { |
| 30 | + template <class Tag> |
| 31 | + void operator() (basic_message<Tag> & message_) const { |
| 32 | + boost::to_lower(message_.source()); |
| 33 | + }; |
| 34 | + |
| 35 | + protected: |
| 36 | + ~to_lower_transformer() { }; |
| 37 | + }; |
| 38 | + |
| 39 | + template <> |
| 40 | + struct to_lower_transformer<selectors::destination_selector> { |
| 41 | + template <class Tag> |
| 42 | + void operator() (basic_message<Tag> & message_) const { |
| 43 | + boost::to_lower(message_.destination()); |
| 44 | + }; |
| 45 | + |
| 46 | + protected: |
| 47 | + ~to_lower_transformer() { }; |
| 48 | + }; |
| 49 | + |
| 50 | + }; // namespace impl |
| 51 | + |
| 52 | + namespace detail { |
| 53 | + struct to_lower_placeholder_helper; |
| 54 | + }; |
| 55 | + |
| 56 | + detail::to_lower_placeholder_helper to_lower_(detail::to_lower_placeholder_helper); |
| 57 | + |
| 58 | + namespace detail { |
| 59 | + |
| 60 | + struct to_lower_placeholder_helper { |
| 61 | + template <class Selector> |
| 62 | + struct type : public impl::to_lower_transformer<Selector> { }; |
| 63 | + private: |
| 64 | + to_lower_placeholder_helper() {}; |
| 65 | + to_lower_placeholder_helper(to_lower_placeholder_helper const &) {}; |
| 66 | + friend to_lower_placeholder_helper boost::network::to_lower_(to_lower_placeholder_helper); |
| 67 | + }; |
| 68 | + |
| 69 | + }; |
| 70 | + |
| 71 | + typedef detail::to_lower_placeholder_helper (*to_lower_placeholder)(detail::to_lower_placeholder_helper); |
| 72 | + |
| 73 | + inline detail::to_lower_placeholder_helper to_lower_(detail::to_lower_placeholder_helper) { |
| 74 | + return detail::to_lower_placeholder_helper(); |
| 75 | + }; |
| 76 | + |
| 77 | +}; // namespace network |
| 78 | + |
| 79 | +}; // namespace boost |
| 80 | + |
| 81 | +#endif // __NETWORK_MESSAGE_TRANSFORMERS_TO_LOWER_HPP__ |
| 82 | + |
0 commit comments