annotate DEPENDENCIES/generic/include/boost/chrono/io/time_point_units.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // (C) Copyright Howard Hinnant
Chris@16 2 // (C) Copyright 2011 Vicente J. Botet Escriba
Chris@101 3 // Copyright (c) Microsoft Corporation 2014
Chris@16 4 // Use, modification and distribution are subject to the Boost Software License,
Chris@16 5 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 // http://www.boost.org/LICENSE_1_0.txt).
Chris@16 7 //
Chris@16 8
Chris@16 9 #ifndef BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP
Chris@16 10 #define BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP
Chris@16 11
Chris@16 12 #include <boost/chrono/config.hpp>
Chris@16 13 #include <boost/chrono/process_cpu_clocks.hpp>
Chris@16 14 #include <boost/chrono/system_clocks.hpp>
Chris@16 15 #include <boost/chrono/thread_clock.hpp>
Chris@16 16 #include <boost/chrono/io/ios_base_state.hpp>
Chris@16 17 #include <string>
Chris@16 18 #include <iostream>
Chris@16 19 #include <ios>
Chris@16 20 #include <locale>
Chris@16 21 #include <algorithm>
Chris@16 22
Chris@16 23 namespace boost
Chris@16 24 {
Chris@16 25 namespace chrono
Chris@16 26 {
Chris@16 27
Chris@16 28 /**
Chris@16 29 * @c time_point_units facet gives useful information about the time_point pattern,
Chris@16 30 * the text associated to a time_point's epoch,
Chris@16 31 */
Chris@16 32 template <typename CharT=char>
Chris@16 33 class time_point_units: public std::locale::facet
Chris@16 34 {
Chris@16 35 public:
Chris@16 36 /**
Chris@16 37 * Type of character the facet is instantiated on.
Chris@16 38 */
Chris@16 39 typedef CharT char_type;
Chris@16 40 /**
Chris@16 41 * Type of character string used by member functions.
Chris@16 42 */
Chris@16 43 typedef std::basic_string<char_type> string_type;
Chris@16 44
Chris@16 45 /**
Chris@16 46 * Unique identifier for this type of facet.
Chris@16 47 */
Chris@16 48 static std::locale::id id;
Chris@16 49
Chris@16 50 /**
Chris@16 51 * Construct a @c time_point_units facet.
Chris@16 52 * @param refs
Chris@16 53 * @Effects Construct a @c time_point_units facet.
Chris@16 54 * If the @c refs argument is @c 0 then destruction of the object is
Chris@16 55 * delegated to the @c locale, or locales, containing it. This allows
Chris@16 56 * the user to ignore lifetime management issues. On the other had,
Chris@16 57 * if @c refs is @c 1 then the object must be explicitly deleted;
Chris@16 58 * the @c locale will not do so. In this case, the object can be
Chris@16 59 * maintained across the lifetime of multiple locales.
Chris@16 60 */
Chris@16 61 explicit time_point_units(size_t refs = 0) :
Chris@16 62 std::locale::facet(refs)
Chris@16 63 {
Chris@16 64 }
Chris@16 65
Chris@16 66 /**
Chris@16 67 * @return the pattern to be used by default.
Chris@16 68 */
Chris@16 69 virtual string_type get_pattern() const =0;
Chris@16 70
Chris@16 71 /**
Chris@16 72 * @return the epoch associated to the clock @c Clock calling @c do_get_epoch(Clock())
Chris@16 73 */
Chris@16 74 template <typename Clock>
Chris@16 75 string_type get_epoch() const
Chris@16 76 {
Chris@16 77 return do_get_epoch(Clock());
Chris@16 78 }
Chris@16 79
Chris@16 80 protected:
Chris@16 81 /**
Chris@16 82 * Destroy the facet.
Chris@16 83 */
Chris@16 84 virtual ~time_point_units() {}
Chris@16 85
Chris@16 86
Chris@16 87 /**
Chris@16 88 *
Chris@16 89 * @param c a dummy instance of @c system_clock.
Chris@16 90 * @return The epoch string associated to the @c system_clock.
Chris@16 91 */
Chris@16 92 virtual string_type do_get_epoch(system_clock) const=0;
Chris@16 93
Chris@16 94 /**
Chris@16 95 *
Chris@16 96 * @param c a dummy instance of @c steady_clock.
Chris@16 97 * @return The epoch string associated to the @c steady_clock.
Chris@16 98 */
Chris@16 99 virtual string_type do_get_epoch(steady_clock) const=0;
Chris@16 100
Chris@16 101 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
Chris@16 102 /**
Chris@16 103 *
Chris@16 104 * @param c a dummy instance of @c process_real_cpu_clock.
Chris@16 105 * @return The epoch string associated to the @c process_real_cpu_clock.
Chris@16 106 */
Chris@16 107 virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
Chris@101 108 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
Chris@16 109 /**
Chris@16 110 *
Chris@16 111 * @param c a dummy instance of @c process_user_cpu_clock.
Chris@16 112 * @return The epoch string associated to the @c process_user_cpu_clock.
Chris@16 113 */
Chris@16 114 virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
Chris@16 115 /**
Chris@16 116 *
Chris@16 117 * @param c a dummy instance of @c process_system_cpu_clock.
Chris@16 118 * @return The epoch string associated to the @c process_system_cpu_clock.
Chris@16 119 */
Chris@16 120 virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
Chris@16 121 /**
Chris@16 122 *
Chris@16 123 * @param c a dummy instance of @c process_cpu_clock.
Chris@16 124 * @return The epoch string associated to the @c process_cpu_clock.
Chris@16 125 */
Chris@16 126 virtual string_type do_get_epoch(process_cpu_clock) const=0;
Chris@16 127 #endif
Chris@101 128 #endif
Chris@16 129 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
Chris@16 130 /**
Chris@16 131 *
Chris@16 132 * @param c a dummy instance of @c thread_clock.
Chris@16 133 * @return The epoch string associated to the @c thread_clock.
Chris@16 134 */
Chris@16 135 virtual string_type do_get_epoch(thread_clock) const=0;
Chris@16 136 #endif
Chris@16 137
Chris@16 138 };
Chris@16 139
Chris@16 140 template <typename CharT>
Chris@16 141 std::locale::id time_point_units<CharT>::id;
Chris@16 142
Chris@16 143
Chris@16 144 // This class is used to define the strings for the default English
Chris@16 145 template <typename CharT=char>
Chris@16 146 class time_point_units_default: public time_point_units<CharT>
Chris@16 147 {
Chris@16 148 public:
Chris@16 149 /**
Chris@16 150 * Type of character the facet is instantiated on.
Chris@16 151 */
Chris@16 152 typedef CharT char_type;
Chris@16 153 /**
Chris@16 154 * Type of character string returned by member functions.
Chris@16 155 */
Chris@16 156 typedef std::basic_string<char_type> string_type;
Chris@16 157
Chris@16 158 explicit time_point_units_default(size_t refs = 0) :
Chris@16 159 time_point_units<CharT> (refs)
Chris@16 160 {
Chris@16 161 }
Chris@16 162 ~time_point_units_default() {}
Chris@16 163
Chris@16 164 /**
Chris@16 165 * @return the default pattern "%d%e".
Chris@16 166 */
Chris@16 167 string_type get_pattern() const
Chris@16 168 {
Chris@16 169 static const CharT t[] =
Chris@16 170 { '%', 'd', '%', 'e' };
Chris@16 171 static const string_type pattern(t, t + sizeof (t) / sizeof (t[0]));
Chris@16 172
Chris@16 173 return pattern;
Chris@16 174 }
Chris@16 175
Chris@16 176 protected:
Chris@16 177 /**
Chris@16 178 * @param c a dummy instance of @c system_clock.
Chris@16 179 * @return The epoch string returned by @c clock_string<system_clock,CharT>::since().
Chris@16 180 */
Chris@16 181 string_type do_get_epoch(system_clock ) const
Chris@16 182 {
Chris@16 183 return clock_string<system_clock,CharT>::since();
Chris@16 184 }
Chris@16 185 /**
Chris@16 186 * @param c a dummy instance of @c steady_clock.
Chris@16 187 * @return The epoch string returned by @c clock_string<steady_clock,CharT>::since().
Chris@16 188 */
Chris@16 189 string_type do_get_epoch(steady_clock ) const
Chris@16 190 {
Chris@16 191 return clock_string<steady_clock,CharT>::since();
Chris@16 192 }
Chris@16 193
Chris@16 194 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
Chris@16 195 /**
Chris@16 196 * @param c a dummy instance of @c process_real_cpu_clock.
Chris@16 197 * @return The epoch string returned by @c clock_string<process_real_cpu_clock,CharT>::since().
Chris@16 198 */
Chris@16 199 string_type do_get_epoch(process_real_cpu_clock ) const
Chris@16 200 {
Chris@16 201 return clock_string<process_real_cpu_clock,CharT>::since();
Chris@16 202 }
Chris@101 203 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
Chris@16 204 /**
Chris@16 205 * @param c a dummy instance of @c process_user_cpu_clock.
Chris@16 206 * @return The epoch string returned by @c clock_string<process_user_cpu_clock,CharT>::since().
Chris@16 207 */
Chris@16 208 string_type do_get_epoch(process_user_cpu_clock ) const
Chris@16 209 {
Chris@16 210 return clock_string<process_user_cpu_clock,CharT>::since();
Chris@16 211 }
Chris@16 212 /**
Chris@16 213 * @param c a dummy instance of @c process_system_cpu_clock.
Chris@16 214 * @return The epoch string returned by @c clock_string<process_system_cpu_clock,CharT>::since().
Chris@16 215 */
Chris@16 216 string_type do_get_epoch(process_system_cpu_clock ) const
Chris@16 217 {
Chris@16 218 return clock_string<process_system_cpu_clock,CharT>::since();
Chris@16 219 }
Chris@16 220 /**
Chris@16 221 * @param c a dummy instance of @c process_cpu_clock.
Chris@16 222 * @return The epoch string returned by @c clock_string<process_cpu_clock,CharT>::since().
Chris@16 223 */
Chris@16 224 string_type do_get_epoch(process_cpu_clock ) const
Chris@16 225 {
Chris@16 226 return clock_string<process_cpu_clock,CharT>::since();
Chris@16 227 }
Chris@16 228
Chris@16 229 #endif
Chris@101 230 #endif
Chris@16 231 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
Chris@16 232 /**
Chris@16 233 * @param c a dummy instance of @c thread_clock.
Chris@16 234 * @return The epoch string returned by @c clock_string<thread_clock,CharT>::since().
Chris@16 235 */
Chris@16 236 string_type do_get_epoch(thread_clock ) const
Chris@16 237 {
Chris@16 238 return clock_string<thread_clock,CharT>::since();
Chris@16 239 }
Chris@16 240 #endif
Chris@16 241
Chris@16 242 };
Chris@16 243
Chris@16 244
Chris@16 245 } // chrono
Chris@16 246
Chris@16 247 } // boost
Chris@16 248
Chris@16 249 #endif // header