diff --git a/Storage/Disk/Disk.hpp b/Storage/Disk/Disk.hpp index b23081a04..f574f2c28 100644 --- a/Storage/Disk/Disk.hpp +++ b/Storage/Disk/Disk.hpp @@ -53,6 +53,11 @@ class Track { @returns the time jumped to. */ virtual Time seek_to(const Time &time_since_index_hole) = 0; + + /*! + The virtual copy constructor pattern; returns a copy of the Track. + */ + virtual Track *clone() = 0; }; /*! diff --git a/Storage/Disk/PCMPatchedTrack.cpp b/Storage/Disk/PCMPatchedTrack.cpp index 4356912c5..05ea73d1b 100644 --- a/Storage/Disk/PCMPatchedTrack.cpp +++ b/Storage/Disk/PCMPatchedTrack.cpp @@ -20,6 +20,18 @@ PCMPatchedTrack::PCMPatchedTrack(std::shared_ptr underlying_track) : underlying_track_->seek_to(zero); } +PCMPatchedTrack::PCMPatchedTrack(const PCMPatchedTrack &original) +{ + underlying_track_.reset(original.underlying_track_->clone()); + periods_ = original.periods_; + active_period_ = periods_.begin(); +} + +Track *PCMPatchedTrack::clone() +{ + return new PCMPatchedTrack(*this); +} + void PCMPatchedTrack::add_segment(const Time &start_time, const PCMSegment &segment) { std::shared_ptr event_source(new PCMSegmentEventSource(segment)); diff --git a/Storage/Disk/PCMPatchedTrack.hpp b/Storage/Disk/PCMPatchedTrack.hpp index 2ea8ffd04..d4cad19ed 100644 --- a/Storage/Disk/PCMPatchedTrack.hpp +++ b/Storage/Disk/PCMPatchedTrack.hpp @@ -26,6 +26,11 @@ class PCMPatchedTrack: public Track { */ PCMPatchedTrack(std::shared_ptr underlying_track); + /*! + Copy constructor, for Track. + */ + PCMPatchedTrack(const PCMPatchedTrack &); + /*! Replaces whatever is currently on the track from @c start_position to @c start_position + segment length with the contents of @c segment. @@ -35,6 +40,7 @@ class PCMPatchedTrack: public Track { // To satisfy Storage::Disk::Track Event get_next_event(); Time seek_to(const Time &time_since_index_hole); + Track *clone(); private: std::shared_ptr underlying_track_; diff --git a/Storage/Disk/PCMTrack.cpp b/Storage/Disk/PCMTrack.cpp index 0e1b401f0..9a8067f31 100644 --- a/Storage/Disk/PCMTrack.cpp +++ b/Storage/Disk/PCMTrack.cpp @@ -52,6 +52,11 @@ PCMTrack::PCMTrack(const PCMTrack &original) : PCMTrack() segment_event_sources_ = original.segment_event_sources_; } +Track *PCMTrack::clone() +{ + return new PCMTrack(*this); +} + Track::Event PCMTrack::get_next_event() { // ask the current segment for a new event diff --git a/Storage/Disk/PCMTrack.hpp b/Storage/Disk/PCMTrack.hpp index ce11d7125..ad1d7093a 100644 --- a/Storage/Disk/PCMTrack.hpp +++ b/Storage/Disk/PCMTrack.hpp @@ -44,6 +44,7 @@ class PCMTrack: public Track { // as per @c Track Event get_next_event(); Time seek_to(const Time &time_since_index_hole); + Track *clone(); private: // storage for the segments that describe this track