From d85f4695bfa65e817ee023e748a869421f692827 Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 6 Jun 2019 17:52:47 +0200 Subject: [PATCH] make capabilities a compile-time test whether backup-restore functionality can be used --- src/amdis/ProblemStat.inc.hpp | 42 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index 0a942639..deacf75c 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -479,16 +479,26 @@ writeFiles(AdaptInfo& adaptInfo, bool force) } +template ::backup(std::declval(), std::string("")))> +void backup_impl(Grid const& grid, GridView const& gv, std::string filename, std::true_type) +{ + Dune::BackupRestoreFacility::backup(grid, filename); +} + +template ::backup(std::declval(), std::string("")))> +void backup_impl(Grid const& grid, GridView const& gv, std::string filename, bool_t) +{ + warning("Falling back to backup of gridview."); + BackupRestoreByGridFactory::backup(gv, filename); +} + template void ProblemStat:: backup(std::string const& filename) const { - if (Dune::Capabilities::hasBackupRestoreFacilities::v) - Dune::BackupRestoreFacility::backup(*grid_, filename); - else { - warning("Falling back to backup of gridview."); - BackupRestoreByGridFactory::backup(gridView(), filename); - } + backup_impl(*grid_, gridView(), filename, bool_t::v>{}); } @@ -510,16 +520,26 @@ backup(AdaptInfo& adaptInfo) } +template ::restore(std::string("")))> +auto restore_impl(std::string filename, std::true_type) +{ + return Dune::BackupRestoreFacility::restore(filename); +} + +template ::restore(std::string("")))> +auto restore_impl(std::string filename, bool_t) +{ + return BackupRestoreByGridFactory::restore(filename); +} + template auto ProblemStat:: restore(std::string const& filename) { // restore grid from file - std::unique_ptr grid; - if (Dune::Capabilities::hasBackupRestoreFacilities::v) - grid.reset(Dune::BackupRestoreFacility::restore(filename)); - else - grid.reset(BackupRestoreByGridFactory::restore(filename)); + std::unique_ptr grid(restore_impl(filename, bool_t::v>{})); return std::move(grid); } -- GitLab