mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-27 10:26:01 +02:00
Merge pull request #353 from jonitis/feature_sbuffer_move_semantics
Add move semantics to sbuffer in c++11 mode
This commit is contained in:
commit
a0b7e7cc27
@ -51,7 +51,32 @@ public:
|
|||||||
::free(m_data);
|
::free(m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
#if !defined(MSGPACK_USE_CPP03)
|
||||||
|
sbuffer(const sbuffer&) = delete;
|
||||||
|
sbuffer& operator=(const sbuffer&) = delete;
|
||||||
|
|
||||||
|
sbuffer(sbuffer&& other) :
|
||||||
|
m_size(other.m_size), m_data(other.m_data), m_alloc(other.m_alloc)
|
||||||
|
{
|
||||||
|
other.m_size = other.m_alloc = 0;
|
||||||
|
other.m_data = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
sbuffer& operator=(sbuffer&& other)
|
||||||
|
{
|
||||||
|
::free(m_data);
|
||||||
|
|
||||||
|
m_size = other.m_size;
|
||||||
|
m_alloc = other.m_alloc;
|
||||||
|
m_data = other.m_data;
|
||||||
|
|
||||||
|
other.m_size = other.m_alloc = 0;
|
||||||
|
other.m_data = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
#endif // !defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
void write(const char* buf, size_t len)
|
void write(const char* buf, size_t len)
|
||||||
{
|
{
|
||||||
if(m_alloc - m_size < len) {
|
if(m_alloc - m_size < len) {
|
||||||
@ -118,9 +143,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
sbuffer(const sbuffer&);
|
sbuffer(const sbuffer&);
|
||||||
sbuffer& operator=(const sbuffer&);
|
sbuffer& operator=(const sbuffer&);
|
||||||
#else // defined(MSGPACK_USE_CPP03)
|
|
||||||
sbuffer(const sbuffer&) = delete;
|
|
||||||
sbuffer& operator=(const sbuffer&) = delete;
|
|
||||||
#endif // defined(MSGPACK_USE_CPP03)
|
#endif // defined(MSGPACK_USE_CPP03)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user