File indexing completed on 2025-01-18 09:29:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP
0010 #define BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP
0011
0012 #include <boost/chrono/config.hpp>
0013 #include <boost/chrono/process_cpu_clocks.hpp>
0014 #include <boost/chrono/system_clocks.hpp>
0015 #include <boost/chrono/thread_clock.hpp>
0016 #include <boost/chrono/io/ios_base_state.hpp>
0017 #include <string>
0018 #include <iosfwd>
0019 #include <ios>
0020 #include <locale>
0021 #include <algorithm>
0022
0023 namespace boost
0024 {
0025 namespace chrono
0026 {
0027
0028
0029
0030
0031
0032 template <typename CharT, typename Clock, typename TPUFacet>
0033 std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f)
0034 {
0035 return f.do_get_epoch(Clock());
0036 }
0037
0038
0039
0040
0041
0042 template <typename CharT=char>
0043 class time_point_units: public std::locale::facet
0044 {
0045 public:
0046
0047
0048
0049 typedef CharT char_type;
0050
0051
0052
0053 typedef std::basic_string<char_type> string_type;
0054
0055
0056
0057
0058 static std::locale::id id;
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 explicit time_point_units(size_t refs = 0) :
0072 std::locale::facet(refs)
0073 {
0074 }
0075
0076
0077
0078
0079 virtual string_type get_pattern() const =0;
0080
0081
0082
0083
0084 template <typename Clock>
0085 string_type get_epoch() const
0086 {
0087 return get_epoch_custom<CharT>(Clock(), *this);
0088 }
0089
0090 protected:
0091
0092
0093
0094 virtual ~time_point_units() {}
0095
0096 public:
0097
0098
0099
0100
0101
0102
0103 virtual string_type do_get_epoch(system_clock) const=0;
0104
0105
0106
0107
0108
0109
0110 virtual string_type do_get_epoch(steady_clock) const=0;
0111
0112 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
0113
0114
0115
0116
0117
0118 virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
0119 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
0120
0121
0122
0123
0124
0125 virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
0126
0127
0128
0129
0130
0131 virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
0132
0133
0134
0135
0136
0137 virtual string_type do_get_epoch(process_cpu_clock) const=0;
0138 #endif
0139 #endif
0140 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
0141
0142
0143
0144
0145
0146 virtual string_type do_get_epoch(thread_clock) const=0;
0147 #endif
0148
0149 };
0150
0151 template <typename CharT>
0152 std::locale::id time_point_units<CharT>::id;
0153
0154
0155
0156 template <typename CharT=char>
0157 class time_point_units_default: public time_point_units<CharT>
0158 {
0159 public:
0160
0161
0162
0163 typedef CharT char_type;
0164
0165
0166
0167 typedef std::basic_string<char_type> string_type;
0168
0169 explicit time_point_units_default(size_t refs = 0) :
0170 time_point_units<CharT> (refs)
0171 {
0172 }
0173 ~time_point_units_default() {}
0174
0175
0176
0177
0178 string_type get_pattern() const
0179 {
0180 static const CharT t[] =
0181 { '%', 'd', '%', 'e' };
0182 static const string_type pattern(t, t + sizeof (t) / sizeof (t[0]));
0183
0184 return pattern;
0185 }
0186
0187
0188
0189
0190
0191
0192 string_type do_get_epoch(system_clock ) const
0193 {
0194 return clock_string<system_clock,CharT>::since();
0195 }
0196
0197
0198
0199
0200 string_type do_get_epoch(steady_clock ) const
0201 {
0202 return clock_string<steady_clock,CharT>::since();
0203 }
0204
0205 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
0206
0207
0208
0209
0210 string_type do_get_epoch(process_real_cpu_clock ) const
0211 {
0212 return clock_string<process_real_cpu_clock,CharT>::since();
0213 }
0214 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
0215
0216
0217
0218
0219 string_type do_get_epoch(process_user_cpu_clock ) const
0220 {
0221 return clock_string<process_user_cpu_clock,CharT>::since();
0222 }
0223
0224
0225
0226
0227 string_type do_get_epoch(process_system_cpu_clock ) const
0228 {
0229 return clock_string<process_system_cpu_clock,CharT>::since();
0230 }
0231
0232
0233
0234
0235 string_type do_get_epoch(process_cpu_clock ) const
0236 {
0237 return clock_string<process_cpu_clock,CharT>::since();
0238 }
0239
0240 #endif
0241 #endif
0242 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
0243
0244
0245
0246
0247 string_type do_get_epoch(thread_clock ) const
0248 {
0249 return clock_string<thread_clock,CharT>::since();
0250 }
0251 #endif
0252
0253 };
0254
0255
0256 }
0257
0258 }
0259
0260 #endif