SQLiteXX  0.1.0
 All Classes Namespaces Files Functions Enumerations Enumerator
Blob.cpp
1 #include "Blob.h"
2 
3 
4 namespace sqlite
5 {
6  blob::blob(const void* data, const size_t size) :
7  m_data(data != nullptr? new char[size]: nullptr),
8  m_size(size)
9  {
10  assert(data == nullptr? size == 0: size > 0);
11  memcpy(m_data.get(), data, size);
12  }
13 
14  blob::blob(const blob& other) :
15  m_data(other.m_size == 0? nullptr: new char[other.m_size]),
16  m_size(other.m_size)
17  {
18  memcpy(m_data.get(), other.m_data.get(), other.m_size);
19  }
20 
21  blob::blob(blob &&other) :
22  m_data(std::move(other.m_data)),
23  m_size(other.m_size)
24  {}
25 
26  blob& blob::operator=(const blob &other) {
27  if (this != &other) {
28  m_data.reset(other.m_size == 0? nullptr: new char[other.m_size]);
29  memcpy(m_data.get(), other.m_data.get(), other.m_size);
30 
31  m_size = other.m_size;
32  }
33 
34  return *this;
35  }
36 
38  assert(this != &other);
39  m_data = std::move(other.m_data);
40  m_size = other.m_size;
41  return *this;
42  }
43 
44  const void* blob::data() const {
45  return m_data.get();
46  }
47 
48  size_t blob::size() const {
49  return m_size;
50  }
51 }
52 
size_t size() const
Used to get the size of the contained 'blob'.
Definition: Blob.cpp:48
const void * data() const
The raw data of the blob's contents.
Definition: Blob.cpp:44
blob(const void *data, const size_t size)
Constructs a blob object with contents of data.
Definition: Blob.cpp:6
blob & operator=(const blob &other)
Copy assignment operator.
Definition: Blob.cpp:26
A "Binary Large OBject".
Definition: Blob.h:20