Chris@16: // (C) Copyright Howard Hinnant Chris@16: // (C) Copyright 2011 Vicente J. Botet Escriba Chris@101: // Copyright (c) Microsoft Corporation 2014 Chris@16: // Use, modification and distribution are subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt). Chris@16: // Chris@16: Chris@16: #ifndef BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP Chris@16: #define BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace chrono Chris@16: { Chris@16: Chris@16: /** Chris@16: * @c time_point_units facet gives useful information about the time_point pattern, Chris@16: * the text associated to a time_point's epoch, Chris@16: */ Chris@16: template Chris@16: class time_point_units: public std::locale::facet Chris@16: { Chris@16: public: Chris@16: /** Chris@16: * Type of character the facet is instantiated on. Chris@16: */ Chris@16: typedef CharT char_type; Chris@16: /** Chris@16: * Type of character string used by member functions. Chris@16: */ Chris@16: typedef std::basic_string string_type; Chris@16: Chris@16: /** Chris@16: * Unique identifier for this type of facet. Chris@16: */ Chris@16: static std::locale::id id; Chris@16: Chris@16: /** Chris@16: * Construct a @c time_point_units facet. Chris@16: * @param refs Chris@16: * @Effects Construct a @c time_point_units facet. Chris@16: * If the @c refs argument is @c 0 then destruction of the object is Chris@16: * delegated to the @c locale, or locales, containing it. This allows Chris@16: * the user to ignore lifetime management issues. On the other had, Chris@16: * if @c refs is @c 1 then the object must be explicitly deleted; Chris@16: * the @c locale will not do so. In this case, the object can be Chris@16: * maintained across the lifetime of multiple locales. Chris@16: */ Chris@16: explicit time_point_units(size_t refs = 0) : Chris@16: std::locale::facet(refs) Chris@16: { Chris@16: } Chris@16: Chris@16: /** Chris@16: * @return the pattern to be used by default. Chris@16: */ Chris@16: virtual string_type get_pattern() const =0; Chris@16: Chris@16: /** Chris@16: * @return the epoch associated to the clock @c Clock calling @c do_get_epoch(Clock()) Chris@16: */ Chris@16: template Chris@16: string_type get_epoch() const Chris@16: { Chris@16: return do_get_epoch(Clock()); Chris@16: } Chris@16: Chris@16: protected: Chris@16: /** Chris@16: * Destroy the facet. Chris@16: */ Chris@16: virtual ~time_point_units() {} Chris@16: Chris@16: Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c system_clock. Chris@16: * @return The epoch string associated to the @c system_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(system_clock) const=0; Chris@16: Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c steady_clock. Chris@16: * @return The epoch string associated to the @c steady_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(steady_clock) const=0; Chris@16: Chris@16: #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c process_real_cpu_clock. Chris@16: * @return The epoch string associated to the @c process_real_cpu_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(process_real_cpu_clock) const=0; Chris@101: #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c process_user_cpu_clock. Chris@16: * @return The epoch string associated to the @c process_user_cpu_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(process_user_cpu_clock) const=0; Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c process_system_cpu_clock. Chris@16: * @return The epoch string associated to the @c process_system_cpu_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(process_system_cpu_clock) const=0; Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c process_cpu_clock. Chris@16: * @return The epoch string associated to the @c process_cpu_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(process_cpu_clock) const=0; Chris@16: #endif Chris@101: #endif Chris@16: #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) Chris@16: /** Chris@16: * Chris@16: * @param c a dummy instance of @c thread_clock. Chris@16: * @return The epoch string associated to the @c thread_clock. Chris@16: */ Chris@16: virtual string_type do_get_epoch(thread_clock) const=0; Chris@16: #endif Chris@16: Chris@16: }; Chris@16: Chris@16: template Chris@16: std::locale::id time_point_units::id; Chris@16: Chris@16: Chris@16: // This class is used to define the strings for the default English Chris@16: template Chris@16: class time_point_units_default: public time_point_units Chris@16: { Chris@16: public: Chris@16: /** Chris@16: * Type of character the facet is instantiated on. Chris@16: */ Chris@16: typedef CharT char_type; Chris@16: /** Chris@16: * Type of character string returned by member functions. Chris@16: */ Chris@16: typedef std::basic_string string_type; Chris@16: Chris@16: explicit time_point_units_default(size_t refs = 0) : Chris@16: time_point_units (refs) Chris@16: { Chris@16: } Chris@16: ~time_point_units_default() {} Chris@16: Chris@16: /** Chris@16: * @return the default pattern "%d%e". Chris@16: */ Chris@16: string_type get_pattern() const Chris@16: { Chris@16: static const CharT t[] = Chris@16: { '%', 'd', '%', 'e' }; Chris@16: static const string_type pattern(t, t + sizeof (t) / sizeof (t[0])); Chris@16: Chris@16: return pattern; Chris@16: } Chris@16: Chris@16: protected: Chris@16: /** Chris@16: * @param c a dummy instance of @c system_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(system_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@16: /** Chris@16: * @param c a dummy instance of @c steady_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(steady_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@16: Chris@16: #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) Chris@16: /** Chris@16: * @param c a dummy instance of @c process_real_cpu_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(process_real_cpu_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@101: #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP Chris@16: /** Chris@16: * @param c a dummy instance of @c process_user_cpu_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(process_user_cpu_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@16: /** Chris@16: * @param c a dummy instance of @c process_system_cpu_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(process_system_cpu_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@16: /** Chris@16: * @param c a dummy instance of @c process_cpu_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(process_cpu_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@16: Chris@16: #endif Chris@101: #endif Chris@16: #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) Chris@16: /** Chris@16: * @param c a dummy instance of @c thread_clock. Chris@16: * @return The epoch string returned by @c clock_string::since(). Chris@16: */ Chris@16: string_type do_get_epoch(thread_clock ) const Chris@16: { Chris@16: return clock_string::since(); Chris@16: } Chris@16: #endif Chris@16: Chris@16: }; Chris@16: Chris@16: Chris@16: } // chrono Chris@16: Chris@16: } // boost Chris@16: Chris@16: #endif // header