Flow 1.0.1
Flow project: Full implementation reference.
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Attributes | List of all members
flow::util::Duration_units_beautified Class Reference

Internally used class that enables some of the activities of beautify_chrono_ostream() API. More...

Inheritance diagram for flow::util::Duration_units_beautified:
[legend]
Collaboration diagram for flow::util::Duration_units_beautified:
[legend]

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...
 

Detailed Description

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.

Implementation notes

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.

Definition at line 41 of file util.cpp.

Member Typedef Documentation

◆ Duration_units_default

Short-hand for superclass.

Definition at line 82 of file util.cpp.

Constructor & Destructor Documentation

◆ Duration_units_beautified()

flow::util::Duration_units_beautified::Duration_units_beautified ( )
explicitprivate

Constructs.

Definition at line 110 of file util.cpp.

Member Function Documentation

◆ beautified_locale()

const std::locale & flow::util::Duration_units_beautified::beautified_locale ( )
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).

Thread safety and perf

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.

Returns
See above.

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().

Here is the caller graph for this function:

◆ do_get_ratio_prefix()

boost::chrono::duration_units< char >::string_type flow::util::Duration_units_beautified::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.

Hence microseconds are either "microsecond[s]" or "us."

Rationale

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.

Parameters
styleEither name_format or symbol_format (the latter being the short-form choice).
period_tagTag indicating this method is for the micro prefix.
Returns
The prefix string.

Definition at line 129 of file util.cpp.

Member Data Documentation

◆ s_beautified_locale_init_flag

boost::once_flag flow::util::Duration_units_beautified::s_beautified_locale_init_flag
staticprivate

Helper to initialize s_beautified_locale_or_null at most once.

Definition at line 98 of file util.cpp.

Referenced by beautified_locale().

◆ s_beautified_locale_or_null

std::locale const * flow::util::Duration_units_beautified::s_beautified_locale_or_null
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().


The documentation for this class was generated from the following file: