Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Boost string_algo library formatter.hpp header file ---------------------------// |
| 2 | |
| 3 | // Copyright Pavol Droba 2002-2003. |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | // See http://www.boost.org/ for updates, documentation, and revision history. |
| 10 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 11 | #ifndef NDNBOOST_STRING_FORMATTER_HPP |
| 12 | #define NDNBOOST_STRING_FORMATTER_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 13 | |
| 14 | #include <ndnboost/detail/iterator.hpp> |
| 15 | #include <ndnboost/range/value_type.hpp> |
| 16 | #include <ndnboost/range/iterator_range.hpp> |
| 17 | #include <ndnboost/range/as_literal.hpp> |
| 18 | |
| 19 | #include <ndnboost/algorithm/string/detail/formatter.hpp> |
| 20 | |
| 21 | /*! \file |
| 22 | Defines Formatter generators. Formatter is a functor which formats |
| 23 | a string according to given parameters. A Formatter works |
| 24 | in conjunction with a Finder. A Finder can provide additional information |
| 25 | for a specific Formatter. An example of such a cooperation is regex_finder |
| 26 | and regex_formatter. |
| 27 | |
| 28 | Formatters are used as pluggable components for replace facilities. |
| 29 | This header contains generator functions for the Formatters provided in this library. |
| 30 | */ |
| 31 | |
| 32 | namespace ndnboost { |
| 33 | namespace algorithm { |
| 34 | |
| 35 | // generic formatters ---------------------------------------------------------------// |
| 36 | |
| 37 | //! Constant formatter |
| 38 | /*! |
| 39 | Constructs a \c const_formatter. Const formatter always returns |
| 40 | the same value, regardless of the parameter. |
| 41 | |
| 42 | \param Format A predefined value used as a result for formatting |
| 43 | \return An instance of the \c const_formatter object. |
| 44 | */ |
| 45 | template<typename RangeT> |
| 46 | inline detail::const_formatF< |
| 47 | iterator_range< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 48 | NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> > |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 49 | const_formatter(const RangeT& Format) |
| 50 | { |
| 51 | return detail::const_formatF< |
| 52 | iterator_range< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 53 | NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(::ndnboost::as_literal(Format)); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | //! Identity formatter |
| 57 | /*! |
| 58 | Constructs an \c identity_formatter. Identity formatter always returns |
| 59 | the parameter. |
| 60 | |
| 61 | \return An instance of the \c identity_formatter object. |
| 62 | */ |
| 63 | template<typename RangeT> |
| 64 | inline detail::identity_formatF< |
| 65 | iterator_range< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 66 | NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> > |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 67 | identity_formatter() |
| 68 | { |
| 69 | return detail::identity_formatF< |
| 70 | iterator_range< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 71 | NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | //! Empty formatter |
| 75 | /*! |
| 76 | Constructs an \c empty_formatter. Empty formatter always returns an empty |
| 77 | sequence. |
| 78 | |
| 79 | \param Input container used to select a correct value_type for the |
| 80 | resulting empty_container<>. |
| 81 | \return An instance of the \c empty_formatter object. |
| 82 | */ |
| 83 | template<typename RangeT> |
| 84 | inline detail::empty_formatF< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 85 | NDNBOOST_STRING_TYPENAME range_value<RangeT>::type> |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 86 | empty_formatter(const RangeT&) |
| 87 | { |
| 88 | return detail::empty_formatF< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 89 | NDNBOOST_STRING_TYPENAME range_value<RangeT>::type>(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | //! Empty formatter |
| 93 | /*! |
| 94 | Constructs a \c dissect_formatter. Dissect formatter uses a specified finder |
| 95 | to extract a portion of the formatted sequence. The first finder's match is returned |
| 96 | as a result |
| 97 | |
| 98 | \param Finder a finder used to select a portion of the formatted sequence |
| 99 | \return An instance of the \c dissect_formatter object. |
| 100 | */ |
| 101 | template<typename FinderT> |
| 102 | inline detail::dissect_formatF< FinderT > |
| 103 | dissect_formatter(const FinderT& Finder) |
| 104 | { |
| 105 | return detail::dissect_formatF<FinderT>(Finder); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | } // namespace algorithm |
| 110 | |
| 111 | // pull the names to the boost namespace |
| 112 | using algorithm::const_formatter; |
| 113 | using algorithm::identity_formatter; |
| 114 | using algorithm::empty_formatter; |
| 115 | using algorithm::dissect_formatter; |
| 116 | |
| 117 | } // namespace ndnboost |
| 118 | |
| 119 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 120 | #endif // NDNBOOST_FORMATTER_HPP |