Document visitors and formatters

This commit is contained in:
vitaut
2016-04-21 07:31:32 -07:00
parent 9ae2ac2fb7
commit c7d9d79ad2

View File

@ -1390,13 +1390,13 @@ class ArgList {
To use `~fmt::ArgVisitor` define a subclass that implements some or all of the To use `~fmt::ArgVisitor` define a subclass that implements some or all of the
visit methods with the same signatures as the methods in `~fmt::ArgVisitor`, visit methods with the same signatures as the methods in `~fmt::ArgVisitor`,
for example, `visit_int(int)`. for example, `~fmt::ArgVisitor::visit_int()`.
Pass the subclass as the *Impl* template parameter. Then calling Pass the subclass as the *Impl* template parameter. Then calling
`~fmt::ArgVisitor::visit` for some argument will dispatch to a visit method `~fmt::ArgVisitor::visit` for some argument will dispatch to a visit method
specific to the argument type. For example, if the argument type is specific to the argument type. For example, if the argument type is
``double`` then `visit_double(double)` method of a subclass will be called. ``double`` then the `~fmt::ArgVisitor::visit_double()` method of a subclass
If the subclass doesn't contain a method with this signature, then will be called. If the subclass doesn't contain a method with this signature,
a corresponding method of `~fmt::ArgVisitor` will be called. then a corresponding method of `~fmt::ArgVisitor` will be called.
**Example**:: **Example**::
@ -1450,7 +1450,7 @@ class ArgVisitor {
return FMT_DISPATCH(visit_any_int(value)); return FMT_DISPATCH(visit_any_int(value));
} }
/** Visits an argument of any integer type. **/ /** Visits an argument of any integral type. **/
template <typename T> template <typename T>
Result visit_any_int(T) { Result visit_any_int(T) {
return FMT_DISPATCH(visit_unhandled_arg()); return FMT_DISPATCH(visit_unhandled_arg());
@ -1498,9 +1498,12 @@ class ArgVisitor {
} }
/** /**
\rst
Visits an argument dispatching to the appropriate visit method based on Visits an argument dispatching to the appropriate visit method based on
the argument type. For example, if the argument type is ``double`` then the argument type. For example, if the argument type is ``double`` then
`visit_double(double)` method of the ``Impl`` class will be called. the `~fmt::ArgVisitor::visit_double()` method of the *Impl* class will be
called.
\endrst
*/ */
Result visit(const Arg &arg) { Result visit(const Arg &arg) {
switch (arg.type) { switch (arg.type) {
@ -1763,7 +1766,8 @@ namespace internal {
template <typename Char> template <typename Char>
class ArgMap { class ArgMap {
private: private:
typedef std::vector<std::pair<fmt::BasicStringRef<Char>, internal::Arg> > MapType; typedef std::vector<
std::pair<fmt::BasicStringRef<Char>, internal::Arg> > MapType;
typedef typename MapType::value_type Pair; typedef typename MapType::value_type Pair;
MapType map_; MapType map_;
@ -1954,14 +1958,14 @@ class PrintfFormatter : private FormatterBase {
To use `~fmt::BasicArgFormatter` define a subclass that implements some or To use `~fmt::BasicArgFormatter` define a subclass that implements some or
all of the visit methods with the same signatures as the methods in all of the visit methods with the same signatures as the methods in
`~fmt::ArgVisitor`, for example, `visit_int(int)`. `~fmt::ArgVisitor`, for example, `~fmt::ArgVisitor::visit_int()`.
Pass the subclass as the *Impl* template parameter. When a formatting Pass the subclass as the *Impl* template parameter. When a formatting
function processes an argument, it will dispatch to a visit method function processes an argument, it will dispatch to a visit method
specific to the argument type. For example, if the argument type is specific to the argument type. For example, if the argument type is
``double`` then `visit_double(double)` method of a subclass will be called. ``double`` then the `~fmt::ArgVisitor::visit_double()` method of a subclass
If the subclass doesn't contain a method with this signature, then will be called. If the subclass doesn't contain a method with this signature,
a corresponding method of `~fmt::BasicArgFormatter` or its superclass will be then a corresponding method of `~fmt::BasicArgFormatter` or its superclass
called. will be called.
**Example**:: **Example**::