1
1
#include " cppjson/object.hpp"
2
+ #include < cstring>
2
3
#include < new>
3
4
#include < stdexcept>
4
- #include < cstring>
5
5
#include < utility>
6
6
7
7
constexpr std::size_t DataStorageSize = std::max({sizeof (std::string), sizeof (cppjson::Object), sizeof (double ), sizeof (bool )});
@@ -11,34 +11,34 @@ cppjson::JsonObject::JsonObject() : _dataStorage(static_cast<std::byte*>(::opera
11
11
cppjson::JsonObject::JsonObject (const cppjson::JsonObject& other)
12
12
{
13
13
if (other._dataStorage == nullptr ) return ;
14
-
14
+
15
15
this ->_dataType = other._dataType ;
16
16
this ->_dataStorage = static_cast <std::byte*>(::operator new (DataStorageSize));
17
17
std::memcpy (this ->_dataStorage , other._dataStorage , DataStorageSize);
18
18
}
19
19
cppjson::JsonObject::JsonObject (JsonObject&& other) noexcept
20
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)));
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
23
}
24
24
cppjson::JsonObject& cppjson::JsonObject::operator =(const cppjson::JsonObject& other)
25
25
{
26
- if (&other != this )
27
- {
26
+ if (&other != this )
27
+ {
28
28
this ->_dataType = other._dataType ;
29
29
this ->_dataStorage = static_cast <std::byte*>(::operator new (DataStorageSize));
30
- std::memcpy (this ->_dataStorage , other._dataStorage , DataStorageSize);
30
+ std::memcpy (this ->_dataStorage , other._dataStorage , DataStorageSize);
31
31
}
32
- return *this ;
32
+ return *this ;
33
33
}
34
34
cppjson::JsonObject& cppjson::JsonObject::operator =(cppjson::JsonObject&& other) noexcept
35
35
{
36
- if (&other != this )
37
- {
36
+ if (&other != this )
37
+ {
38
38
this ->_dataType = std::exchange (other._dataType , cppjson::JsonType::Null);
39
39
this ->_dataStorage = std::exchange (other._dataStorage , static_cast <std::byte*>(::operator new (DataStorageSize)));
40
40
}
41
- return *this ;
41
+ return *this ;
42
42
}
43
43
cppjson::JsonObject::~JsonObject ()
44
44
{
@@ -48,9 +48,9 @@ cppjson::JsonObject::~JsonObject()
48
48
49
49
void cppjson::JsonObject::Destroy (void )
50
50
{
51
- using std::string;
52
- using cppjson::Object;
53
51
using cppjson::Array;
52
+ using cppjson::Object;
53
+ using std::string;
54
54
55
55
switch (std::exchange (this ->_dataType , JsonType::Null))
56
56
{
@@ -179,13 +179,9 @@ const std::nullptr_t& cppjson::JsonObject::As<std::nullptr_t>() const noexcept(f
179
179
return DangerousAs<std::nullptr_t >();
180
180
}
181
181
182
- cppjson::Object::ObjectProxy cppjson::Object::ObjectProxy::operator [](const std::string& key)
183
- {
184
- return ObjectProxy{ this ->_object .get ().As <Object>()[key] };
185
- }
186
-
182
+ cppjson::Object::ObjectProxy cppjson::Object::ObjectProxy::operator [](const std::string& key) { return ObjectProxy{this ->_object .get ().As <Object>()[key]}; }
187
183
188
184
cppjson::Object::ConstObjectProxy cppjson::Object::ConstObjectProxy::operator [](const std::string& key) const
189
185
{
190
- return ConstObjectProxy{ this ->_object .get ().As <Object>()[key] };
186
+ return ConstObjectProxy{this ->_object .get ().As <Object>()[key]};
191
187
}
0 commit comments