Files

118 lines
2.6 KiB
C++

/**
* @file include/ActivMiddleware/CxxYZ/memory.h
*
* @brief Header file for easing C++11 (or later) <memory> features across compilers.
*/
#if (!defined ACTIV_CXXYX_MEMORY_H)
#define ACTIV_CXXYX_MEMORY_H
#include "ActivMiddleware/ActivMiddleware.h"
#if (defined ACTIV_BOOST_NO_CXX11_SMART_PTR)
#include ACTIV_BOOST_INCLUDE(core/addressof.hpp)
#include ACTIV_BOOST_INCLUDE(move/unique_ptr.hpp)
#include ACTIV_BOOST_INCLUDE(move/make_unique.hpp)
#include ACTIV_BOOST_INCLUDE(smart_ptr/enable_shared_from_this.hpp)
#include ACTIV_BOOST_INCLUDE(smart_ptr/shared_ptr.hpp)
#include ACTIV_BOOST_INCLUDE(smart_ptr/make_shared.hpp)
//! Activ namespace.
namespace Activ
{
//! CxxYZ namespace.
namespace CxxYZ
{
using Boost::addressof;
using Boost::movelib::unique_ptr;
using Boost::movelib::make_unique;
using Boost::shared_ptr;
using Boost::make_shared;
using Boost::enable_shared_from_this;
using Boost::weak_ptr;
} // namespace CxxYZ
} // namespace Activ
#else
#include <memory>
#if (ACTIV_CPLUSPLUS >= ACTIV_CPLUSPLUS_14)
#define ACTIV_CXXYZ_MEMORY_HAS_MAKE_UNIQUE
#else
#include ACTIV_BOOST_INCLUDE(smart_ptr/make_unique.hpp)
#endif
//! Activ namespace.
namespace Activ
{
//! CxxYZ namespace.
namespace CxxYZ
{
using std::addressof;
using std::unique_ptr;
using std::shared_ptr;
using std::make_shared;
using std::enable_shared_from_this;
using std::weak_ptr;
#if (defined ACTIV_CXXYZ_MEMORY_HAS_MAKE_UNIQUE)
using std::make_unique;
#undef ACTIV_CXXYZ_MEMORY_HAS_MAKE_UNIQUE
#else
using Boost::make_unique;
#endif // (defined ACTIV_CXXYZ_MEMORY_HAS_MAKE_UNIQUE)
} // namespace CxxYZ
} // namespace Activ
#endif
// ---------------------------------------------------------------------------------------------------------------------------------
//! Activ namespace.
namespace Activ
{
#if (defined ACTIV_BOOST_NO_CXX11_TEMPLATE_ALIASES) || (defined ACTIV_BOOST_NO_CXX11_SMART_PTR)
/**
* @brief A wrapper over Boost::shared_ptr to allow construction from a Boost::interprocess::unique_ptr.
*
* C++11's std::shared_ptr supports construction from std::unique_ptr.
*
* Usage:
* pSomeSharedPtr(SharedPtrFromUniquePtr<UnderlyingType>(CxxYZ::move(pUniquePtrToUnderlyingType)));
*
* Note there is no custom deleter version for now.
*/
template<typename T>
class SharedPtrFromUniquePtr : public CxxYZ::shared_ptr<T>
{
public:
SharedPtrFromUniquePtr(ACTIV_BOOST_RV_REF(CxxYZ::unique_ptr<T>) pUnique) :
CxxYZ::shared_ptr<T>(pUnique.get())
{
pUnique.release();
}
};
#else
template<typename T>
using SharedPtrFromUniquePtr = CxxYZ::shared_ptr<T>;
#endif
} // namespace Activ
#endif // (!defined ACTIV_CXXYX_MEMORY_H)