Переглянути джерело

Merge branch 'json_integration_improvement' of public/ls-standard-library into development

Lynar Studios - Public Repositories 2 роки тому
батько
коміт
0d9dfa4393

+ 1 - 0
README.md

@@ -42,6 +42,7 @@ A __Date__ class comes with this submodule, which you can use to represent a dat
 - this library can now build shared libraries by using MSVC
 - Clang support has been added to this library
 - added Base64 CLI Tool, which enables a user to use Base64 encoding and decoding functionalities via CLI
+- JSON type alias has been added to avoid direct nlohmann library usage
 
 #### Improvements ####
 

+ 3 - 1
include/ls_std/core/types/Types.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2022-07-02
+ * Changed:         2022-07-14
  *
  * */
 
@@ -11,6 +11,7 @@
 #define LS_STD_TYPES_HPP
 
 #include <string>
+#include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
 
 namespace ls::std::core::type
 {
@@ -18,6 +19,7 @@ namespace ls::std::core::type
   using byte_field = ::std::string;
   using long_type = long long int;
   using version_type = uint16_t;
+  using json = nlohmann::json;
 }
 
 #endif

+ 3 - 3
include/ls_std/event/serialization/SerializableJsonEvent.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-07
- * Changed:         2022-07-03
+ * Changed:         2022-07-14
  *
  * */
 
@@ -14,7 +14,7 @@
 #include <ls_std/core/Class.hpp>
 #include <ls_std/event/Event.hpp>
 #include <memory>
-#include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
+#include <ls_std/core/types/Types.hpp>
 #include <ls_std/os/dynamic_goal.hpp>
 
 namespace ls::std::event
@@ -38,7 +38,7 @@ namespace ls::std::event
 
     private:
 
-      nlohmann::json jsonObject{};
+      ls::std::core::type::json jsonObject{};
       ::std::shared_ptr<ls::std::event::Event> value{};
 
       void _assignValue(const ::std::shared_ptr<ls::std::event::Event> &_value);

+ 3 - 3
include/ls_std/logic/serialization/SerializableJsonState.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-15
- * Changed:         2022-07-03
+ * Changed:         2022-07-14
  *
  * */
 
@@ -11,7 +11,7 @@
 #define LS_STD_SERIALIZABLE_JSON_STATE_HPP
 
 #include <memory>
-#include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
+#include <ls_std/core/types/Types.hpp>
 #include <ls_std/logic/State.hpp>
 #include <ls_std/core/interface/ISerializable.hpp>
 #include <ls_std/core/Class.hpp>
@@ -38,7 +38,7 @@ namespace ls::std::logic
 
     private:
 
-      nlohmann::json jsonObject{};
+      ls::std::core::type::json jsonObject{};
       ::std::shared_ptr<ls::std::logic::State> value{};
 
       void _assignValue(const ::std::shared_ptr<ls::std::logic::State> &_value);

+ 3 - 3
include/ls_std/logic/serialization/SerializableJsonStateConnection.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-14
- * Changed:         2022-07-03
+ * Changed:         2022-07-14
  *
  * */
 
@@ -11,7 +11,7 @@
 #define LS_STD_SERIALIZABLE_JSON_STATE_CONNECTION_HPP
 
 #include <memory>
-#include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
+#include <ls_std/core/types/Types.hpp>
 #include <ls_std/core/Class.hpp>
 #include <ls_std/core/interface/ISerializable.hpp>
 #include <ls_std/logic/StateConnection.hpp>
@@ -38,7 +38,7 @@ namespace ls::std::logic
 
     private:
 
-      nlohmann::json jsonObject{};
+      ls::std::core::type::json jsonObject{};
       ::std::shared_ptr<ls::std::logic::StateConnection> value{};
 
       void _assignValue(const ::std::shared_ptr<ls::std::logic::StateConnection> &_value);

+ 3 - 3
include/ls_std/logic/serialization/SerializableJsonStateMachine.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-17
- * Changed:         2022-07-03
+ * Changed:         2022-07-14
  *
  * */
 
@@ -14,7 +14,7 @@
 #include <ls_std/core/interface/ISerializable.hpp>
 #include <ls_std/logic/StateMachine.hpp>
 #include <memory>
-#include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
+#include <ls_std/core/types/Types.hpp>
 #include <ls_std/os/dynamic_goal.hpp>
 
 namespace ls::std::logic
@@ -38,7 +38,7 @@ namespace ls::std::logic
 
     private:
 
-      nlohmann::json jsonObject{};
+      ls::std::core::type::json jsonObject{};
       ::std::shared_ptr<ls::std::logic::StateMachine> value{};
 
       void _assignValue(const ::std::shared_ptr<ls::std::logic::StateMachine> &_value);

+ 3 - 3
source/ls_std/event/serialization/SerializableJsonEvent.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-07
- * Changed:         2022-05-20
+ * Changed:         2022-07-14
  *
  * */
 
@@ -23,7 +23,7 @@ ls::std::core::type::byte_field ls::std::event::SerializableJsonEvent::marshal()
 
 void ls::std::event::SerializableJsonEvent::unmarshal(const ls::std::core::type::byte_field &_data)
 {
-  this->jsonObject = nlohmann::json::parse(_data);
+  this->jsonObject = ls::std::core::type::json::parse(_data);
 
   this->value->setId(this->jsonObject["id"]);
   this->_unmarshalParameterList();
@@ -73,7 +73,7 @@ void ls::std::event::SerializableJsonEvent::_updateEventParameterList()
 
   for (const auto &eventParameter : this->value->getParameterList())
   {
-    nlohmann::json parameterJson = {eventParameter.first, eventParameter.second};
+    ls::std::core::type::json parameterJson = {eventParameter.first, eventParameter.second};
     this->jsonObject["parameterList"][eventParameter.first] = parameterJson;
   }
 }

+ 3 - 3
source/ls_std/logic/serialization/SerializableJsonState.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-15
- * Changed:         2022-05-20
+ * Changed:         2022-07-14
  *
  * */
 
@@ -24,7 +24,7 @@ ls::std::core::type::byte_field ls::std::logic::SerializableJsonState::marshal()
 
 void ls::std::logic::SerializableJsonState::unmarshal(const ls::std::core::type::byte_field &_data)
 {
-  this->jsonObject = nlohmann::json::parse(_data);
+  this->jsonObject = ls::std::core::type::json::parse(_data);
 
   this->_unmarshalStateConnections();
   this->value->setId(this->jsonObject["id"]);
@@ -85,6 +85,6 @@ void ls::std::logic::SerializableJsonState::_updateStateConnections()
   for (const auto &connection : this->value->getConnectedStates())
   {
     jsonString = ls::std::logic::SerializableJsonStateConnection{connection.second}.marshal();
-    this->jsonObject["connectedStates"][connection.first] = nlohmann::json::parse(jsonString);
+    this->jsonObject["connectedStates"][connection.first] = ls::std::core::type::json::parse(jsonString);
   }
 }

+ 2 - 2
source/ls_std/logic/serialization/SerializableJsonStateConnection.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-14
- * Changed:         2022-05-20
+ * Changed:         2022-07-14
  *
  * */
 
@@ -24,7 +24,7 @@ ls::std::core::type::byte_field ls::std::logic::SerializableJsonStateConnection:
 void ls::std::logic::SerializableJsonStateConnection::unmarshal(const ls::std::core::type::byte_field &_data)
 {
   ::std::string jsonString = ::std::string(_data);
-  this->jsonObject = nlohmann::json::parse(jsonString);
+  this->jsonObject = ls::std::core::type::json::parse(jsonString);
 
   this->value->setConnectionId(this->jsonObject["connectionId"]);
   this->value->setStateId(this->jsonObject["stateId"]);

+ 3 - 3
source/ls_std/logic/serialization/SerializableJsonStateMachine.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-17
- * Changed:         2022-05-20
+ * Changed:         2022-07-14
  *
  * */
 
@@ -24,7 +24,7 @@ ls::std::core::type::byte_field ls::std::logic::SerializableJsonStateMachine::ma
 
 void ls::std::logic::SerializableJsonStateMachine::unmarshal(const ls::std::core::type::byte_field &_data)
 {
-  this->jsonObject = nlohmann::json::parse(_data);
+  this->jsonObject = ls::std::core::type::json::parse(_data);
 
   this->_unmarshalStates();
   this->_unmarshalCurrentState();
@@ -94,6 +94,6 @@ void ls::std::logic::SerializableJsonStateMachine::_updateStates()
   for (const auto &state : this->value->getStates())
   {
     jsonString = ls::std::logic::SerializableJsonState{state.second}.marshal();
-    this->jsonObject["states"][state.first] = nlohmann::json::parse(jsonString);
+    this->jsonObject["states"][state.first] = ls::std::core::type::json::parse(jsonString);
   }
 }

+ 3 - 3
test/cases/serialization/JsonTest.cpp

@@ -3,12 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2022-05-05
+ * Changed:         2022-07-15
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std/lib/nlohmann_json/include/nlohmann/json.hpp>
+#include <ls_std/core/types/Types.hpp>
 
 namespace
 {
@@ -28,7 +28,7 @@ namespace
 
   TEST_F(JsonTest, simpleSerialization)
   {
-    nlohmann::json jsonObject{};
+    ls::std::core::type::json jsonObject{};
     jsonObject["value"] = 1989;
 
     ASSERT_STREQ(R"({"value":1989})", jsonObject.dump().c_str());