123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- #ifndef BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP
- #define BOOST_CHRONO_IO_TIME_POINT_UNITS_HPP
- #include <boost/chrono/config.hpp>
- #include <boost/chrono/process_cpu_clocks.hpp>
- #include <boost/chrono/system_clocks.hpp>
- #include <boost/chrono/thread_clock.hpp>
- #include <boost/chrono/io/ios_base_state.hpp>
- #include <string>
- #include <iosfwd>
- #include <ios>
- #include <locale>
- #include <algorithm>
- namespace boost
- {
- namespace chrono
- {
-
- template <typename CharT, typename Clock, typename TPUFacet>
- std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f)
- {
- return f.do_get_epoch(Clock());
- }
-
- template <typename CharT=char>
- class time_point_units: public std::locale::facet
- {
- public:
-
- typedef CharT char_type;
-
- typedef std::basic_string<char_type> string_type;
-
- static std::locale::id id;
-
- explicit time_point_units(size_t refs = 0) :
- std::locale::facet(refs)
- {
- }
-
- virtual string_type get_pattern() const =0;
-
- template <typename Clock>
- string_type get_epoch() const
- {
- return get_epoch_custom<CharT>(Clock(), *this);
- }
- protected:
-
- virtual ~time_point_units() {}
- public:
-
- virtual string_type do_get_epoch(system_clock) const=0;
-
- virtual string_type do_get_epoch(steady_clock) const=0;
- #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
-
- virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
- #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
-
- virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
-
- virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
-
- virtual string_type do_get_epoch(process_cpu_clock) const=0;
- #endif
- #endif
- #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
-
- virtual string_type do_get_epoch(thread_clock) const=0;
- #endif
- };
- template <typename CharT>
- std::locale::id time_point_units<CharT>::id;
-
- template <typename CharT=char>
- class time_point_units_default: public time_point_units<CharT>
- {
- public:
-
- typedef CharT char_type;
-
- typedef std::basic_string<char_type> string_type;
- explicit time_point_units_default(size_t refs = 0) :
- time_point_units<CharT> (refs)
- {
- }
- ~time_point_units_default() {}
-
- string_type get_pattern() const
- {
- static const CharT t[] =
- { '%', 'd', '%', 'e' };
- static const string_type pattern(t, t + sizeof (t) / sizeof (t[0]));
- return pattern;
- }
-
-
- string_type do_get_epoch(system_clock ) const
- {
- return clock_string<system_clock,CharT>::since();
- }
-
- string_type do_get_epoch(steady_clock ) const
- {
- return clock_string<steady_clock,CharT>::since();
- }
- #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
-
- string_type do_get_epoch(process_real_cpu_clock ) const
- {
- return clock_string<process_real_cpu_clock,CharT>::since();
- }
- #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
-
- string_type do_get_epoch(process_user_cpu_clock ) const
- {
- return clock_string<process_user_cpu_clock,CharT>::since();
- }
-
- string_type do_get_epoch(process_system_cpu_clock ) const
- {
- return clock_string<process_system_cpu_clock,CharT>::since();
- }
-
- string_type do_get_epoch(process_cpu_clock ) const
- {
- return clock_string<process_cpu_clock,CharT>::since();
- }
- #endif
- #endif
- #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
-
- string_type do_get_epoch(thread_clock ) const
- {
- return clock_string<thread_clock,CharT>::since();
- }
- #endif
- };
- }
- }
- #endif
|