p.hpp
Go to the documentation of this file.
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PMEMOBJ_P_HPP
#define PMEMOBJ_P_HPP
#include <memory>
#include "libpmemobj++/detail/common.hpp"
#include "libpmemobj++/detail/specialization.hpp"
namespace pmem
{
namespace obj
{
template <typename T>
class p {
typedef p<T> this_type;
public:
p(const T &_val) noexcept : val{_val}
{
}
p() = default;
p &
operator=(const p &rhs)
{
this_type(rhs).swap(*this);
return *this;
}
template <typename Y, typename = typename std::enable_if<
std::is_convertible<Y, T>::value>::type>
p &
operator=(const p<Y> &rhs)
{
this_type(rhs).swap(*this);
return *this;
}
operator T() const noexcept
{
return this->val;
}
T &
get_rw()
{
detail::conditional_add_to_tx(this);
return this->val;
}
const T &
get_ro() const noexcept
{
return this->val;
}
void
swap(p &other)
{
detail::conditional_add_to_tx(this);
detail::conditional_add_to_tx(&other);
std::swap(this->val, other.val);
}
private:
T val;
};
template <class T>
inline void
swap(p<T> &a, p<T> &b)
{
a.swap(b);
}
} /* namespace obj */
} /* namespace pmem */
#endif /* PMEMOBJ_P_HPP */
specialization.hpp
Helper template for persistent ptr specialization.
pmem::obj::p::get_rw
T & get_rw()
Retrieves read-write reference of the object.
Definition: p.hpp:141
common.hpp
Commonly used functionality.
pmem::obj::p::p
p(const T &_val) noexcept
Value constructor.
Definition: p.hpp:75
pmem::obj::p::operator=
p & operator=(const p &rhs)
Assignment operator.
Definition: p.hpp:95
pmem::obj::p::get_ro
const T & get_ro() const noexcept
Retrieves read-only const reference of the object.
Definition: p.hpp:156
pmem::obj::p::swap
void swap(p &other)
Swaps two p objects of the same type.
Definition: p.hpp:168
pmem::obj::p
Resides on pmem class.
Definition: p.hpp:64
pmem
Definition: allocator.hpp:48
pmem::obj::p::p
p()=default
Defaulted constructor.
pmem::obj::p::operator=
p & operator=(const p< Y > &rhs)
Converting assignment operator from a different p<>.
Definition: p.hpp:115