Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:14

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/container for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_CONTAINER_PMR_MEMORY_RESOURCE_HPP
0012 #define BOOST_CONTAINER_PMR_MEMORY_RESOURCE_HPP
0013 
0014 #if defined (_MSC_VER)
0015 #  pragma once 
0016 #endif
0017 
0018 #include <boost/container/detail/config_begin.hpp>
0019 #include <boost/container/detail/workaround.hpp>
0020 #include <boost/container/container_fwd.hpp>
0021 #include <boost/move/detail/type_traits.hpp>
0022 #include <boost/container/detail/placement_new.hpp>
0023 #include <cstddef>
0024 
0025 namespace boost {
0026 namespace container {
0027 namespace pmr {
0028 
0029 //! The memory_resource class is an abstract interface to an
0030 //! unbounded set of classes encapsulating memory resources.
0031 class memory_resource
0032 {
0033    public:
0034    // For exposition only
0035    static BOOST_CONSTEXPR_OR_CONST std::size_t max_align =
0036       boost::move_detail::alignment_of<boost::move_detail::max_align_t>::value;
0037 
0038    //! <b>Effects</b>: Destroys
0039    //! this memory_resource.
0040    virtual ~memory_resource(){}
0041 
0042    //! <b>Effects</b>: Equivalent to
0043    //! `return do_allocate(bytes, alignment);`
0044    void* allocate(std::size_t bytes, std::size_t alignment = max_align)
0045    {  
0046       //Obtain a pointer to enough storage and initialize the lifetime 
0047       //of an array object of the given size in the address
0048       return ::operator new(bytes, this->do_allocate(bytes, alignment), boost_container_new_t());
0049    }
0050 
0051    //! <b>Effects</b>: Equivalent to
0052    //! `return do_deallocate(bytes, alignment);`
0053    void  deallocate(void* p, std::size_t bytes, std::size_t alignment = max_align)
0054    {  return this->do_deallocate(p, bytes, alignment);  }
0055 
0056    //! <b>Effects</b>: Equivalent to
0057    //! `return do_is_equal(other);`
0058    bool is_equal(const memory_resource& other) const BOOST_NOEXCEPT
0059    {  return this->do_is_equal(other);  }
0060    
0061    #if !defined(BOOST_EMBTC)
0062 
0063    //! <b>Returns</b>:
0064    //!   `&a == &b || a.is_equal(b)`.
0065    friend bool operator==(const memory_resource& a, const memory_resource& b) BOOST_NOEXCEPT
0066    {  return &a == &b || a.is_equal(b);   }
0067 
0068    //! <b>Returns</b>:
0069    //!   !(a == b).
0070    friend bool operator!=(const memory_resource& a, const memory_resource& b) BOOST_NOEXCEPT
0071    {  return !(a == b); }
0072    
0073    #else
0074    
0075    //! <b>Returns</b>:
0076    //!   `&a == &b || a.is_equal(b)`.
0077    friend bool operator==(const memory_resource& a, const memory_resource& b) BOOST_NOEXCEPT;
0078 
0079    //! <b>Returns</b>:
0080    //!   !(a == b).
0081    friend bool operator!=(const memory_resource& a, const memory_resource& b) BOOST_NOEXCEPT;
0082    
0083    #endif
0084 
0085    protected:
0086    //! <b>Requires</b>: Alignment shall be a power of two.
0087    //!
0088    //! <b>Returns</b>: A derived class shall implement this function to return a pointer
0089    //!   to allocated storage with a size of at least bytes. The returned storage is
0090    //!   aligned to the specified alignment, if such alignment is supported; otherwise
0091    //!   it is aligned to max_align.
0092    //!
0093    //! <b>Throws</b>: A derived class implementation shall throw an appropriate exception if
0094    //!   it is unable to allocate memory with the requested size and alignment.
0095    virtual void* do_allocate(std::size_t bytes, std::size_t alignment) = 0;
0096 
0097    //! <b>Requires</b>: p shall have been returned from a prior call to
0098    //!   `allocate(bytes, alignment)` on a memory resource equal to *this, and the storage
0099    //!   at p shall not yet have been deallocated.
0100    //!
0101    //! <b>Effects</b>: A derived class shall implement this function to dispose of allocated storage.
0102    //!
0103    //! <b>Throws</b>: Nothing.
0104    virtual void do_deallocate(void* p, std::size_t bytes, std::size_t alignment) = 0;
0105 
0106    //! <b>Returns</b>: A derived class shall implement this function to return true if memory
0107    //!   allocated from this can be deallocated from other and vice-versa; otherwise it shall
0108    //!   return false. <i>[Note: The most-derived type of other might not match the type of this.
0109    //!   For a derived class, D, a typical implementation of this function will compute
0110    //!   `dynamic_cast<const D*>(&other)` and go no further (i.e., return false)
0111    //!   if it returns nullptr. - end note]</i>.
0112    virtual bool do_is_equal(const memory_resource& other) const BOOST_NOEXCEPT = 0;
0113 };
0114 
0115 #if defined(BOOST_EMBTC)
0116 
0117 //! <b>Returns</b>:
0118 //!   `&a == &b || a.is_equal(b)`.
0119 inline bool operator==(const memory_resource& a, const memory_resource& b) BOOST_NOEXCEPT
0120 {  return &a == &b || a.is_equal(b);   }
0121 
0122 //! <b>Returns</b>:
0123 //!   !(a == b).
0124 inline bool operator!=(const memory_resource& a, const memory_resource& b) BOOST_NOEXCEPT
0125 {  return !(a == b); }
0126 
0127 #endif
0128    
0129 }  //namespace pmr {
0130 }  //namespace container {
0131 }  //namespace boost {
0132 
0133 #include <boost/container/detail/config_end.hpp>
0134 
0135 #endif   //BOOST_CONTAINER_PMR_MEMORY_RESOURCE_HPP