Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:41

0001 //
0002 // detail/null_global.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_NULL_GLOBAL_HPP
0012 #define BOOST_ASIO_DETAIL_NULL_GLOBAL_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #include <boost/asio/detail/push_options.hpp>
0021 
0022 namespace boost {
0023 namespace asio {
0024 namespace detail {
0025 
0026 template <typename T>
0027 struct null_global_impl
0028 {
0029   null_global_impl()
0030     : ptr_(0)
0031   {
0032   }
0033 
0034   // Destructor automatically cleans up the global.
0035   ~null_global_impl()
0036   {
0037     delete ptr_;
0038   }
0039 
0040   static null_global_impl instance_;
0041   T* ptr_;
0042 };
0043 
0044 template <typename T>
0045 null_global_impl<T> null_global_impl<T>::instance_;
0046 
0047 template <typename T>
0048 T& null_global()
0049 {
0050   if (null_global_impl<T>::instance_.ptr_ == 0)
0051     null_global_impl<T>::instance_.ptr_ = new T;
0052   return *null_global_impl<T>::instance_.ptr_;
0053 }
0054 
0055 } // namespace detail
0056 } // namespace asio
0057 } // namespace boost
0058 
0059 #include <boost/asio/detail/pop_options.hpp>
0060 
0061 #endif // BOOST_ASIO_DETAIL_NULL_GLOBAL_HPP