Browse Source

Improve member access in Exception class

Patrick-Christopher Mattulat 11 months ago
parent
commit
820ccb73e3

+ 2 - 2
include/ls-std/core/exception/EventNotHandledException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-27
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       EventNotHandledException();
-      explicit EventNotHandledException(::std::string _message);
+      explicit EventNotHandledException(const ::std::string &_message);
       ~EventNotHandledException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/EventNotSubscribedException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-27
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       EventNotSubscribedException();
-      explicit EventNotSubscribedException(::std::string _message);
+      explicit EventNotSubscribedException(const ::std::string &_message);
       ~EventNotSubscribedException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 8 - 3
include/ls-std/core/exception/Exception.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-22
-* Changed:         2023-03-28
+* Changed:         2023-05-19
 *
 * */
 
@@ -13,6 +13,7 @@
 #include <exception>
 #include <ls-std/os/dynamic-goal.hpp>
 #include <string>
+#include <string_view>
 
 namespace ls::std::core
 {
@@ -28,10 +29,14 @@ namespace ls::std::core
 
     protected:
 
+      [[nodiscard]] const char *_getIdentifiedMessage(const ::std::string &_defaultMessage) const;
+      [[nodiscard]] ::std::string _getMessage() const;
+      void _setMessage(::std::string_view _message);
+
+    private:
+
       ::std::string message{};
       ::std::string name{};
-
-      [[nodiscard]] const char *_getIdentifiedMessage(const ::std::string &_defaultMessage) const;
   };
 }
 

+ 2 - 2
include/ls-std/core/exception/FileNotFoundException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-17
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       FileNotFoundException();
-      explicit FileNotFoundException(::std::string _message);
+      explicit FileNotFoundException(const ::std::string &_message);
       ~FileNotFoundException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/FileOperationException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-15
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       FileOperationException();
-      explicit FileOperationException(::std::string _message);
+      explicit FileOperationException(const ::std::string &_message);
       ~FileOperationException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/IllegalArgumentException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       IllegalArgumentException();
-      explicit IllegalArgumentException(::std::string _message);
+      explicit IllegalArgumentException(const ::std::string &_message);
       ~IllegalArgumentException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/IllegalArithmeticOperationException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       IllegalArithmeticOperationException();
-      explicit IllegalArithmeticOperationException(::std::string _message);
+      explicit IllegalArithmeticOperationException(const ::std::string &_message);
       ~IllegalArithmeticOperationException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/IncompleteJsonException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-04-30
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       IncompleteJsonException();
-      explicit IncompleteJsonException(::std::string _message);
+      explicit IncompleteJsonException(const ::std::string &_message);
       ~IncompleteJsonException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/IndexOutOfBoundsException.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-10
-* Changed:         2023-02-22
+* Changed:         2023-05-19
 *
 * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       IndexOutOfBoundsException();
-      explicit IndexOutOfBoundsException(::std::string _message);
+      explicit IndexOutOfBoundsException(const ::std::string &_message);
       ~IndexOutOfBoundsException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/NotImplementedException.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-27
-* Changed:         2023-03-27
+* Changed:         2023-05-19
 *
 * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       NotImplementedException();
-      explicit NotImplementedException(::std::string _message);
+      explicit NotImplementedException(const ::std::string &_message);
       ~NotImplementedException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 2 - 2
include/ls-std/core/exception/NullPointerException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-06
- * Changed:         2023-02-22
+ * Changed:         2023-05-19
  *
  * */
 
@@ -21,7 +21,7 @@ namespace ls::std::core
     public:
 
       NullPointerException();
-      explicit NullPointerException(::std::string _message);
+      explicit NullPointerException(const ::std::string &_message);
       ~NullPointerException() noexcept override;
 
       [[nodiscard]] const char *what() const noexcept override;

+ 3 - 3
source/ls-std/core/exception/EventNotHandledException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 EventNotHandledException::EventNotHandledException() : Exception("EventNotHandledException")
 {}
 
-EventNotHandledException::EventNotHandledException(string _message) : EventNotHandledException()
+EventNotHandledException::EventNotHandledException(const string &_message) : EventNotHandledException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 EventNotHandledException::~EventNotHandledException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/EventNotSubscribedException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 EventNotSubscribedException::EventNotSubscribedException() : Exception("EventNotSubscribedException")
 {}
 
-EventNotSubscribedException::EventNotSubscribedException(string _message) : EventNotSubscribedException()
+EventNotSubscribedException::EventNotSubscribedException(const string &_message) : EventNotSubscribedException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 EventNotSubscribedException::~EventNotSubscribedException() noexcept = default;

+ 12 - 1
source/ls-std/core/exception/Exception.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-22
-* Changed:         2023-03-28
+* Changed:         2023-05-19
 *
 * */
 
@@ -13,6 +13,7 @@
 using ls::std::core::Exception;
 using std::move;
 using std::string;
+using std::string_view;
 
 Exception::Exception(string _name) : name(::move(_name))
 {}
@@ -39,3 +40,13 @@ const char *Exception::_getIdentifiedMessage(const string &_defaultMessage) cons
 
   return ExceptionMessage{concatenatedMessage}.toCharacterPointer();
 }
+
+string Exception::_getMessage() const
+{
+  return this->message;
+}
+
+void Exception::_setMessage(string_view _message)
+{
+  this->message = _message;
+}

+ 3 - 3
source/ls-std/core/exception/FileNotFoundException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 FileNotFoundException::FileNotFoundException() : Exception("FileNotFoundException")
 {}
 
-FileNotFoundException::FileNotFoundException(string _message) : FileNotFoundException()
+FileNotFoundException::FileNotFoundException(const string &_message) : FileNotFoundException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 FileNotFoundException::~FileNotFoundException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/FileOperationException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 FileOperationException::FileOperationException() : Exception("FileOperationException")
 {}
 
-FileOperationException::FileOperationException(string _message) : FileOperationException()
+FileOperationException::FileOperationException(const string &_message) : FileOperationException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 FileOperationException::~FileOperationException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/IllegalArgumentException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 IllegalArgumentException::IllegalArgumentException() : Exception("IllegalArgumentException")
 {}
 
-IllegalArgumentException::IllegalArgumentException(string _message) : IllegalArgumentException()
+IllegalArgumentException::IllegalArgumentException(const string &_message) : IllegalArgumentException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 IllegalArgumentException::~IllegalArgumentException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/IllegalArithmeticOperationException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 IllegalArithmeticOperationException::IllegalArithmeticOperationException() : Exception("IllegalArithmeticOperationException")
 {}
 
-IllegalArithmeticOperationException::IllegalArithmeticOperationException(string _message) : IllegalArithmeticOperationException()
+IllegalArithmeticOperationException::IllegalArithmeticOperationException(const string &_message) : IllegalArithmeticOperationException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 IllegalArithmeticOperationException::~IllegalArithmeticOperationException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/IncompleteJsonException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 IncompleteJsonException::IncompleteJsonException() : Exception("IncompleteJsonException")
 {}
 
-IncompleteJsonException::IncompleteJsonException(string _message) : IncompleteJsonException()
+IncompleteJsonException::IncompleteJsonException(const string &_message) : IncompleteJsonException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 IncompleteJsonException::~IncompleteJsonException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/IndexOutOfBoundsException.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-10
-* Changed:         2023-03-28
+* Changed:         2023-05-19
 *
 * */
 
@@ -18,9 +18,9 @@ using std::string;
 IndexOutOfBoundsException::IndexOutOfBoundsException() : Exception("IndexOutOfBoundsException")
 {}
 
-IndexOutOfBoundsException::IndexOutOfBoundsException(string _message) : IndexOutOfBoundsException()
+IndexOutOfBoundsException::IndexOutOfBoundsException(const string &_message) : IndexOutOfBoundsException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 IndexOutOfBoundsException::~IndexOutOfBoundsException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/NotImplementedException.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-27
-* Changed:         2023-03-28
+* Changed:         2023-05-19
 *
 * */
 
@@ -20,9 +20,9 @@ using std::string;
 NotImplementedException::NotImplementedException() : Exception("NotImplementedException")
 {}
 
-NotImplementedException::NotImplementedException(string _message) : NotImplementedException()
+NotImplementedException::NotImplementedException(const string &_message) : NotImplementedException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 NotImplementedException::~NotImplementedException() noexcept = default;

+ 3 - 3
source/ls-std/core/exception/NullPointerException.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2023-02-04
- * Changed:         2023-03-28
+ * Changed:         2023-05-19
  *
  * */
 
@@ -18,9 +18,9 @@ using std::string;
 NullPointerException::NullPointerException() : Exception("NullPointerException")
 {}
 
-NullPointerException::NullPointerException(string _message) : NullPointerException()
+NullPointerException::NullPointerException(const string &_message) : NullPointerException()
 {
-  this->message = ::move(_message);
+  this->_setMessage(_message);
 }
 
 NullPointerException::~NullPointerException() noexcept = default;