Document the API.
This commit is contained in:
parent
3c90a8736b
commit
9e81263cf5
@ -54,9 +54,9 @@ copyright = u'1990-2012, Python Software Foundation'
|
|||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = '0.3'
|
version = '0.4'
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = '0.3'
|
release = '0.4'
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
# for a list of supported languages.
|
# for a list of supported languages.
|
||||||
|
@ -10,6 +10,11 @@ String Formatting
|
|||||||
.. doxygenclass:: format::Formatter
|
.. doxygenclass:: format::Formatter
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
.. doxygenclass:: format::TempFormatter
|
||||||
|
:members:
|
||||||
|
|
||||||
|
.. doxygenstruct:: format::NoAction
|
||||||
|
|
||||||
.. doxygenclass:: format::StringRef
|
.. doxygenclass:: format::StringRef
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
29
format.h
29
format.h
@ -761,8 +761,11 @@ inline internal::ArgInserter Formatter::operator()(StringRef format) {
|
|||||||
return formatter;
|
return formatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A formatting action that does nothing.
|
/**
|
||||||
|
A formatting action that does nothing.
|
||||||
|
*/
|
||||||
struct NoAction {
|
struct NoAction {
|
||||||
|
/** Does nothing. */
|
||||||
void operator()(const Formatter &) const {}
|
void operator()(const Formatter &) const {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -793,25 +796,39 @@ class TempFormatter : public internal::ArgInserter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Creates an active formatter with a format string and an action.
|
/**
|
||||||
// Action should be an unary function object that takes a const
|
\rst
|
||||||
// reference to Formatter as an argument. See Ignore and Write
|
Constructs a temporary formatter with a format string and an action.
|
||||||
// for examples of action classes.
|
The action should be an unary function object that takes a const
|
||||||
|
reference to :cpp:class:`format::Formatter` as an argument.
|
||||||
|
See :cpp:class:`format::NoAction` and :cpp:class:`format::Write` for
|
||||||
|
examples of action classes.
|
||||||
|
\endrst
|
||||||
|
*/
|
||||||
explicit TempFormatter(StringRef format, Action a = Action())
|
explicit TempFormatter(StringRef format, Action a = Action())
|
||||||
: action_(a) {
|
: action_(a) {
|
||||||
Init(formatter_, format.c_str());
|
Init(formatter_, format.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructs a temporary formatter from a proxy object.
|
||||||
|
*/
|
||||||
TempFormatter(const Proxy &p)
|
TempFormatter(const Proxy &p)
|
||||||
: ArgInserter(0), action_(p.action) {
|
: ArgInserter(0), action_(p.action) {
|
||||||
Init(formatter_, p.format);
|
Init(formatter_, p.format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Performs the actual formatting, invokes the action and destroys the object.
|
||||||
|
*/
|
||||||
~TempFormatter() {
|
~TempFormatter() {
|
||||||
if (formatter())
|
if (formatter())
|
||||||
action_(*Format());
|
action_(*Format());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Converts a temporary formatter into a proxy object.
|
||||||
|
*/
|
||||||
operator Proxy() {
|
operator Proxy() {
|
||||||
const char *fmt = format();
|
const char *fmt = format();
|
||||||
ResetFormatter();
|
ResetFormatter();
|
||||||
@ -831,7 +848,7 @@ class TempFormatter : public internal::ArgInserter {
|
|||||||
|
|
||||||
**Example**::
|
**Example**::
|
||||||
|
|
||||||
std::string message = str(Format("Elapsed time: {0:.2f} seconds") << 1.23);
|
std::string message = str(Format("The answer is {}") << 42);
|
||||||
|
|
||||||
See also `Format String Syntax`_.
|
See also `Format String Syntax`_.
|
||||||
\endrst
|
\endrst
|
||||||
|
Loading…
Reference in New Issue
Block a user