2 * Copyright Lingxi Li 2015.
3 * Copyright Andrey Semashev 2015.
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
9 * \file permissions.hpp
11 * \author Andrey Semashev
14 * The header contains an abstraction wrapper for security permissions.
17 #ifndef BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
18 #define BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/header.hpp>
23 #ifdef BOOST_HAS_PRAGMA_ONCE
29 struct _SECURITY_ATTRIBUTES;
31 #endif // BOOST_WINDOWS
38 struct BOOST_LOG_MAY_ALIAS _SECURITY_ATTRIBUTES;
43 namespace interprocess {
45 } // namespace interprocess
47 BOOST_LOG_OPEN_NAMESPACE
50 * \brief Access permissions wrapper.
52 * On Windows platforms, it represents a pointer to \c SECURITY_ATTRIBUTES. The user is responsible
53 * for allocating and reclaiming resources associated with the pointer, \c permissions instance does
56 * On POSIX platforms, it represents a \c mode_t value.
61 #if defined(BOOST_LOG_DOXYGEN_PASS)
62 //! The type of security permissions, specific to the operating system
63 typedef implementation_defined native_type;
64 #elif defined(BOOST_WINDOWS)
65 typedef ::_SECURITY_ATTRIBUTES* native_type;
67 // Equivalent to POSIX mode_t
68 typedef unsigned int native_type;
71 #if !defined(BOOST_LOG_DOXYGEN_PASS)
78 * Default constructor. The method constructs an object that represents
79 * a null \c SECURITY_ATTRIBUTES pointer on Windows platforms, and a
80 * \c mode_t value \c 0644 on POSIX platforms.
82 permissions() BOOST_NOEXCEPT
90 permissions(permissions const& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
97 permissions& operator=(permissions const& that) BOOST_NOEXCEPT
99 m_perms = that.m_perms;
104 * Initializing constructor.
106 permissions(native_type perms) BOOST_NOEXCEPT : m_perms(perms)
111 permissions(boost::detail::winapi::_SECURITY_ATTRIBUTES* perms) BOOST_NOEXCEPT : m_perms(reinterpret_cast< native_type >(perms))
117 * Initializing constructor.
119 BOOST_LOG_API permissions(boost::interprocess::permissions const& perms) BOOST_NOEXCEPT;
121 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
125 permissions(permissions&& that) BOOST_NOEXCEPT : m_perms(that.m_perms)
133 permissions& operator=(permissions&& that) BOOST_NOEXCEPT
135 m_perms = that.m_perms;
142 * Sets permissions from the OS-specific permissions.
144 void set_native(native_type perms) BOOST_NOEXCEPT
150 * Returns the underlying OS-specific permissions.
152 native_type get_native() const BOOST_NOEXCEPT
158 * Sets the default permissions, which are equivalent to \c NULL \c SECURITY_ATTRIBUTES
159 * on Windows and \c 0644 on POSIX platforms.
161 void set_default() BOOST_NOEXCEPT
163 #if defined(BOOST_WINDOWS)
171 * Sets unrestricted permissions, which are equivalent to \c SECURITY_ATTRIBUTES with \c NULL DACL
172 * on Windows and \c 0666 on POSIX platforms.
174 void set_unrestricted()
176 #if defined(BOOST_WINDOWS)
177 m_perms = get_unrestricted_security_attributes();
184 * The method swaps the object with \a that.
186 * \param that The other object to swap with.
188 void swap(permissions& that) BOOST_NOEXCEPT
190 native_type perms = m_perms;
191 m_perms = that.m_perms;
192 that.m_perms = perms;
195 //! Swaps the two \c permissions objects.
196 friend void swap(permissions& a, permissions& b) BOOST_NOEXCEPT
201 #if !defined(BOOST_LOG_DOXYGEN_PASS) && defined(BOOST_WINDOWS)
203 static BOOST_LOG_API native_type get_unrestricted_security_attributes();
207 BOOST_LOG_CLOSE_NAMESPACE // namespace log
211 #include <boost/log/detail/footer.hpp>
213 #endif // BOOST_LOG_UTILITY_PERMISSIONS_HPP_INCLUDED_