Skip to content
Snippets Groups Projects
Commit 6a4b1c51 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Implement swaps

parent 4f433e9e
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,21 @@ class Frame { ...@@ -23,6 +23,21 @@ class Frame {
explicit Frame(Frame *parent) : parent_(parent) {}; explicit Frame(Frame *parent) : parent_(parent) {};
~Frame() { flush(); }; ~Frame() { flush(); };
Frame(Frame &&f) {
f.swapTo(*this);
f.reset();
}
Frame &operator=(Frame &&f) {
f.swapTo(*this);
f.reset();
return *this;
}
// Prevent frame copy, instead use a move.
Frame(const Frame &)=delete;
Frame &operator=(const Frame &)=delete;
inline bool has(ftl::codecs::Channel c) { inline bool has(ftl::codecs::Channel c) {
return data_.find(c) != data_.end() || (parent_ && parent_->has(c)); return data_.find(c) != data_.end() || (parent_ && parent_->has(c));
} }
...@@ -79,7 +94,9 @@ class Frame { ...@@ -79,7 +94,9 @@ class Frame {
void merge(Frame &); void merge(Frame &);
void swap(Frame &); void swapTo(Frame &);
void swapChanged(Frame &);
void swapChannel(ftl::codecs::Channel, Frame &); void swapChannel(ftl::codecs::Channel, Frame &);
......
...@@ -30,3 +30,38 @@ bool Frame::flush() { ...@@ -30,3 +30,38 @@ bool Frame::flush() {
changed_.clear(); changed_.clear();
return true; return true;
} }
void Frame::merge(Frame &f) {
for (auto x : f) {
data_[x.first] = std::move(x.second);
touch(x.first);
}
}
void Frame::swapTo(Frame &f) {
for (auto x : *this) {
f.data_[x.first].swap(x.second);
f.changed_.emplace(x.first);
changed_.emplace(x.first);
}
}
void Frame::swapChanged(Frame &f) {
for (auto x : changed_) {
f.data_[x].swap(data_[x]);
f.changed_.emplace(x);
}
}
void Frame::swapChannel(ftl::codecs::Channel c, Frame &f) {
if (has(c)) {
f.data_[c].swap(data_[c]);
f.changed_.emplace(c);
changed_.emplace(c);
}
}
void Frame::clear() {
changed_.clear();
data_.clear();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment