Flow 1.0.1
Flow project: Full implementation reference.
|
Internally used class that enables some of the activities of beautify_chrono_ostream() API. More...
Public Member Functions | |
boost::chrono::duration_units< char_type >::string_type | do_get_ratio_prefix (boost::chrono::duration_style style, boost::micro period_tag) const override |
Returns the prefix string for micro-units; namely the default thing for long-form format ("micro") but the non-default "u" for the short-form. More... | |
Static Public Member Functions | |
static const std::locale & | beautified_locale () |
Returns a reference to a locale that – if imbued onto an ostream – equals std::locale::classic except beautified by a Duration_units_beautified facet (as described in the class doc header). More... | |
Private Types | |
using | Duration_units_default = boost::chrono::duration_units_default< char > |
Short-hand for superclass. More... | |
Private Member Functions | |
Duration_units_beautified () | |
Constructs. More... | |
Static Private Attributes | |
static std::locale const * | s_beautified_locale_or_null |
Pointer returned by beautified_locale(), pointing to an object allocated exactly once; or null if that has not yet been called. More... | |
static boost::once_flag | s_beautified_locale_init_flag |
Helper to initialize s_beautified_locale_or_null at most once. More... | |
Internally used class that enables some of the activities of beautify_chrono_ostream() API.
It's a locale facet, whose virtual
API can be used to imbue onto an ostream
; but even within our own internal code the only public API used is beautified_locale(), which returns a reference to a ready-made such std::locale
.
This facet enables the default chrono
output behavior, except the "micro" short-form prefix is just "u" instead of the default Unicode Greek letter mu.
How it does this is fairly self-explanatory, but finding out how to do it was annoyingly tricky due to the inconsistent/outdated boost.chrono docs which only partially explain boost.chrono I/O v2. Ultimately I had to find the actual example french.cpp
(not its outdated v1 version directly inside the main doc text, in Boost 1.76); then cross-reference it with the Reference section that described the duration_units_default
class.
|
explicitprivate |
|
static |
Returns a reference to a locale that – if imbued onto an ostream
– equals std::locale::classic
except beautified by a Duration_units_beautified facet (as described in the class doc header).
This (static
) method is safe to call concurrently with itself. Internally it achieves this possibly by using a simple mutex. Since it is not expected one would call this frequently, let alone frequently enough for any contention to occur, we consider this acceptable.
Definition at line 116 of file util.cpp.
References s_beautified_locale_init_flag, and s_beautified_locale_or_null.
Referenced by flow::util::beautify_chrono_ostream().
|
override |
Returns the prefix string for micro-units; namely the default thing for long-form format ("micro") but the non-default "u" for the short-form.
Hence microseconds are either "microsecond[s]" or "us."
This is public
only so as to work as a virtual
facet interface element invoked by STL ostream
machinery upon imbuing *this
onto a locale
. Since Duration_units_beautified is not exposed as a flow::util public API, leaving this method public
(to our internal code in this .cpp file only) is acceptable.
style | Either name_format or symbol_format (the latter being the short-form choice). |
period_tag | Tag indicating this method is for the micro prefix. |
|
staticprivate |
Helper to initialize s_beautified_locale_or_null at most once.
Definition at line 98 of file util.cpp.
Referenced by beautified_locale().
|
staticprivate |
Pointer returned by beautified_locale(), pointing to an object allocated exactly once; or null if that has not yet been called.
The allocated object lives until the process exits.
Definition at line 95 of file util.cpp.
Referenced by beautified_locale().