current_process_id.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 current_process_id.hpp
  9. * \author Andrey Semashev
  10. * \date 12.09.2009
  11. *
  12. * The header contains implementation of a current process id attribute
  13. */
  14. #ifndef BOOST_LOG_ATTRIBUTES_CURRENT_PROCESS_ID_HPP_INCLUDED_
  15. #define BOOST_LOG_ATTRIBUTES_CURRENT_PROCESS_ID_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/detail/process_id.hpp>
  18. #include <boost/log/attributes/constant.hpp>
  19. #include <boost/log/attributes/attribute_cast.hpp>
  20. #include <boost/log/detail/header.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. namespace boost {
  25. BOOST_LOG_OPEN_NAMESPACE
  26. //! Process identifier type used by the library
  27. typedef boost::log::aux::process::id process_id;
  28. namespace attributes {
  29. /*!
  30. * \brief A class of an attribute that holds the current process identifier
  31. */
  32. class current_process_id :
  33. public constant< process_id >
  34. {
  35. typedef constant< process_id > base_type;
  36. public:
  37. /*!
  38. * Constructor. Initializes the attribute with the current process identifier.
  39. */
  40. current_process_id() : base_type(boost::log::aux::this_process::get_id()) {}
  41. /*!
  42. * Constructor for casting support
  43. */
  44. explicit current_process_id(cast_source const& source) :
  45. base_type(source)
  46. {
  47. }
  48. };
  49. } // namespace attributes
  50. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  51. } // namespace boost
  52. #include <boost/log/detail/footer.hpp>
  53. #endif // BOOST_LOG_ATTRIBUTES_CURRENT_PROCESS_ID_HPP_INCLUDED_