Skip to content

Commit 8624408

Browse files
authored
Define copy/move constructors
1 parent c70469c commit 8624408

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cppjson/src/object.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ constexpr std::size_t DataStorageSize = std::max({sizeof(std::string), sizeof(cp
66

77
cppjson::JsonObject::JsonObject() : _dataStorage(static_cast<std::byte*>(::operator new(DataStorageSize))) {}
88

9+
cppjson::JsonObject::JsonObject(const cppjson::JsonObject& other)
10+
{
11+
if (other._dataStorage == nullptr) return;
12+
13+
this->_dataType = other._dataType;
14+
this->_dataStorage = ::operator new(DataStorageSize);
15+
std::memcpy(this->_dataStorage, other._dataStorage, DataStorageSize);
16+
}
17+
cppjson::JsonObject::JsonObject(JsonObject&& other)
18+
{
19+
this->_dataType = std::exchange(other._dataType, cppjson::JsonType::Null);
20+
this->_dataStorage = std::exchange(other._dataStorage, ::operator new(DataStorageSize));
21+
}
22+
923
cppjson::JsonObject::~JsonObject()
1024
{
1125
this->Destroy();

0 commit comments

Comments
 (0)