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