Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:18

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   clock.hpp
0009  * \author Andrey Semashev
0010  * \date   01.12.2007
0011  *
0012  * The header contains wall clock attribute implementation and typedefs.
0013  */
0014 
0015 #ifndef BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
0016 #define BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_
0017 
0018 #include <boost/log/detail/config.hpp>
0019 #include <boost/log/attributes/attribute.hpp>
0020 #include <boost/log/attributes/attribute_value.hpp>
0021 #include <boost/log/attributes/attribute_cast.hpp>
0022 #include <boost/log/attributes/attribute_value_impl.hpp>
0023 #include <boost/log/attributes/time_traits.hpp>
0024 #include <boost/log/detail/header.hpp>
0025 
0026 #ifdef BOOST_HAS_PRAGMA_ONCE
0027 #pragma once
0028 #endif
0029 
0030 namespace boost {
0031 
0032 BOOST_LOG_OPEN_NAMESPACE
0033 
0034 namespace attributes {
0035 
0036 /*!
0037  * \brief A class of an attribute that makes an attribute value of the current date and time
0038  *
0039  * The attribute generates current time stamp as a value. The type of the attribute value
0040  * is determined with time traits passed to the class template as a template parameter.
0041  * The time traits provided by the library use \c boost::posix_time::ptime as the time type.
0042  *
0043  * Time traits also determine the way time is acquired. There are two types of time traits
0044  * provided by the library: \c utc_time_traits and \c local_time_traits. The first returns UTC time,
0045  * the second returns local time.
0046  */
0047 template< typename TimeTraitsT >
0048 class basic_clock :
0049     public attribute
0050 {
0051 public:
0052     //! Generated value type
0053     typedef typename TimeTraitsT::time_type value_type;
0054 
0055 protected:
0056     //! Attribute factory implementation
0057     struct BOOST_SYMBOL_VISIBLE impl :
0058         public attribute::impl
0059     {
0060         attribute_value get_value()
0061         {
0062             typedef attribute_value_impl< value_type > result_value;
0063             return attribute_value(new result_value(TimeTraitsT::get_clock()));
0064         }
0065     };
0066 
0067 public:
0068     /*!
0069      * Default constructor
0070      */
0071     basic_clock() : attribute(new impl())
0072     {
0073     }
0074     /*!
0075      * Constructor for casting support
0076      */
0077     explicit basic_clock(cast_source const& source) : attribute(source.as< impl >())
0078     {
0079     }
0080 };
0081 
0082 //! Attribute that returns current UTC time
0083 typedef basic_clock< utc_time_traits > utc_clock;
0084 //! Attribute that returns current local time
0085 typedef basic_clock< local_time_traits > local_clock;
0086 
0087 } // namespace attributes
0088 
0089 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0090 
0091 } // namespace boost
0092 
0093 #include <boost/log/detail/footer.hpp>
0094 
0095 #endif // BOOST_LOG_ATTRIBUTES_CLOCK_HPP_INCLUDED_