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:
parent
2f593bd2eb
commit
564dcdc2cf
@ -101,13 +101,13 @@ namespace openvpn {
|
|||||||
|
|
||||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||||
|
|
||||||
Wrap(Wrap&& other)
|
Wrap(Wrap&& other) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
obj_ = other.obj_;
|
obj_ = other.obj_;
|
||||||
other.obj_ = NULL;
|
other.obj_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wrap& operator=(Wrap&& other)
|
Wrap& operator=(Wrap&& other) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (obj_)
|
if (obj_)
|
||||||
CFRelease(obj_);
|
CFRelease(obj_);
|
||||||
|
@ -552,15 +552,7 @@ namespace openvpn {
|
|||||||
{
|
{
|
||||||
if (data_)
|
if (data_)
|
||||||
delete_(data_, capacity_, flags_);
|
delete_(data_, capacity_, flags_);
|
||||||
|
move_(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 swap(BufferAllocatedType& other)
|
void swap(BufferAllocatedType& other)
|
||||||
@ -572,6 +564,21 @@ namespace openvpn {
|
|||||||
std::swap(flags_, other.flags_);
|
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()
|
void clear()
|
||||||
{
|
{
|
||||||
erase_();
|
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_()
|
void erase_()
|
||||||
{
|
{
|
||||||
if (data_)
|
if (data_)
|
||||||
|
@ -99,6 +99,24 @@ namespace openvpn {
|
|||||||
close();
|
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:
|
private:
|
||||||
int fd;
|
int fd;
|
||||||
};
|
};
|
||||||
|
@ -117,12 +117,31 @@ namespace openvpn {
|
|||||||
del(px);
|
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)
|
static void del(T* p)
|
||||||
{
|
{
|
||||||
F<T>::del(p);
|
F<T>::del(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
T* px;
|
T* px;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user