11#include  " cppjson/object.hpp" 
22#include  < new> 
33#include  < stdexcept> 
4+ #include  < cstring> 
5+ #include  < utility> 
46
57constexpr  std::size_t  DataStorageSize = std::max({sizeof (std::string), sizeof (cppjson::Object), sizeof (double ), sizeof (bool )});
68
79cppjson::JsonObject::JsonObject () : _dataStorage(static_cast <std::byte*>(::operator  new (DataStorageSize))) {}
810
11+ cppjson::JsonObject::JsonObject (const  cppjson::JsonObject& other)
12+ {
13+ 	if  (other._dataStorage  == nullptr ) return ;
14+ 	
15+ 	this ->_dataType  = other._dataType ;
16+ 	this ->_dataStorage  = static_cast <std::byte*>(::operator  new (DataStorageSize));
17+ 	std::memcpy (this ->_dataStorage , other._dataStorage , DataStorageSize);
18+ }
19+ cppjson::JsonObject::JsonObject (JsonObject&& other)
20+ {
21+      this ->_dataType  = std::exchange (other._dataType , cppjson::JsonType::Null);
22+      this ->_dataStorage  = std::exchange (other._dataStorage , static_cast <std::byte*>(::operator  new (DataStorageSize)));
23+ }
24+ cppjson::JsonObject& cppjson::JsonObject::operator =(const  cppjson::JsonObject& other)
25+ {
26+     if  (&other != this )
27+     {
28+ 		this ->_dataType  = other._dataType ;
29+ 		this ->_dataStorage  = static_cast <std::byte*>(::operator  new (DataStorageSize));
30+ 	    std::memcpy (this ->_dataStorage , other._dataStorage , DataStorageSize);
31+ 	}
32+     return  *this ;
33+ }
34+ cppjson::JsonObject& cppjson::JsonObject::operator =(cppjson::JsonObject&& other)
35+ {
36+     if  (&other != this )
37+     {
38+ 		this ->_dataType  = std::exchange (other._dataType , cppjson::JsonType::Null);
39+ 		this ->_dataStorage  = std::exchange (other._dataStorage , static_cast <std::byte*>(::operator  new (DataStorageSize)));
40+ 	}
41+     return  *this ;
42+ }
943cppjson::JsonObject::~JsonObject ()
1044{
1145	this ->Destroy ();
@@ -15,13 +49,16 @@ cppjson::JsonObject::~JsonObject()
1549void  cppjson::JsonObject::Destroy (void )
1650{
1751	using  std::string;
52+ 	using  cppjson::Object;
1853
1954	switch  (std::exchange (this ->_dataType , JsonType::Null))
2055	{
2156	case  JsonType::Null:
2257	case  JsonType::Number:
2358	case  JsonType::Bool: break ;
24- 	case  JsonType::String: DangerousAs<std::string>().~string ();
59+ 	case  JsonType::String: DangerousAs<std::string>().~string (); break ;
60+ 	case  JsonType::Object: DangerousAs<cppjson::Object>().~Object (); break ;
61+ 	//  TODO: Array
2562	}
2663}
2764
0 commit comments