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)
9 * \author Andrey Semashev
12 * The header contains wall clock attribute implementation and typedefs.
15 #ifndef BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
16 #define BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
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>
26 #ifdef BOOST_HAS_PRAGMA_ONCE
32 BOOST_LOG_OPEN_NAMESPACE
34 namespace attributes {
37 * \brief A class of an attribute that makes an attribute value of the current date and time
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.
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.
47 template< typename TimeTraitsT >
52 //! Generated value type
53 typedef typename TimeTraitsT::time_type value_type;
56 //! Attribute factory implementation
57 struct BOOST_SYMBOL_VISIBLE impl :
58 public attribute::impl
60 attribute_value get_value()
62 typedef attribute_value_impl< value_type > result_value;
63 return attribute_value(new result_value(TimeTraitsT::get_clock()));
71 basic_clock() : attribute(new impl())
75 * Constructor for casting support
77 explicit basic_clock(cast_source const& source) : attribute(source.as< impl >())
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;
87 } // namespace attributes
89 BOOST_LOG_CLOSE_NAMESPACE // namespace log
93 #include <boost/log/detail/footer.hpp>
95 #endif // BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_