1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

After a quick bit of reading, discovered the virtual copy constructor pattern really is only a convention in C++, and conformed to it. Which hopefully gives copyable tracks.

This commit is contained in:
Thomas Harte 2016-12-30 17:25:39 -05:00
parent 71dbd78cf2
commit 63ff5165a4
5 changed files with 29 additions and 0 deletions

View File

@ -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;
};
/*!

View File

@ -20,6 +20,18 @@ PCMPatchedTrack::PCMPatchedTrack(std::shared_ptr<Track> 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<PCMSegmentEventSource> event_source(new PCMSegmentEventSource(segment));

View File

@ -26,6 +26,11 @@ class PCMPatchedTrack: public Track {
*/
PCMPatchedTrack(std::shared_ptr<Track> 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<Track> underlying_track_;

View File

@ -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

View File

@ -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