diff --git a/include/aman/config/FileFormat.h b/include/aman/config/FileFormat.h new file mode 100644 index 0000000..241a87f --- /dev/null +++ b/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 + * @copyright Copyright 2021 Sven Czarnian + * @license This project is published under the GNU General Public License v3 (GPLv3) + */ + +#pragma once + +#include +#include + +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; + }; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83e1bf7..86807c0 100644 --- a/src/CMakeLists.txt +++ b/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}) diff --git a/src/config/FileFormat.cpp b/src/config/FileFormat.cpp new file mode 100644 index 0000000..8508c18 --- /dev/null +++ b/src/config/FileFormat.cpp @@ -0,0 +1,37 @@ +/* + * Author: + * Sven Czarnian + * Brief: + * Implements the generic file format + * Copyright: + * 2021 Sven Czarnian + * License: + * GNU General Public License v3 (GPLv3) + */ + +#include + +#include + +using namespace aman; + +FileFormat::FileFormat() noexcept : + m_errorLine(std::numeric_limits::max()), + m_errorMessage() { } + +void FileFormat::reset() noexcept { + this->m_errorLine = std::numeric_limits::max(); + this->m_errorMessage.clear(); +} + +bool FileFormat::errorFound() const noexcept { + return std::numeric_limits::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; +}