0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 20:13:05 +02:00
openvpn3/openvpn/common/scoped_ptr.hpp
James Yonan 29bc40bf09 Added TCP transport support.
Disable retransmission of control channel packets
when running in TCP mode.
2012-01-20 23:13:48 +00:00

62 lines
915 B
C++

#ifndef OPENVPN_COMMON_SCOPED_PTR_H
#define OPENVPN_COMMON_SCOPED_PTR_H
#include <algorithm>
#include <boost/assert.hpp>
#include <boost/noncopyable.hpp>
#include <openvpn/common/types.hpp>
namespace openvpn {
// like boost::scoped_ptr but has release method
template <typename T>
class ScopedPtr : boost::noncopyable
{
public:
explicit ScopedPtr(T* p)
: px(p) {}
T* release()
{
T* ret = px;
px = NULL;
return ret;
}
void swap(ScopedPtr& other)
{
std::swap(px, other.px);
}
T& operator*() const
{
BOOST_ASSERT( px != 0 );
return *px;
}
T* operator->() const
{
BOOST_ASSERT( px != 0 );
return px;
}
T* get() const
{
return px;
}
~ScopedPtr() {
if (px)
delete px;
}
private:
T* px;
};
} // namespace openvpn
#endif // OPENVPN_COMMON_SCOPED_PTR_H