Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file clock.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 01.12.2007
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains wall clock attribute implementation and typedefs.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/log/detail/config.hpp>
|
Chris@16
|
19 #include <boost/log/attributes/attribute.hpp>
|
Chris@16
|
20 #include <boost/log/attributes/attribute_value.hpp>
|
Chris@16
|
21 #include <boost/log/attributes/attribute_cast.hpp>
|
Chris@16
|
22 #include <boost/log/attributes/attribute_value_impl.hpp>
|
Chris@16
|
23 #include <boost/log/attributes/time_traits.hpp>
|
Chris@16
|
24 #include <boost/log/detail/header.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
27 #pragma once
|
Chris@16
|
28 #endif
|
Chris@16
|
29
|
Chris@16
|
30 namespace boost {
|
Chris@16
|
31
|
Chris@16
|
32 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
33
|
Chris@16
|
34 namespace attributes {
|
Chris@16
|
35
|
Chris@16
|
36 /*!
|
Chris@16
|
37 * \brief A class of an attribute that makes an attribute value of the current date and time
|
Chris@16
|
38 *
|
Chris@16
|
39 * The attribute generates current time stamp as a value. The type of the attribute value
|
Chris@16
|
40 * is determined with time traits passed to the class template as a template parameter.
|
Chris@16
|
41 * The time traits provided by the library use \c boost::posix_time::ptime as the time type.
|
Chris@16
|
42 *
|
Chris@16
|
43 * Time traits also determine the way time is acquired. There are two types of time traits
|
Chris@16
|
44 * provided by the library: \c utc_time_traits and \c local_time_traits. The first returns UTC time,
|
Chris@16
|
45 * the second returns local time.
|
Chris@16
|
46 */
|
Chris@16
|
47 template< typename TimeTraitsT >
|
Chris@16
|
48 class basic_clock :
|
Chris@16
|
49 public attribute
|
Chris@16
|
50 {
|
Chris@16
|
51 public:
|
Chris@16
|
52 //! Generated value type
|
Chris@16
|
53 typedef typename TimeTraitsT::time_type value_type;
|
Chris@16
|
54
|
Chris@16
|
55 protected:
|
Chris@16
|
56 //! Attribute factory implementation
|
Chris@16
|
57 struct BOOST_SYMBOL_VISIBLE impl :
|
Chris@16
|
58 public attribute::impl
|
Chris@16
|
59 {
|
Chris@16
|
60 attribute_value get_value()
|
Chris@16
|
61 {
|
Chris@16
|
62 typedef attribute_value_impl< value_type > result_value;
|
Chris@16
|
63 return attribute_value(new result_value(TimeTraitsT::get_clock()));
|
Chris@16
|
64 }
|
Chris@16
|
65 };
|
Chris@16
|
66
|
Chris@16
|
67 public:
|
Chris@16
|
68 /*!
|
Chris@16
|
69 * Default constructor
|
Chris@16
|
70 */
|
Chris@16
|
71 basic_clock() : attribute(new impl())
|
Chris@16
|
72 {
|
Chris@16
|
73 }
|
Chris@16
|
74 /*!
|
Chris@16
|
75 * Constructor for casting support
|
Chris@16
|
76 */
|
Chris@16
|
77 explicit basic_clock(cast_source const& source) : attribute(source.as< impl >())
|
Chris@16
|
78 {
|
Chris@16
|
79 }
|
Chris@16
|
80 };
|
Chris@16
|
81
|
Chris@16
|
82 //! Attribute that returns current UTC time
|
Chris@16
|
83 typedef basic_clock< utc_time_traits > utc_clock;
|
Chris@16
|
84 //! Attribute that returns current local time
|
Chris@16
|
85 typedef basic_clock< local_time_traits > local_clock;
|
Chris@16
|
86
|
Chris@16
|
87 } // namespace attributes
|
Chris@16
|
88
|
Chris@16
|
89 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
90
|
Chris@16
|
91 } // namespace boost
|
Chris@16
|
92
|
Chris@16
|
93 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
94
|
Chris@16
|
95 #endif // BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
|