46 const std::shared_ptr<EquationSystem> &pEquation)
47 : m_session(pSession), m_equ(pEquation)
62 bool root =
m_session->GetComm()->TreatAsRankZero();
67 auto it = pParams.find(
"OutputFile");
68 if (it == pParams.end())
74 ASSERTL0(it->second.length() > 0,
"Missing parameter 'OutputFile'.");
79 outname = fs::path(outname).replace_extension(
"").string() + ext;
80 fs::path specPath(outname);
83 if (backup && root && fs::exists(specPath))
88 fs::path bakPath = specPath;
90 while (fs::exists(bakPath))
92 bakPath = specPath.parent_path();
94 bakPath += specPath.stem();
95 bakPath += fs::path(
".bak" + std::to_string(cnt++));
96 bakPath += specPath.extension();
98 std::cout <<
"renaming " << specPath <<
" -> " << bakPath << std::endl;
101 fs::rename(specPath, bakPath);
103 catch (fs::filesystem_error &e)
105 ASSERTL0(e.code() == std::errc::no_such_file_or_directory,
106 "Filesystem error: " + std::string(e.what()));
113 const std::string inname)
119 bool root =
m_session->GetComm()->TreatAsRankZero();
122 std::string outname = inname;
125 outname = fs::path(outname).replace_extension(
"").string() + ext;
127 fs::path specPath(outname);
131 if (backup && root && fs::exists(specPath))
137 fs::path bakPath = specPath;
139 while (fs::exists(bakPath))
141 bakPath = specPath.parent_path();
143 bakPath += specPath.stem();
144 bakPath += fs::path(
".bak" + std::to_string(cnt++));
145 bakPath += specPath.extension();
147 std::cout <<
"renaming " << specPath <<
" -> " << bakPath << std::endl;
150 fs::rename(specPath, bakPath);
152 catch (fs::filesystem_error &e)
154 ASSERTL0(e.code() == std::errc::no_such_file_or_directory,
155 "Filesystem error: " + std::string(e.what()));
#define ASSERTL0(condition, msg)
Provides a generic Factory class.
LibUtilities::SessionReaderSharedPtr m_session
SOLVER_UTILS_EXPORT Filter(const LibUtilities::SessionReaderSharedPtr &pSession, const std::shared_ptr< EquationSystem > &pEquation)
virtual SOLVER_UTILS_EXPORT ~Filter()
std::map< std::string, std::string > ParamMap
virtual SOLVER_UTILS_EXPORT std::string v_SetupOutput(const std::string ext, const ParamMap &pParams)
static std::string PortablePath(const fs::path &path)
create portable path on different platforms for std::filesystem path.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
FilterFactory & GetFilterFactory()