Эх сурвалжийг харах

Address SonarLint findings in XML like classes

Patrick-Christopher Mattulat 1 жил өмнө
parent
commit
185a66bb09

+ 4 - 4
include/ls-std/io/xml/XmlAttribute.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-23
- * Changed:         2023-02-22
+ * Changed:         2023-05-17
  *
  * */
 
@@ -23,11 +23,11 @@ namespace ls::std::io
       explicit XmlAttribute(const ::std::string &_name);
       ~XmlAttribute() noexcept override;
 
-      [[nodiscard]] ::std::string getName();
-      [[nodiscard]] ::std::string getValue();
+      [[nodiscard]] ::std::string getName() const;
+      [[nodiscard]] ::std::string getValue() const;
       void setName(const ::std::string &_name);
       void setValue(const ::std::string &_value);
-      [[nodiscard]] ::std::string toXml();
+      [[nodiscard]] ::std::string toXml() const;
 
     private:
 

+ 6 - 6
include/ls-std/io/xml/XmlDeclaration.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-27
- * Changed:         2023-02-22
+ * Changed:         2023-05-17
  *
  * */
 
@@ -23,13 +23,13 @@ namespace ls::std::io
       explicit XmlDeclaration(const ::std::string &_version);
       ~XmlDeclaration() noexcept override;
 
-      [[nodiscard]] ::std::string getEncoding();
-      [[nodiscard]] ::std::string getStandalone();
-      [[nodiscard]] ::std::string getVersion();
+      [[nodiscard]] ::std::string getEncoding() const;
+      [[nodiscard]] ::std::string getStandalone() const;
+      [[nodiscard]] ::std::string getVersion() const;
       void setEncoding(const ::std::string &_encoding);
       void setStandalone(const ::std::string &_standalone);
       void setVersion(const ::std::string &_version);
-      [[nodiscard]] ::std::string toXml();
+      [[nodiscard]] ::std::string toXml() const;
 
     private:
 
@@ -37,7 +37,7 @@ namespace ls::std::io
       ls::std::io::XmlAttribute standalone{"standalone"};
       ls::std::io::XmlAttribute version{"version"};
 
-      [[nodiscard]] static ::std::string _toXmlAttribute(ls::std::io::XmlAttribute _attribute);
+      [[nodiscard]] static ::std::string _toXmlAttribute(const ls::std::io::XmlAttribute &_attribute);
   };
 }
 

+ 4 - 4
include/ls-std/io/xml/XmlDocument.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-27
- * Changed:         2023-02-22
+ * Changed:         2023-05-17
  *
  * */
 
@@ -25,11 +25,11 @@ namespace ls::std::io
       XmlDocument();
       ~XmlDocument() noexcept override;
 
-      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlDeclaration> getDeclaration();
-      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlNode> getRootElement();
+      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlDeclaration> getDeclaration() const;
+      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlNode> getRootElement() const;
       void setDeclaration(const ::std::shared_ptr<ls::std::io::XmlDeclaration> &_declaration);
       void setRootElement(const ::std::shared_ptr<ls::std::io::XmlNode> &_rootElement);
-      [[nodiscard]] ::std::string toXml();
+      [[nodiscard]] ::std::string toXml() const;
 
     private:
 

+ 2 - 2
include/ls-std/io/xml/XmlParseParameter.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-17
- * Changed:         2023-02-22
+ * Changed:         2023-05-17
  *
  * */
 
@@ -25,7 +25,7 @@ namespace ls::std::io
       ~XmlParseParameter();
 
       [[nodiscard]] uint8_t getLevel() const;
-      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlNode> getNode();
+      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlNode> getNode() const;
       void setLevel(const uint8_t &_level);
       void setNode(const ::std::shared_ptr<ls::std::io::XmlNode> &_node);
 

+ 4 - 4
include/ls-std/io/xml/XmlReader.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-08
- * Changed:         2023-02-22
+ * Changed:         2023-05-17
  *
  * */
 
@@ -34,17 +34,17 @@ namespace ls::std::io
 
       // additional functionality
 
-      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlDocument> getDocument();
+      [[nodiscard]] ::std::shared_ptr<ls::std::io::XmlDocument> getDocument() const;
       void setDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document);
       void setFile(const ls::std::io::File &_xmlFile);
 
     private:
 
       ::std::shared_ptr<ls::std::io::XmlDocument> document{};
-      ls::std::io::File xmlFile;
+      ls::std::io::File xmlFile = ls::std::io::File{""};
 
       void _assignDocument(const ::std::shared_ptr<ls::std::io::XmlDocument> &_document);
-      void _assignFile(ls::std::io::File _xmlFile);
+      void _assignFile(const ls::std::io::File &_xmlFile);
   };
 }
 

+ 4 - 4
source/ls-std/io/xml/XmlAttribute.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-23
- * Changed:         2023-02-23
+ * Changed:         2023-05-17
  *
  * */
 
@@ -22,12 +22,12 @@ XmlAttribute::XmlAttribute(const string &_name) : Class("XmlAttribute")
 
 XmlAttribute::~XmlAttribute() noexcept = default;
 
-string XmlAttribute::getName()
+string XmlAttribute::getName() const
 {
   return this->name;
 }
 
-string XmlAttribute::getValue()
+string XmlAttribute::getValue() const
 {
   return this->value;
 }
@@ -42,7 +42,7 @@ void XmlAttribute::setValue(const string &_value)
   this->_assignValue(_value);
 }
 
-string XmlAttribute::toXml()
+string XmlAttribute::toXml() const
 {
   return this->name + "=\"" + this->value + "\"";
 }

+ 6 - 6
source/ls-std/io/xml/XmlDeclaration.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-29
- * Changed:         2023-02-23
+ * Changed:         2023-05-17
  *
  * */
 
@@ -20,17 +20,17 @@ XmlDeclaration::XmlDeclaration(const string &_version) : ls::std::core::Class("X
 
 XmlDeclaration::~XmlDeclaration() noexcept = default;
 
-string XmlDeclaration::getEncoding()
+string XmlDeclaration::getEncoding() const
 {
   return this->encoding.getValue();
 }
 
-string XmlDeclaration::getStandalone()
+string XmlDeclaration::getStandalone() const
 {
   return this->standalone.getValue();
 }
 
-string XmlDeclaration::getVersion()
+string XmlDeclaration::getVersion() const
 {
   return this->version.getValue();
 }
@@ -50,7 +50,7 @@ void XmlDeclaration::setVersion(const string &_version)
   this->version.setValue(_version);
 }
 
-string XmlDeclaration::toXml()
+string XmlDeclaration::toXml() const
 {
   string declaration = "<?xml";
 
@@ -61,7 +61,7 @@ string XmlDeclaration::toXml()
   return declaration + " ?>";
 }
 
-string XmlDeclaration::_toXmlAttribute(XmlAttribute _attribute)
+string XmlDeclaration::_toXmlAttribute(const XmlAttribute &_attribute)
 {
   string xmlString{};
 

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

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-30
- * Changed:         2023-02-23
+ * Changed:         2023-05-17
  *
  * */
 
@@ -23,12 +23,12 @@ XmlDocument::XmlDocument() : Class("XmlDocument")
 
 XmlDocument::~XmlDocument() noexcept = default;
 
-shared_ptr<XmlDeclaration> XmlDocument::getDeclaration()
+shared_ptr<XmlDeclaration> XmlDocument::getDeclaration() const
 {
   return this->declaration;
 }
 
-shared_ptr<XmlNode> XmlDocument::getRootElement()
+shared_ptr<XmlNode> XmlDocument::getRootElement() const
 {
   return this->rootElement;
 }
@@ -43,7 +43,7 @@ void XmlDocument::setRootElement(const shared_ptr<XmlNode> &_rootElement)
   this->_assignRootElement(_rootElement);
 }
 
-string XmlDocument::toXml()
+string XmlDocument::toXml() const
 {
   string xmlString{};
 

+ 2 - 2
source/ls-std/io/xml/XmlParseParameter.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-05
-* Changed:         2023-02-23
+* Changed:         2023-05-17
 *
 * */
 
@@ -24,7 +24,7 @@ uint8_t XmlParseParameter::getLevel() const
   return this->level;
 }
 
-shared_ptr<XmlNode> XmlParseParameter::getNode()
+shared_ptr<XmlNode> XmlParseParameter::getNode() const
 {
   return this->node;
 }

+ 4 - 4
source/ls-std/io/xml/XmlReader.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-10
- * Changed:         2023-02-23
+ * Changed:         2023-05-17
  *
  * */
 
@@ -25,7 +25,7 @@ using ls::std::io::XmlReader;
 using std::shared_ptr;
 using std::string;
 
-XmlReader::XmlReader(const shared_ptr<XmlDocument> &_document, const string &_absolutePath) : Class("XmlReader"), xmlFile(File{""})
+XmlReader::XmlReader(const shared_ptr<XmlDocument> &_document, const string &_absolutePath) : Class("XmlReader")
 {
   this->_assignDocument(_document);
   this->_assignFile(File{_absolutePath});
@@ -41,7 +41,7 @@ byte_field XmlReader::read()
   return data;
 }
 
-shared_ptr<XmlDocument> XmlReader::getDocument()
+shared_ptr<XmlDocument> XmlReader::getDocument() const
 {
   return this->document;
 }
@@ -62,7 +62,7 @@ void XmlReader::_assignDocument(const shared_ptr<XmlDocument> &_document)
   this->document = _document;
 }
 
-void XmlReader::_assignFile(File _xmlFile)
+void XmlReader::_assignFile(const File &_xmlFile)
 {
   if (!_xmlFile.exists())
   {

+ 2 - 3
test/cases/io/xml/XmlDocumentTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-30
- * Changed:         2023-03-25
+ * Changed:         2023-05-17
  *
  * */
 
@@ -47,8 +47,7 @@ namespace
     XmlDocument document{};
     ASSERT_TRUE(document.getDeclaration() == nullptr);
 
-    XmlDeclaration declaration{"1.0"};
-    document.setDeclaration(make_shared<XmlDeclaration>(declaration));
+    document.setDeclaration(make_shared<XmlDeclaration>(XmlDeclaration{"1.0"}));
     ASSERT_TRUE(document.getDeclaration() != nullptr);
     ASSERT_STREQ("1.0", document.getDeclaration()->getVersion().c_str());
   }

+ 3 - 3
test/cases/io/xml/XmlReaderTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-10
- * Changed:         2023-03-25
+ * Changed:         2023-05-17
  *
  * */
 
@@ -51,7 +51,7 @@ namespace
   TEST_F(XmlReaderTest, setDocument)
   {
     string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
-    shared_ptr<XmlDocument> document = make_shared<XmlDocument>();
+    auto document = make_shared<XmlDocument>();
     XmlReader xmlReader{document, xmlPath};
     ASSERT_TRUE(xmlReader.getDocument() == document);
 
@@ -63,7 +63,7 @@ namespace
   TEST_F(XmlReaderTest, setDocument_no_reference)
   {
     string xmlPath = TestHelper::getResourcesFolderLocation() + "state-machine-test.xml";
-    shared_ptr<XmlDocument> document = make_shared<XmlDocument>();
+    auto document = make_shared<XmlDocument>();
     XmlReader xmlReader{document, xmlPath};
 
     EXPECT_THROW(