Prechádzať zdrojové kódy

Add nullptr check to serialization class constructors

Patrick-Christopher Mattulat 4 rokov pred
rodič
commit
4c359a4e07

+ 3 - 2
include/ls_std/serialization/boxing/SerializableJSONBoolean.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-04
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -20,7 +20,7 @@ namespace ls_std {
   class SerializableJSONBoolean : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONBoolean(std::shared_ptr<ls_std::Boolean> _value);
+      explicit SerializableJSONBoolean(const std::shared_ptr<ls_std::Boolean>& _value);
       ~SerializableJSONBoolean() = default;
 
       ls_std::byte_field marshal() override;
@@ -31,6 +31,7 @@ namespace ls_std {
       std::shared_ptr<ls_std::Boolean> value {};
       nlohmann::json jsonObject {};
 
+      void _assignValue(const std::shared_ptr<ls_std::Boolean>& _value);
       void _update();
   };
 }

+ 3 - 2
include/ls_std/serialization/boxing/SerializableJSONDouble.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-04
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -20,7 +20,7 @@ namespace ls_std {
   class SerializableJSONDouble : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONDouble(std::shared_ptr<ls_std::Double> _value);
+      explicit SerializableJSONDouble(const std::shared_ptr<ls_std::Double>& _value);
       ~SerializableJSONDouble() = default;
 
       ls_std::byte_field marshal() override;
@@ -31,6 +31,7 @@ namespace ls_std {
       std::shared_ptr<ls_std::Double> value {};
       nlohmann::json jsonObject {};
 
+      void _assignValue(const std::shared_ptr<ls_std::Double>& _value);
       void _update();
   };
 }

+ 3 - 2
include/ls_std/serialization/boxing/SerializableJSONFloat.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-04
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -20,7 +20,7 @@ namespace ls_std {
   class SerializableJSONFloat : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONFloat(std::shared_ptr<ls_std::Float> _value);
+      explicit SerializableJSONFloat(const std::shared_ptr<ls_std::Float>& _value);
       ~SerializableJSONFloat() = default;
 
       ls_std::byte_field marshal() override;
@@ -31,6 +31,7 @@ namespace ls_std {
       std::shared_ptr<ls_std::Float> value {};
       nlohmann::json jsonObject {};
 
+      void _assignValue(const std::shared_ptr<ls_std::Float>& _value);
       void _update();
   };
 }

+ 3 - 2
include/ls_std/serialization/boxing/SerializableJSONInteger.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-21
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -19,7 +19,7 @@ namespace ls_std {
   class SerializableJSONInteger : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONInteger(std::shared_ptr<ls_std::Integer> _value);
+      explicit SerializableJSONInteger(const std::shared_ptr<ls_std::Integer>& _value);
       ~SerializableJSONInteger() = default;
 
       ls_std::byte_field marshal() override;
@@ -30,6 +30,7 @@ namespace ls_std {
       std::shared_ptr<ls_std::Integer> value {};
       nlohmann::json jsonObject {};
 
+      void _assignValue(const std::shared_ptr<ls_std::Integer>& _value);
       void _update();
   };
 }

+ 3 - 2
include/ls_std/serialization/boxing/SerializableJSONLong.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-25
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -19,7 +19,7 @@ namespace ls_std {
   class SerializableJSONLong : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONLong(std::shared_ptr<ls_std::Long> _value);
+      explicit SerializableJSONLong(const std::shared_ptr<ls_std::Long>& _value);
       ~SerializableJSONLong() = default;
 
       ls_std::byte_field marshal() override;
@@ -30,6 +30,7 @@ namespace ls_std {
       nlohmann::json jsonObject {};
       std::shared_ptr<ls_std::Long> value {};
 
+      void _assignValue(const std::shared_ptr<ls_std::Long>& _value);
       void _update();
   };
 }

+ 3 - 2
include/ls_std/serialization/boxing/SerializableJSONString.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-30
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -19,7 +19,7 @@ namespace ls_std {
   class SerializableJSONString : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONString(std::shared_ptr<ls_std::String> _value);
+      explicit SerializableJSONString(const std::shared_ptr<ls_std::String>& _value);
       ~SerializableJSONString() = default;
 
       ls_std::byte_field marshal() override;
@@ -30,6 +30,7 @@ namespace ls_std {
       nlohmann::json jsonObject {};
       std::shared_ptr<ls_std::String> value {};
 
+      void _assignValue(const std::shared_ptr<ls_std::String>& _value);
       void _update();
   };
 }

+ 4 - 3
include/ls_std/serialization/logic/SerializableJSONState.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-15
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -20,7 +20,7 @@ namespace ls_std {
   class SerializableJSONState : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONState(std::shared_ptr<State> _value);
+      explicit SerializableJSONState(const std::shared_ptr<State>& _value);
       ~SerializableJSONState() = default;
 
       // implementation
@@ -30,13 +30,14 @@ namespace ls_std {
 
       // additional functionality
 
-      void setValue(std::shared_ptr<State> _value);
+      void setValue(const std::shared_ptr<State>& _value);
 
     private:
 
       nlohmann::json jsonObject {};
       std::shared_ptr<ls_std::State> value {};
 
+      void _assignValue(const std::shared_ptr<State>& _value);
       void _clear();
       void _unmarshalExistingStateConnection(nlohmann::json _jsonObject);
       void _unmarshalNewStateConnection(nlohmann::json _jsonObject);

+ 4 - 3
include/ls_std/serialization/logic/SerializableJSONStateConnection.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-14
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -20,7 +20,7 @@ namespace ls_std {
   class SerializableJSONStateConnection : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONStateConnection(std::shared_ptr<ls_std::StateConnection> _value);
+      explicit SerializableJSONStateConnection(const std::shared_ptr<ls_std::StateConnection>& _value);
       ~SerializableJSONStateConnection() = default;
 
       // implementation
@@ -30,13 +30,14 @@ namespace ls_std {
 
       // additional functionality
 
-      void setValue(std::shared_ptr<ls_std::StateConnection> _value);
+      void setValue(const std::shared_ptr<ls_std::StateConnection>& _value);
 
     private:
 
       nlohmann::json jsonObject {};
       std::shared_ptr<ls_std::StateConnection> value {};
 
+      void _assignValue(const std::shared_ptr<ls_std::StateConnection>& _value);
       void _clear();
       void _update();
   };

+ 3 - 2
include/ls_std/serialization/logic/SerializableJSONStateMachine.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-17
- * Changed:         2020-11-20
+ * Changed:         2020-11-25
  *
  * */
 
@@ -20,7 +20,7 @@ namespace ls_std {
   class SerializableJSONStateMachine : public Class, public ISerializable {
     public:
 
-      explicit SerializableJSONStateMachine(std::shared_ptr<StateMachine> _value);
+      explicit SerializableJSONStateMachine(const std::shared_ptr<StateMachine>& _value);
       ~SerializableJSONStateMachine() = default;
 
       ls_std::byte_field marshal() override;
@@ -31,6 +31,7 @@ namespace ls_std {
       nlohmann::json jsonObject {};
       std::shared_ptr<ls_std::StateMachine> value {};
 
+      void _assignValue(const std::shared_ptr<StateMachine>& _value);
       void _unmarshalCurrentState();
       void _unmarshalStates();
       void _update();

+ 16 - 5
source/ls_std/serialization/json/boxing/SerializableJSONBoolean.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-04
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONBoolean.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONBoolean::SerializableJSONBoolean(std::shared_ptr<ls_std::Boolean> _value) :
-Class("SerializableJSONBoolean"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONBoolean::SerializableJSONBoolean(const std::shared_ptr<ls_std::Boolean>& _value) :
+Class("SerializableJSONBoolean")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONBoolean::marshal()
 {
@@ -29,6 +31,15 @@ void ls_std::SerializableJSONBoolean::unmarshal(const ls_std::byte_field& _data)
   }
 }
 
+void ls_std::SerializableJSONBoolean::_assignValue(const std::shared_ptr<ls_std::Boolean> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONBoolean::_update()
 {
   this->jsonObject = {

+ 16 - 5
source/ls_std/serialization/json/boxing/SerializableJSONDouble.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-04
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONDouble.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONDouble::SerializableJSONDouble(std::shared_ptr<ls_std::Double> _value) :
-Class("SerializableJSONDouble"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONDouble::SerializableJSONDouble(const std::shared_ptr<ls_std::Double>& _value) :
+Class("SerializableJSONDouble")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONDouble::marshal()
 {
@@ -30,6 +32,15 @@ void ls_std::SerializableJSONDouble::unmarshal(const ls_std::byte_field& _data)
   }
 }
 
+void ls_std::SerializableJSONDouble::_assignValue(const std::shared_ptr<ls_std::Double> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONDouble::_update()
 {
   this->jsonObject = {

+ 16 - 5
source/ls_std/serialization/json/boxing/SerializableJSONFloat.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-04
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONFloat.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONFloat::SerializableJSONFloat(std::shared_ptr<ls_std::Float> _value) :
-Class("SerializableJSONFloat"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONFloat::SerializableJSONFloat(const std::shared_ptr<ls_std::Float>& _value) :
+Class("SerializableJSONFloat")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONFloat::marshal()
 {
@@ -30,6 +32,15 @@ void ls_std::SerializableJSONFloat::unmarshal(const ls_std::byte_field& _data)
   }
 }
 
+void ls_std::SerializableJSONFloat::_assignValue(const std::shared_ptr<ls_std::Float> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONFloat::_update()
 {
   this->jsonObject = {

+ 16 - 5
source/ls_std/serialization/json/boxing/SerializableJSONInteger.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-21
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONInteger.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONInteger::SerializableJSONInteger(std::shared_ptr<ls_std::Integer> _value) :
-Class("SerializableJSONInteger"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONInteger::SerializableJSONInteger(const std::shared_ptr<ls_std::Integer>& _value) :
+Class("SerializableJSONInteger")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONInteger::marshal()
 {
@@ -30,6 +32,15 @@ void ls_std::SerializableJSONInteger::unmarshal(const ls_std::byte_field& _data)
   }
 }
 
+void ls_std::SerializableJSONInteger::_assignValue(const std::shared_ptr<ls_std::Integer> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONInteger::_update()
 {
   this->jsonObject = {

+ 16 - 5
source/ls_std/serialization/json/boxing/SerializableJSONLong.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-25
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONLong.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONLong::SerializableJSONLong(std::shared_ptr<ls_std::Long> _value) :
-Class("SerializableJSONLong"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONLong::SerializableJSONLong(const std::shared_ptr<ls_std::Long>& _value) :
+Class("SerializableJSONLong")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONLong::marshal()
 {
@@ -30,6 +32,15 @@ void ls_std::SerializableJSONLong::unmarshal(const ls_std::byte_field& _data)
   }
 }
 
+void ls_std::SerializableJSONLong::_assignValue(const std::shared_ptr<ls_std::Long> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONLong::_update()
 {
   this->jsonObject = {

+ 16 - 5
source/ls_std/serialization/json/boxing/SerializableJSONString.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-30
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/boxing/SerializableJSONString.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONString::SerializableJSONString(std::shared_ptr<ls_std::String> _value) :
-Class("SerializableJSONString"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONString::SerializableJSONString(const std::shared_ptr<ls_std::String>& _value) :
+Class("SerializableJSONString")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONString::marshal()
 {
@@ -30,6 +32,15 @@ void ls_std::SerializableJSONString::unmarshal(const ls_std::byte_field& _data)
   }
 }
 
+void ls_std::SerializableJSONString::_assignValue(const std::shared_ptr<ls_std::String> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONString::_update()
 {
   this->jsonObject = {

+ 17 - 6
source/ls_std/serialization/json/logic/SerializableJSONState.cpp

@@ -9,11 +9,13 @@
 
 #include "../../../../../include/ls_std/serialization/logic/SerializableJSONState.hpp"
 #include "../../../../../include/ls_std/serialization/logic/SerializableJSONStateConnection.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONState::SerializableJSONState(std::shared_ptr<State> _value) :
-Class("SerializableJSONState"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONState::SerializableJSONState(const std::shared_ptr<State>& _value) :
+Class("SerializableJSONState")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONState::marshal()
 {
@@ -29,12 +31,21 @@ void ls_std::SerializableJSONState::unmarshal(const ls_std::byte_field &_data)
   this->value->setId(this->jsonObject["id"]);
 }
 
-void ls_std::SerializableJSONState::setValue(std::shared_ptr<State> _value)
+void ls_std::SerializableJSONState::setValue(const std::shared_ptr<State>& _value)
 {
-  this->value = std::move(_value);
+  this->_assignValue(_value);
   this->_clear();
 }
 
+void ls_std::SerializableJSONState::_assignValue(const std::shared_ptr<State> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONState::_clear()
 {
   this->jsonObject.clear();

+ 18 - 7
source/ls_std/serialization/json/logic/SerializableJSONStateConnection.cpp

@@ -3,16 +3,18 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-14
- * Changed:         2020-11-06
+ * Changed:         2020-11-25
  *
  * */
 
 #include "../../../../../include/ls_std/serialization/logic/SerializableJSONStateConnection.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONStateConnection::SerializableJSONStateConnection(std::shared_ptr<ls_std::StateConnection> _value) :
-Class("SerializableJSONStateConnection"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONStateConnection::SerializableJSONStateConnection(const std::shared_ptr<ls_std::StateConnection>& _value) :
+Class("SerializableJSONStateConnection")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONStateConnection::marshal()
 {
@@ -30,12 +32,21 @@ void ls_std::SerializableJSONStateConnection::unmarshal(const ls_std::byte_field
   this->value->updatePassCondition(this->jsonObject["condition"]);
 }
 
-void ls_std::SerializableJSONStateConnection::setValue(std::shared_ptr<ls_std::StateConnection> _value)
+void ls_std::SerializableJSONStateConnection::setValue(const std::shared_ptr<ls_std::StateConnection>& _value)
 {
-  this->value = std::move(_value);
+  this->_assignValue(_value);
   this->_clear();
 }
 
+void ls_std::SerializableJSONStateConnection::_assignValue(const std::shared_ptr<ls_std::StateConnection> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONStateConnection::_clear()
 {
   this->jsonObject.clear();

+ 15 - 4
source/ls_std/serialization/json/logic/SerializableJSONStateMachine.cpp

@@ -9,11 +9,13 @@
 
 #include "../../../../../include/ls_std/serialization/logic/SerializableJSONStateMachine.hpp"
 #include "../../../../../include/ls_std/serialization/logic/SerializableJSONState.hpp"
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::SerializableJSONStateMachine::SerializableJSONStateMachine(std::shared_ptr<StateMachine> _value) :
-Class("SerializableJSONStateMachine"),
-value(std::move(_value))
-{}
+ls_std::SerializableJSONStateMachine::SerializableJSONStateMachine(const std::shared_ptr<StateMachine>& _value) :
+Class("SerializableJSONStateMachine")
+{
+  this->_assignValue(_value);
+}
 
 ls_std::byte_field ls_std::SerializableJSONStateMachine::marshal()
 {
@@ -31,6 +33,15 @@ void ls_std::SerializableJSONStateMachine::unmarshal(const ls_std::byte_field &_
   this->value->setName(this->jsonObject["name"]);
 }
 
+void ls_std::SerializableJSONStateMachine::_assignValue(const std::shared_ptr<StateMachine> &_value)
+{
+  if(_value == nullptr) {
+    throw ls_std::IllegalArgumentException {};
+  }
+
+  this->value = _value;
+}
+
 void ls_std::SerializableJSONStateMachine::_unmarshalCurrentState()
 {
   if(this->jsonObject.contains("currentState")) {