Bladeren bron

Add NullPointerArgumentEvaluator class

This class evaluates, whether a parameter reference is null and throws an IllegalArgumentException.
Patrick-Christopher Mattulat 1 jaar geleden
bovenliggende
commit
43c0d903f0

+ 2 - 0
CMakeLists.txt

@@ -128,6 +128,7 @@ set(SOURCE_FILES_BOXING
 
 set(SOURCE_FILES_CORE
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/evaluator/EmptyStringArgumentEvaluator.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/evaluator/NullPointerArgumentEvaluator.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/EventNotHandledException.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/EventNotSubscribedException.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/ExceptionMessage.cpp
@@ -207,6 +208,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
 
     set(TEST_FILES_CORE
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/evaluator/EmptyStringArgumentEvaluatorTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/evaluator/NullPointerArgumentEvaluatorTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/EventNotHandledExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/EventNotSubscribedExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/ExceptionMessageTest.cpp

+ 1 - 1
include/ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp

@@ -20,7 +20,7 @@ namespace ls::std::core
     public:
 
       explicit EmptyStringArgumentEvaluator(::std::string _argument);
-      EmptyStringArgumentEvaluator(::std::string _argument, ::std::string _message);
+      explicit EmptyStringArgumentEvaluator(::std::string _argument, ::std::string _message);
       ~EmptyStringArgumentEvaluator() override;
 
       void evaluate() override;

+ 36 - 0
include/ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp

@@ -0,0 +1,36 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#ifndef LS_STD_NULL_POINTER_ARGUMENT_EVALUATOR_HPP
+#define LS_STD_NULL_POINTER_ARGUMENT_EVALUATOR_HPP
+
+#include <ls-std/core/interface/IEvaluator.hpp>
+#include <memory>
+#include <string>
+
+namespace ls::std::core
+{
+  class NullPointerArgumentEvaluator : public ls::std::core::interface_type::IEvaluator
+  {
+    public:
+
+    explicit NullPointerArgumentEvaluator(const ::std::shared_ptr<void> &_argument);
+    explicit NullPointerArgumentEvaluator(const ::std::shared_ptr<void> &_argument, ::std::string _message);
+    ~NullPointerArgumentEvaluator() override;
+
+      void evaluate() override;
+
+    private:
+
+      ::std::shared_ptr<void> argument{};
+      ::std::string message{};
+  };
+}
+
+#endif

+ 0 - 2
include/ls-std/io/xml/XmlNode.hpp

@@ -64,8 +64,6 @@ namespace ls::std::io
 
       void _assignName(const ::std::string &_name);
       void _assignValue(const ::std::string &_value);
-      static void _checkIfAttributeReferenceIsValid(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute);
-      static void _checkIfNodeReferenceIsValid(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);
       [[nodiscard]] static ::std::string _getTab(uint8_t _tabSize);
       [[nodiscard]] bool _hasAttribute(const ::std::string &_name);
       [[nodiscard]] bool _hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_child);

+ 1 - 0
include/ls-std/ls-std-core.hpp

@@ -11,6 +11,7 @@
 #define LS_STD_LS_STD_CORE_HPP
 
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 
 #include <ls-std/core/exception/EventNotHandledException.hpp>
 #include <ls-std/core/exception/EventNotSubscribedException.hpp>

+ 34 - 0
source/ls-std/core/evaluator/NullPointerArgumentEvaluator.cpp

@@ -0,0 +1,34 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+
+ls::std::core::NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const ::std::shared_ptr<void> &_argument) : argument(_argument)
+{}
+
+ls::std::core::NullPointerArgumentEvaluator::NullPointerArgumentEvaluator(const ::std::shared_ptr<void> &_argument, ::std::string _message) : argument(_argument), message(::std::move(_message))
+{}
+
+ls::std::core::NullPointerArgumentEvaluator::~NullPointerArgumentEvaluator() = default;
+
+void ls::std::core::NullPointerArgumentEvaluator::evaluate()
+{
+  if (this->argument == nullptr)
+  {
+    if (this->message.empty())
+    {
+      throw ls::std::core::IllegalArgumentException{"passed argument is null!"};
+    }
+    else
+    {
+      throw ls::std::core::IllegalArgumentException{this->message};
+    }
+  }
+}

+ 5 - 21
source/ls-std/event/EventManager.cpp

@@ -8,9 +8,9 @@
  * */
 
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/core/exception/EventNotHandledException.hpp>
 #include <ls-std/core/exception/EventNotSubscribedException.hpp>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
 #include <ls-std/event/EventManager.hpp>
 
 ls::std::event::EventManager::EventManager() : ls::std::core::Class("EventManager")
@@ -21,11 +21,7 @@ ls::std::event::EventManager::~EventManager() = default;
 void ls::std::event::EventManager::subscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
 {
   ls::std::core::EmptyStringArgumentEvaluator{_id, "event id is empty and can not be subscribed!"}.evaluate();
-
-  if (_listener == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_listener is null"};
-  }
+  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for subscribe attempt is null!"}.evaluate();
 
   if (this->_hasEventHandler(_id))
   {
@@ -40,11 +36,7 @@ void ls::std::event::EventManager::subscribe(const ls::std::core::type::event_id
 void ls::std::event::EventManager::unsubscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
 {
   ls::std::core::EmptyStringArgumentEvaluator{_id, "event id is empty and can not be unsubscribed!"}.evaluate();
-
-  if (_listener == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_listener is null"};
-  }
+  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for unsubscribe attempt is null!"}.evaluate();
 
   if (this->_hasEventHandler(_id))
   {
@@ -55,11 +47,7 @@ void ls::std::event::EventManager::unsubscribe(const ls::std::core::type::event_
 bool ls::std::event::EventManager::addEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler)
 {
   bool wasAdded{};
-
-  if (_eventHandler == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_eventHandler is null"};
-  }
+  ls::std::core::NullPointerArgumentEvaluator{_eventHandler, "event handler reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasEventHandler(_eventHandler->getId()))
   {
@@ -90,11 +78,7 @@ bool ls::std::event::EventManager::hasEventHandler(const ls::std::core::type::ev
 
 bool ls::std::event::EventManager::removeEventHandler(const ::std::shared_ptr<ls::std::event::EventHandler> &_eventHandler)
 {
-  if (_eventHandler == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_eventHandler is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_eventHandler, "event handler reference for remove attempt is null!"}.evaluate();
   return this->_removeEventHandler(_eventHandler);
 }
 

+ 10 - 22
source/ls-std/event/Narrator.cpp

@@ -3,12 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
 #include <algorithm>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/event/Narrator.hpp>
 
 ls::std::event::Narrator::Narrator() : ls::std::core::Class("Narrator")
@@ -19,18 +19,12 @@ ls::std::event::Narrator::~Narrator() = default;
 bool ls::std::event::Narrator::addListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
 {
   bool wasAdded{};
+  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for add attempt is null!"}.evaluate();
 
-  if (_listener == nullptr)
+  if (!this->_hasListener(_listener))
   {
-    throw ls::std::core::IllegalArgumentException{"_listener is null"};
-  }
-  else
-  {
-    if (!this->_hasListener(_listener))
-    {
-      this->listeners.push_back(_listener);
-      wasAdded = true;
-    }
+    this->listeners.push_back(_listener);
+    wasAdded = true;
   }
 
   return wasAdded;
@@ -49,18 +43,12 @@ void ls::std::event::Narrator::clear()
 bool ls::std::event::Narrator::removeListener(const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
 {
   bool wasRemoved{};
+  ls::std::core::NullPointerArgumentEvaluator{_listener, "listener reference for remove attempt is null!"}.evaluate();
 
-  if (_listener == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_listener is null"};
-  }
-  else
+  if (this->_hasListener(_listener))
   {
-    if (this->_hasListener(_listener))
-    {
-      this->listeners.remove(_listener);
-      wasRemoved = true;
-    }
+    this->listeners.remove(_listener);
+    wasRemoved = true;
   }
 
   return wasRemoved;

+ 3 - 7
source/ls-std/event/serialization/SerializableJsonEvent.cpp

@@ -3,11 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-07
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/event/serialization/SerializableJsonEvent.hpp>
 
 ls::std::event::SerializableJsonEvent::SerializableJsonEvent(const ::std::shared_ptr<ls::std::event::Event> &_value) : ls::std::core::Class("SerializableJsonEvent")
@@ -43,11 +43,7 @@ void ls::std::event::SerializableJsonEvent::setValue(const ::std::shared_ptr<ls:
 
 void ls::std::event::SerializableJsonEvent::_assignValue(const ::std::shared_ptr<ls::std::event::Event> &_value)
 {
-  if (_value == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_value is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_value, "event reference for serialization attempt is null!"}.evaluate();
   this->value = _value;
 }
 

+ 3 - 6
source/ls-std/io/kv/KvFileReader.cpp

@@ -3,10 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/core/exception/IllegalArgumentException.hpp>
 #include <ls-std/io/FileReader.hpp>
 #include <ls-std/io/kv/KvFileReader.hpp>
@@ -45,11 +46,7 @@ void ls::std::io::KvFileReader::setFile(const ls::std::io::File &_kvFile)
 
 void ls::std::io::KvFileReader::_assignDocument(const ::std::shared_ptr<ls::std::io::KvDocument> &_document)
 {
-  if (_document == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_document is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_document, "passed document reference is null!"}.evaluate();
   this->document = _document;
 }
 

+ 3 - 7
source/ls-std/io/kv/KvParser.cpp

@@ -3,11 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/io/NewLine.hpp>
 #include <ls-std/io/kv/KvParser.hpp>
 
@@ -35,11 +35,7 @@ void ls::std::io::KvParser::setDocument(const ::std::shared_ptr<ls::std::io::KvD
 
 void ls::std::io::KvParser::_assignDocument(const ::std::shared_ptr<ls::std::io::KvDocument> &_document)
 {
-  if (_document == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_document is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_document, "reference to document is null!"}.evaluate();
   this->document = _document;
 }
 

+ 3 - 7
source/ls-std/io/logging/Logger.cpp

@@ -3,13 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-20
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
 #include <ctime>
 #include <iomanip>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/io/NewLine.hpp>
 #include <ls-std/io/logging/Logger.hpp>
 #if defined(_MSC_VER) || defined(__APPLE__)
@@ -83,11 +83,7 @@ void ls::std::io::Logger::warn(const ls::std::core::type::byte *_data)
 
 void ls::std::io::Logger::_assignWriter(const ::std::shared_ptr<ls::std::core::interface_type::IWriter> &_writer)
 {
-  if (_writer == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_writer is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_writer, "writer reference is null!"}.evaluate();
   this->writer = _writer;
 }
 

+ 4 - 12
source/ls-std/io/xml/XmlDocument.cpp

@@ -3,11 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-30
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/io/xml/XmlDocument.hpp>
 
 ls::std::io::XmlDocument::XmlDocument() : ls::std::core::Class("XmlDocument")
@@ -54,20 +54,12 @@ void ls::std::io::XmlDocument::setRootElement(const ::std::shared_ptr<ls::std::i
 
 void ls::std::io::XmlDocument::_assignDeclaration(const ::std::shared_ptr<ls::std::io::XmlDeclaration> &_declaration)
 {
-  if (_declaration == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_declaration is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_declaration, "xml declaration reference is null!"}.evaluate();
   this->declaration = _declaration;
 }
 
 void ls::std::io::XmlDocument::_assignRootElement(const ::std::shared_ptr<ls::std::io::XmlNode> &_rootElement)
 {
-  if (_rootElement == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_rootElement is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_rootElement, "xml root node reference is null!"}.evaluate();
   this->rootElement = _rootElement;
 }

+ 13 - 28
source/ls-std/io/xml/XmlNode.cpp

@@ -9,7 +9,7 @@
 
 #include <algorithm>
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/io/xml/XmlNode.hpp>
 
 ls::std::io::XmlNode::XmlNode(::std::string _name) : ls::std::core::Class("XmlNode"), name(::std::move(_name))
@@ -21,7 +21,7 @@ bool ls::std::io::XmlNode::addAttributeAfter(const ::std::shared_ptr<ls::std::io
 {
   bool added{};
   auto iterator = this->attributes.begin();
-  _checkIfAttributeReferenceIsValid(_attribute);
+  ls::std::core::NullPointerArgumentEvaluator{_attribute, "passed attribute reference for add attempt is null!"}.evaluate();
   ls::std::core::EmptyStringArgumentEvaluator{_name, "xml node name is empty!"}.evaluate();
 
   if (!this->_hasAttribute(_attribute->getName()))
@@ -47,7 +47,7 @@ bool ls::std::io::XmlNode::addAttributeBefore(const ::std::shared_ptr<ls::std::i
 {
   bool added{};
   auto iterator = this->attributes.begin();
-  _checkIfAttributeReferenceIsValid(_attribute);
+  ls::std::core::NullPointerArgumentEvaluator{_attribute, "passed attribute reference for add attempt is null!"}.evaluate();
   ls::std::core::EmptyStringArgumentEvaluator{_name, "xml node name is empty!"}.evaluate();
 
   if (!this->_hasAttribute(_attribute->getName()))
@@ -71,7 +71,8 @@ bool ls::std::io::XmlNode::addAttributeBefore(const ::std::shared_ptr<ls::std::i
 bool ls::std::io::XmlNode::addAttributeToBeginning(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute)
 {
   bool added{};
-  _checkIfAttributeReferenceIsValid(_attribute);
+  ls::std::core::NullPointerArgumentEvaluator{_attribute, "passed attribute reference for add attempt is null!"}.evaluate();
+  ;
 
   if (!_hasAttribute(_attribute->getName()))
   {
@@ -85,7 +86,7 @@ bool ls::std::io::XmlNode::addAttributeToBeginning(const ::std::shared_ptr<ls::s
 bool ls::std::io::XmlNode::addAttributeToEnd(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute)
 {
   bool added{};
-  _checkIfAttributeReferenceIsValid(_attribute);
+  ls::std::core::NullPointerArgumentEvaluator{_attribute, "passed attribute reference for add attempt is null!"}.evaluate();
 
   if (!_hasAttribute(_attribute->getName()))
   {
@@ -100,8 +101,8 @@ bool ls::std::io::XmlNode::addChildAfter(const ::std::shared_ptr<ls::std::io::Xm
 {
   bool added{};
   auto iterator = this->children.begin();
-  _checkIfNodeReferenceIsValid(_child);
-  _checkIfNodeReferenceIsValid(_search);
+  ls::std::core::NullPointerArgumentEvaluator{_child, "passed child node reference for add attempt is null!"}.evaluate();
+  ls::std::core::NullPointerArgumentEvaluator{_search, "passed search node reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasChild(_child))
   {
@@ -126,8 +127,8 @@ bool ls::std::io::XmlNode::addChildBefore(const ::std::shared_ptr<ls::std::io::X
 {
   bool added{};
   auto iterator = this->children.begin();
-  _checkIfNodeReferenceIsValid(_child);
-  _checkIfNodeReferenceIsValid(_search);
+  ls::std::core::NullPointerArgumentEvaluator{_child, "passed child node reference for add attempt is null!"}.evaluate();
+  ls::std::core::NullPointerArgumentEvaluator{_search, "passed search node reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasChild(_child))
   {
@@ -150,7 +151,7 @@ bool ls::std::io::XmlNode::addChildBefore(const ::std::shared_ptr<ls::std::io::X
 bool ls::std::io::XmlNode::addChildToBeginning(const ::std::shared_ptr<ls::std::io::XmlNode> &_child)
 {
   bool added{};
-  _checkIfNodeReferenceIsValid(_child);
+  ls::std::core::NullPointerArgumentEvaluator{_child, "passed child node reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasChild(_child))
   {
@@ -164,7 +165,7 @@ bool ls::std::io::XmlNode::addChildToBeginning(const ::std::shared_ptr<ls::std::
 bool ls::std::io::XmlNode::addChildToEnd(const ::std::shared_ptr<ls::std::io::XmlNode> &_child)
 {
   bool added{};
-  _checkIfNodeReferenceIsValid(_child);
+  ls::std::core::NullPointerArgumentEvaluator{_child, "passed child node reference for add attempt is null!"}.evaluate();
 
   if (!this->_hasChild(_child))
   {
@@ -321,22 +322,6 @@ void ls::std::io::XmlNode::_assignValue(const ::std::string &_value)
   this->value = _value;
 }
 
-void ls::std::io::XmlNode::_checkIfAttributeReferenceIsValid(const ::std::shared_ptr<ls::std::io::XmlAttribute> &_attribute)
-{
-  if (_attribute == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_attribute is null"};
-  }
-}
-
-void ls::std::io::XmlNode::_checkIfNodeReferenceIsValid(const ::std::shared_ptr<ls::std::io::XmlNode> &_child)
-{
-  if (_child == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_child is null"};
-  }
-}
-
 std::string ls::std::io::XmlNode::_getTab(uint8_t _tabSize)
 {
   ::std::string tab{};
@@ -368,7 +353,7 @@ bool ls::std::io::XmlNode::_hasAttribute(const ::std::string &_name)
 
 bool ls::std::io::XmlNode::_hasChild(const ::std::shared_ptr<ls::std::io::XmlNode> &_child)
 {
-  _checkIfNodeReferenceIsValid(_child);
+  ls::std::core::NullPointerArgumentEvaluator{_child, "passed child node reference for check attempt is null!"}.evaluate();
   return ::std::find(this->children.begin(), this->children.end(), _child) != this->children.end();
 }
 

+ 3 - 7
source/ls-std/io/xml/XmlParseParameter.cpp

@@ -3,11 +3,11 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-05
-* Changed:         2023-02-07
+* Changed:         2023-02-08
 *
 * */
 
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/io/xml/XmlParseParameter.hpp>
 
 ls::std::io::XmlParseParameter::XmlParseParameter() = default;
@@ -36,10 +36,6 @@ void ls::std::io::XmlParseParameter::setNode(const ::std::shared_ptr<ls::std::io
 
 void ls::std::io::XmlParseParameter::_setNode(const ::std::shared_ptr<ls::std::io::XmlNode> &_node)
 {
-  if (_node == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_node is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_node, "passed node reference is null!"}.evaluate();
   this->node = _node;
 }

+ 3 - 7
source/ls-std/io/xml/XmlParser.cpp

@@ -3,11 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/io/xml/XmlParser.hpp>
 
 ls::std::io::XmlParser::XmlParser(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document) : ls::std::core::Class("XmlParser")
@@ -55,11 +55,7 @@ void ls::std::io::XmlParser::_analyze(const ls::std::core::type::byte_field &_da
 
 void ls::std::io::XmlParser::_assignDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document)
 {
-  if (_document == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_document is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_document, "passed document reference is null!"}.evaluate();
   this->document = _document;
 }
 

+ 3 - 6
source/ls-std/io/xml/XmlReader.cpp

@@ -3,10 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-10
- * Changed:         2023-02-07
+ * Changed:         2023-02-08
  *
  * */
 
+#include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 #include <ls-std/core/exception/IllegalArgumentException.hpp>
 #include <ls-std/io/FileReader.hpp>
 #include <ls-std/io/xml/XmlParser.hpp>
@@ -45,11 +46,7 @@ void ls::std::io::XmlReader::setFile(const ls::std::io::File &_xmlFile)
 
 void ls::std::io::XmlReader::_assignDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document)
 {
-  if (_document == nullptr)
-  {
-    throw ls::std::core::IllegalArgumentException{"_document is null"};
-  }
-
+  ls::std::core::NullPointerArgumentEvaluator{_document, "xml document reference is null!"}.evaluate();
   this->document = _document;
 }
 

+ 68 - 0
test/cases/core/evaluator/NullPointerArgumentEvaluatorTest.cpp

@@ -0,0 +1,68 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-02-08
+* Changed:         2023-02-08
+*
+* */
+
+#include <gtest/gtest.h>
+#include <ls-std/ls-std-core.hpp>
+#include <string>
+
+using namespace ls::std::core;
+using namespace ::std;
+
+namespace
+{
+  class NullPointerArgumentEvaluatorTest : public ::testing::Test
+  {
+    protected:
+
+      NullPointerArgumentEvaluatorTest() = default;
+      ~NullPointerArgumentEvaluatorTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(NullPointerArgumentEvaluatorTest, evaluate)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            NullPointerArgumentEvaluator{nullptr}.evaluate();
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            string message = _exception.what();
+            ASSERT_STREQ("IllegalArgumentException thrown - passed argument is null!", message.c_str());
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+
+  TEST_F(NullPointerArgumentEvaluatorTest, evaluate_dedicated_message)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            NullPointerArgumentEvaluator(nullptr, "this reference is null!").evaluate();
+          }
+          catch (const IllegalArgumentException &_exception)
+          {
+            string message = _exception.what();
+            ASSERT_STREQ("IllegalArgumentException thrown - this reference is null!", message.c_str());
+            throw;
+          }
+        },
+        IllegalArgumentException);
+  }
+}