0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

Added C++11 move construction/assignment to CF::Wrap,

BufferAllocatedType, ScopedPtr, and ScopedFD.
This commit is contained in:
James Yonan 2014-08-10 16:53:39 -06:00
parent 2f593bd2eb
commit 564dcdc2cf
4 changed files with 68 additions and 12 deletions

View File

@ -101,13 +101,13 @@ namespace openvpn {
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
Wrap(Wrap&& other)
Wrap(Wrap&& other) BOOST_NOEXCEPT
{
obj_ = other.obj_;
other.obj_ = NULL;
}
Wrap& operator=(Wrap&& other)
Wrap& operator=(Wrap&& other) BOOST_NOEXCEPT
{
if (obj_)
CFRelease(obj_);

View File

@ -552,15 +552,7 @@ namespace openvpn {
{
if (data_)
delete_(data_, capacity_, flags_);
data_ = other.data_;
offset_ = other.offset_;
size_ = other.size_;
capacity_ = other.capacity_;
flags_ = other.flags_;
other.data_ = NULL;
other.offset_ = other.size_ = other.capacity_ = 0;
move_(other);
}
void swap(BufferAllocatedType& other)
@ -572,6 +564,21 @@ namespace openvpn {
std::swap(flags_, other.flags_);
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BufferAllocatedType(BufferAllocatedType&& other) BOOST_NOEXCEPT
{
move_(other);
}
BufferAllocatedType& operator=(BufferAllocatedType&& other) BOOST_NOEXCEPT
{
move(other);
return *this;
}
#endif
void clear()
{
erase_();
@ -625,6 +632,18 @@ namespace openvpn {
}
}
void move_(BufferAllocatedType& other)
{
data_ = other.data_;
offset_ = other.offset_;
size_ = other.size_;
capacity_ = other.capacity_;
flags_ = other.flags_;
other.data_ = NULL;
other.offset_ = other.size_ = other.capacity_ = 0;
}
void erase_()
{
if (data_)

View File

@ -99,6 +99,24 @@ namespace openvpn {
close();
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
ScopedFD(ScopedFD&& other) BOOST_NOEXCEPT
{
fd = other.fd;
other.fd = -1;
}
ScopedFD& operator=(ScopedFD&& other) BOOST_NOEXCEPT
{
close();
fd = other.fd;
other.fd = -1;
return *this;
}
#endif
private:
int fd;
};

View File

@ -117,12 +117,31 @@ namespace openvpn {
del(px);
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
ScopedPtr(ScopedPtr&& other) BOOST_NOEXCEPT
{
px = other.px;
other.px = NULL;
}
ScopedPtr& operator=(ScopedPtr&& other) BOOST_NOEXCEPT
{
if (px)
del(px);
px = other.px;
other.px = NULL;
return *this;
}
#endif
private:
static void del(T* p)
{
F<T>::del(p);
}
protected:
T* px;
};