Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file clock.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 01.12.2007 Chris@16: * Chris@16: * The header contains wall clock attribute implementation and typedefs. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace attributes { Chris@16: Chris@16: /*! Chris@16: * \brief A class of an attribute that makes an attribute value of the current date and time Chris@16: * Chris@16: * The attribute generates current time stamp as a value. The type of the attribute value Chris@16: * is determined with time traits passed to the class template as a template parameter. Chris@16: * The time traits provided by the library use \c boost::posix_time::ptime as the time type. Chris@16: * Chris@16: * Time traits also determine the way time is acquired. There are two types of time traits Chris@16: * provided by the library: \c utc_time_traits and \c local_time_traits. The first returns UTC time, Chris@16: * the second returns local time. Chris@16: */ Chris@16: template< typename TimeTraitsT > Chris@16: class basic_clock : Chris@16: public attribute Chris@16: { Chris@16: public: Chris@16: //! Generated value type Chris@16: typedef typename TimeTraitsT::time_type value_type; Chris@16: Chris@16: protected: Chris@16: //! Attribute factory implementation Chris@16: struct BOOST_SYMBOL_VISIBLE impl : Chris@16: public attribute::impl Chris@16: { Chris@16: attribute_value get_value() Chris@16: { Chris@16: typedef attribute_value_impl< value_type > result_value; Chris@16: return attribute_value(new result_value(TimeTraitsT::get_clock())); Chris@16: } Chris@16: }; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Default constructor Chris@16: */ Chris@16: basic_clock() : attribute(new impl()) Chris@16: { Chris@16: } Chris@16: /*! Chris@16: * Constructor for casting support Chris@16: */ Chris@16: explicit basic_clock(cast_source const& source) : attribute(source.as< impl >()) Chris@16: { Chris@16: } Chris@16: }; Chris@16: Chris@16: //! Attribute that returns current UTC time Chris@16: typedef basic_clock< utc_time_traits > utc_clock; Chris@16: //! Attribute that returns current local time Chris@16: typedef basic_clock< local_time_traits > local_clock; Chris@16: Chris@16: } // namespace attributes Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_