Explorar el Código

define the base class to define different file formats

Sven Czarnian hace 3 años
padre
commit
163786698c
Se han modificado 3 ficheros con 99 adiciones y 0 borrados
  1. 53 0
      include/aman/config/FileFormat.h
  2. 9 0
      src/CMakeLists.txt
  3. 37 0
      src/config/FileFormat.cpp

+ 53 - 0
include/aman/config/FileFormat.h

@@ -0,0 +1,53 @@
+/*
+ * @brief Defines the base class for all file formats
+ * @file aman/config/FileFormat.h
+ * @author Sven Czarnian <devel@svcz.de>
+ * @copyright Copyright 2021 Sven Czarnian
+ * @license This project is published under the GNU General Public License v3 (GPLv3)
+ */
+
+#pragma once
+
+#include <cstdint>
+#include <string>
+
+namespace aman {
+    /**
+     * @brief Defines the base class for all file formats
+     * @ingroup format
+     *
+     * The base class provides error information, etc.
+     */
+    class FileFormat {
+    protected:
+        std::uint32_t m_errorLine;    /**< Defines the line number if a parser detected an error */
+        std::string   m_errorMessage; /**< Defines the descriptive error message */
+
+        /**
+         * @brief Creates the default file format
+         */
+        FileFormat() noexcept;
+
+        /**
+         * @brief Resets the internal structures
+         */
+        void reset() noexcept;
+
+    public:
+        /**
+         * @brief Checks if an error was found
+         * @return True if an error was found, else false
+         */
+        bool errorFound() const noexcept;
+        /**
+         * @brief Returns the error line
+         * @return The error line
+         */
+        std::uint32_t errorLine() const noexcept;
+        /**
+         * @brief Returns the error message
+         * @return The error message
+         */
+        const std::string& errorMessage() const noexcept;
+    };
+}

+ 9 - 0
src/CMakeLists.txt

@@ -14,11 +14,17 @@ SET(SOURCE_FILES
     stdafx.cpp
     stdafx.h
 )
+SET(SOURCE_CONFIG_FILES
+    config/FileFormat.cpp
+)
 SET(SOURCE_FILES_RES
     ${CMAKE_BINARY_DIR}/ArrivalMANager.rc
     ${CMAKE_SOURCE_DIR}/res/resource.h
     ${CMAKE_SOURCE_DIR}/res/targetver.h
 )
+SET(INCLUDE_CONFIG_FILES
+    ${CMAKE_SOURCE_DIR}/include/aman/config/FileFormat.h
+)
 SET(INCLUDE_HELPER_FILES
     ${CMAKE_SOURCE_DIR}/include/aman/helper/String.h
 )
@@ -27,7 +33,9 @@ SET(INCLUDE_HELPER_FILES
 ADD_LIBRARY(
     ArrivalMANager SHARED
         ${SOURCE_FILES_RES}
+        ${SOURCE_CONFIG_FILES}
         ${SOURCE_FILES}
+        ${INCLUDE_CONFIG_FILES}
         ${INCLUDE_HELPER_FILES}
 )
 
@@ -50,4 +58,5 @@ ENDIF()
 
 SOURCE_GROUP("Source Files" FILES ${SOURCE_FILES})
 SOURCE_GROUP("Source Files\\res" FILES ${SOURCE_FILES_RES})
+SOURCE_GROUP("Header Files\\config" FILES ${INCLUDE_CONFIG_FILES})
 SOURCE_GROUP("Header Files\\helper" FILES ${INCLUDE_HELPER_FILES})

+ 37 - 0
src/config/FileFormat.cpp

@@ -0,0 +1,37 @@
+/*
+ * Author:
+ *   Sven Czarnian <devel@svcz.de>
+ * Brief:
+ *   Implements the generic file format
+ * Copyright:
+ *   2021 Sven Czarnian
+ * License:
+ *   GNU General Public License v3 (GPLv3)
+ */
+
+#include <limits>
+
+#include <aman/config/FileFormat.h>
+
+using namespace aman;
+
+FileFormat::FileFormat() noexcept :
+        m_errorLine(std::numeric_limits<std::uint32_t>::max()),
+        m_errorMessage() { }
+
+void FileFormat::reset() noexcept {
+    this->m_errorLine = std::numeric_limits<std::uint32_t>::max();
+    this->m_errorMessage.clear();
+}
+
+bool FileFormat::errorFound() const noexcept {
+    return std::numeric_limits<std::uint32_t>::max() != this->m_errorLine;
+}
+
+std::uint32_t FileFormat::errorLine() const noexcept {
+    return this->m_errorLine;
+}
+
+const std::string& FileFormat::errorMessage() const noexcept {
+    return this->m_errorMessage;
+}