From 8fc815854a039f16fa6c0639a8a7626861092446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Mon, 10 Feb 2025 15:01:40 +0100 Subject: [PATCH 1/2] [Core] Minor change in `FileSerializer` --- kratos/includes/file_serializer.h | 97 ++++++++++++++++++------------ kratos/sources/file_serializer.cpp | 34 +++++++++++ 2 files changed, 92 insertions(+), 39 deletions(-) create mode 100644 kratos/sources/file_serializer.cpp diff --git a/kratos/includes/file_serializer.h b/kratos/includes/file_serializer.h index 72732bb182f2..440d7304b754 100644 --- a/kratos/includes/file_serializer.h +++ b/kratos/includes/file_serializer.h @@ -4,62 +4,81 @@ // _|\_\_| \__,_|\__|\___/ ____/ // Multi-Physics // -// License: BSD License -// Kratos default license: kratos/license.txt +// License: BSD License +// Kratos default license: kratos/license.txt // // Main authors: Pooyan Dadvand // -// -#if !defined(KRATOS_FILE_SERIALIZER_H_INCLUDED ) -#define KRATOS_FILE_SERIALIZER_H_INCLUDED +#pragma once // System includes -#include -#include -#include // External includes // Project includes -#include "includes/define.h" #include "includes/serializer.h" namespace Kratos { - //This class provides a simpler interface for serialization to a file - // Note that you may not override any load or save method of the Serializer. They are not virtual - class FileSerializer : public Serializer - { - public: - KRATOS_CLASS_POINTER_DEFINITION(FileSerializer); +///@name Kratos Classes +///@{ +/** + * @class FileSerializer + * @ingroup KratosCore + * @brief This class provides a simplified interface for serializing data to a file. + * @details Note that you may not override any load or save method of the Serializer base class, as they are not virtual. + * @author Pooyan Dadvand + */ +class FileSerializer + : public Serializer +{ +public: + ///@name Type Definitions + ///@{ - ///this constructor simply wraps the standard Serializer and defines output to basic_iostream - ///@param rTrace type of serialization to be employed - FileSerializer(std::string const& Filename, Serializer::TraceType const& rTrace=SERIALIZER_NO_TRACE) - : Serializer(nullptr, rTrace) - { - std::fstream* p_file = new std::fstream(std::string(Filename+".rest").c_str(), std::ios::binary|std::ios::in|std::ios::out); - if(!(*p_file)) - { - delete p_file; - p_file = new std::fstream(std::string(Filename+".rest").c_str(), std::ios::binary|std::ios::out); - } - SetBuffer( p_file ); - KRATOS_ERROR_IF_NOT(*pGetBuffer()) << "Error opening input file : " - << std::string(Filename+".rest") << std::endl; - } + /// Pointer definition of Condition + KRATOS_CLASS_POINTER_DEFINITION(FileSerializer); - virtual ~FileSerializer(){} + ///@} + ///@name Life Cycle + ///@{ - private: + /** + * @brief Constructor that initializes the FileSerializer. + * @param Filename The name of the file for serialization. + * @param rTrace Type of serialization trace to be employed (default: SERIALIZER_NO_TRACE). + */ + FileSerializer(std::string const& Filename, Serializer::TraceType const& rTrace = SERIALIZER_NO_TRACE); - /// Assignment operator. - FileSerializer& operator=(FileSerializer const& rOther) = delete; + /** + * @brief Destructor + */ + ~FileSerializer() override {} - /// Copy constructor. - FileSerializer(FileSerializer const& rOther) = delete; - }; -} + ///@} +private: + ///@name Private Operators + ///@{ + + /** + * @brief Deleted assignment operator to prevent unwanted copying. + * @param rOther Another instance of FileSerializer to assign from. + * @return FileSerializer& Reference to the assigned FileSerializer object. + */ + FileSerializer& operator=(FileSerializer const& rOther) = delete; -#endif // KRATOS_FILE_SERIALIZER_H_INCLUDED defined + ///@} + ///@name Private Life Cycle + ///@{ + + /** + * @brief Deleted copy constructor to prevent unwanted copying. + * @param rOther Another instance of FileSerializer to construct from. + */ + FileSerializer(FileSerializer const& rOther) = delete; + + ///@} +}; +///@} +} diff --git a/kratos/sources/file_serializer.cpp b/kratos/sources/file_serializer.cpp new file mode 100644 index 000000000000..c65c1be6ad98 --- /dev/null +++ b/kratos/sources/file_serializer.cpp @@ -0,0 +1,34 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Pooyan Dadvand +// + +// System includes + +// External includes + +// Project includes +#include "includes/file_serializer.h" + +namespace Kratos +{ +FileSerializer::FileSerializer(std::string const& Filename, Serializer::TraceType const& rTrace) + : Serializer(nullptr, rTrace) +{ + std::fstream* p_file = new std::fstream(std::string(Filename+".rest").c_str(), std::ios::binary|std::ios::in|std::ios::out); + if(!(*p_file)) { + delete p_file; + p_file = new std::fstream(std::string(Filename+".rest").c_str(), std::ios::binary|std::ios::out); + } + SetBuffer( p_file ); + KRATOS_ERROR_IF_NOT(*pGetBuffer()) << "Error opening input file : " + << std::string(Filename+".rest") << std::endl; +} +} \ No newline at end of file From 60246f88733df207aa560ab8a4e1f8e2ee138fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Mon, 10 Feb 2025 17:17:07 +0100 Subject: [PATCH 2/2] Missing KRATOS_API(KRATOS_CORE) --- kratos/includes/file_serializer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kratos/includes/file_serializer.h b/kratos/includes/file_serializer.h index 440d7304b754..e067990be3e6 100644 --- a/kratos/includes/file_serializer.h +++ b/kratos/includes/file_serializer.h @@ -30,7 +30,7 @@ namespace Kratos * @details Note that you may not override any load or save method of the Serializer base class, as they are not virtual. * @author Pooyan Dadvand */ -class FileSerializer +class KRATOS_API(KRATOS_CORE) FileSerializer : public Serializer { public: