From f9f13143a2a5d474b624658845416b3f96e4955a Mon Sep 17 00:00:00 2001 From: Robert Kloefkorn Date: Mon, 21 Mar 2016 10:53:54 +0100 Subject: [PATCH] SimulatorTimers: added method clone to allow for copying of the objects. --- opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp | 9 +++++++++ opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp | 3 +++ opm/simulators/timestepping/SimulatorTimer.cpp | 8 ++++++++ opm/simulators/timestepping/SimulatorTimer.hpp | 3 +++ opm/simulators/timestepping/SimulatorTimerInterface.hpp | 3 +++ 5 files changed, 26 insertions(+) diff --git a/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp b/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp index 9b2737d74..d64d47cea 100644 --- a/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp +++ b/opm/simulators/timestepping/AdaptiveSimulatorTimer.cpp @@ -153,4 +153,13 @@ namespace Opm return start_date_time_; } + /// return copy of object + std::unique_ptr< SimulatorTimerInterface > + AdaptiveSimulatorTimer::clone() const + { + return std::unique_ptr< SimulatorTimerInterface > (new AdaptiveSimulatorTimer( *this )); + } + + + } // namespace Opm diff --git a/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp b/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp index ac4bb6ed1..be93f3047 100644 --- a/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp +++ b/opm/simulators/timestepping/AdaptiveSimulatorTimer.hpp @@ -93,6 +93,9 @@ namespace Opm /// \brief start date time of simulation boost::posix_time::ptime startDateTime() const; + /// return copy of object + virtual std::unique_ptr< SimulatorTimerInterface > clone() const; + protected: const boost::posix_time::ptime start_date_time_; const double start_time_; diff --git a/opm/simulators/timestepping/SimulatorTimer.cpp b/opm/simulators/timestepping/SimulatorTimer.cpp index 2dc2f295f..c5a58749a 100644 --- a/opm/simulators/timestepping/SimulatorTimer.cpp +++ b/opm/simulators/timestepping/SimulatorTimer.cpp @@ -148,5 +148,13 @@ namespace Opm return int(timesteps_.size()) == current_step_; } + /// return copy of object + std::unique_ptr< SimulatorTimerInterface > + SimulatorTimer::clone() const + { + return std::unique_ptr< SimulatorTimerInterface > (new SimulatorTimer( *this )); + } + + } // namespace Opm diff --git a/opm/simulators/timestepping/SimulatorTimer.hpp b/opm/simulators/timestepping/SimulatorTimer.hpp index 12794ebf8..882f13a19 100644 --- a/opm/simulators/timestepping/SimulatorTimer.hpp +++ b/opm/simulators/timestepping/SimulatorTimer.hpp @@ -104,6 +104,9 @@ namespace Opm /// Return true if op++() has been called numSteps() times. bool done() const; + /// return copy of object + virtual std::unique_ptr< SimulatorTimerInterface > clone() const; + private: std::vector timesteps_; int current_step_; diff --git a/opm/simulators/timestepping/SimulatorTimerInterface.hpp b/opm/simulators/timestepping/SimulatorTimerInterface.hpp index c3cb9eee4..4a1edbdf4 100644 --- a/opm/simulators/timestepping/SimulatorTimerInterface.hpp +++ b/opm/simulators/timestepping/SimulatorTimerInterface.hpp @@ -98,6 +98,9 @@ namespace Opm tm t = boost::posix_time::to_tm(currentDateTime()); return std::mktime(&t); } + + /// return copy of current timer instance + virtual std::unique_ptr< SimulatorTimerInterface > clone () const = 0; };