2017-09-23 02:46:31 +00:00
|
|
|
//
|
|
|
|
// DiskImageImplementation.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 22/09/2017.
|
|
|
|
// Copyright © 2017 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
template <typename T> int DiskImageHolder<T>::get_head_position_count() {
|
2017-09-23 02:46:31 +00:00
|
|
|
return disk_image_.get_head_position_count();
|
|
|
|
}
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
template <typename T> int DiskImageHolder<T>::get_head_count() {
|
2017-09-23 02:46:31 +00:00
|
|
|
return disk_image_.get_head_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> bool DiskImageHolder<T>::get_is_read_only() {
|
|
|
|
return disk_image_.get_is_read_only();
|
|
|
|
}
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
template <typename T> void DiskImageHolder<T>::flush_tracks() {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> void DiskImageHolder<T>::set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) {
|
2017-09-23 02:46:31 +00:00
|
|
|
if(disk_image_.get_is_read_only()) return;
|
|
|
|
|
|
|
|
cached_tracks_[address] = track;
|
|
|
|
|
|
|
|
if(!update_queue_) update_queue_.reset(new Concurrency::AsyncTaskQueue);
|
|
|
|
std::shared_ptr<Track> track_copy(track->clone());
|
2017-10-07 01:45:12 +00:00
|
|
|
update_queue_->enqueue([this, address, track_copy] {
|
|
|
|
disk_image_.set_track_at_position(address, track_copy);
|
2017-09-23 02:46:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
template <typename T> std::shared_ptr<Track> DiskImageHolder<T>::get_track_at_position(Track::Address address) {
|
|
|
|
if(address.head >= get_head_count()) return nullptr;
|
|
|
|
if(address.position >= get_head_position_count()) return nullptr;
|
2017-09-23 02:46:31 +00:00
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
auto cached_track = cached_tracks_.find(address);
|
2017-09-23 02:46:31 +00:00
|
|
|
if(cached_track != cached_tracks_.end()) return cached_track->second;
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
std::shared_ptr<Track> track = disk_image_.get_track_at_position(address);
|
2017-09-23 02:46:31 +00:00
|
|
|
if(!track) return nullptr;
|
|
|
|
cached_tracks_[address] = track;
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> DiskImageHolder<T>::~DiskImageHolder() {
|
|
|
|
if(update_queue_) update_queue_->flush();
|
|
|
|
}
|