blob: 5739b40a995fee7ba48de2e692c94c6840daa5cb [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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
11#ifndef BOOST_STRING_FORMATTER_HPP
12#define BOOST_STRING_FORMATTER_HPP
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
32namespace 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<
48 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >
49 const_formatter(const RangeT& Format)
50 {
51 return detail::const_formatF<
52 iterator_range<
53 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(::ndnboost::as_literal(Format));
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<
66 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >
67 identity_formatter()
68 {
69 return detail::identity_formatF<
70 iterator_range<
71 BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
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<
85 BOOST_STRING_TYPENAME range_value<RangeT>::type>
86 empty_formatter(const RangeT&)
87 {
88 return detail::empty_formatF<
89 BOOST_STRING_TYPENAME range_value<RangeT>::type>();
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
120#endif // BOOST_FORMATTER_HPP