Revision 2203db2b75f1728068a6e82a279c531b1abf307e authored by Lars Bilke on 26 July 2021, 09:13:09 UTC, committed by Lars Bilke on 26 July 2021, 09:37:44 UTC
1 parent f841b8a
Writer.cpp
/**
* \file
* \author Lars Bilke
* \date 2012-02-13
* \brief Implementation of the Writer class.
*
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "Writer.h"
#include <fstream>
#include <limits>
#include "BaseLib/Logging.h"
namespace BaseLib
{
namespace IO
{
Writer::Writer()
{
out.precision(std::numeric_limits<double>::digits10);
}
std::string Writer::writeToString()
{
// Empty stream and clear error states.
out.str("");
out.clear();
if (this->write())
{
return out.str();
}
return std::string("");
}
int writeStringToFile(std::string content,
std::filesystem::path const& file_path)
{
if (content.empty())
{
return 0;
}
std::ofstream fileStream;
fileStream.open(file_path.c_str());
// check file stream
if (!fileStream)
{
ERR("Could not open file '{:s}'!", file_path.string());
return 0;
}
fileStream << content;
fileStream.close();
return 1;
}
} // namespace IO
} // namespace BaseLib
Computing file changes ...