blob: 746d268f15dff522b25e7cf22e0ceb2a609071db [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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070011#ifndef NDNBOOST_STRING_FORMATTER_HPP
12#define NDNBOOST_STRING_FORMATTER_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070013
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<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070048 NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070049 const_formatter(const RangeT& Format)
50 {
51 return detail::const_formatF<
52 iterator_range<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053 NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >(::ndnboost::as_literal(Format));
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070054 }
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 Thompson3d613fd2013-10-15 15:39:04 -070066 NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070067 identity_formatter()
68 {
69 return detail::identity_formatF<
70 iterator_range<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071 NDNBOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> >();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070072 }
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 Thompson3d613fd2013-10-15 15:39:04 -070085 NDNBOOST_STRING_TYPENAME range_value<RangeT>::type>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070086 empty_formatter(const RangeT&)
87 {
88 return detail::empty_formatF<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070089 NDNBOOST_STRING_TYPENAME range_value<RangeT>::type>();
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070090 }
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 Thompson3d613fd2013-10-15 15:39:04 -0700120#endif // NDNBOOST_FORMATTER_HPP