diff options
author | Max Kellermann <max@musicpd.org> | 2017-10-18 08:50:01 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-10-18 08:50:01 +0200 |
commit | f2fac77d8c6ae42ce2e9a67dcfde4085ec44cfdf (patch) | |
tree | 7dac59c1f3f11226cf36a5c86ac56ae46c5f5d4a /src/queue | |
parent | 81b7373637e4b0c5c961b31c64ada8ed2a84d3a2 (diff) |
queue/Queue: add methods MoveOrderBefore() and MoveOrderAfter()
Diffstat (limited to 'src/queue')
-rw-r--r-- | src/queue/Queue.cxx | 18 | ||||
-rw-r--r-- | src/queue/Queue.hxx | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/queue/Queue.cxx b/src/queue/Queue.cxx index 9ee9568e0..720778099 100644 --- a/src/queue/Queue.cxx +++ b/src/queue/Queue.cxx @@ -215,6 +215,24 @@ Queue::MoveOrder(unsigned from_order, unsigned to_order) noexcept return to_order; } +unsigned +Queue::MoveOrderBefore(unsigned from_order, unsigned to_order) noexcept +{ + /* if "from_order" comes before "to_order", then the new + position is "to_order-1"; otherwise the "to_order" song is + moved one ahead */ + return MoveOrder(from_order, to_order - (from_order < to_order)); +} + +unsigned +Queue::MoveOrderAfter(unsigned from_order, unsigned to_order) noexcept +{ + /* if "from_order" comes after "to_order", then the new + position is "to_order+1"; otherwise the "to_order" song is + moved one back */ + return MoveOrder(from_order, to_order + (from_order > to_order)); +} + void Queue::DeletePosition(unsigned position) noexcept { diff --git a/src/queue/Queue.hxx b/src/queue/Queue.hxx index b9ca341e4..06e800479 100644 --- a/src/queue/Queue.hxx +++ b/src/queue/Queue.hxx @@ -290,6 +290,24 @@ struct Queue { unsigned MoveOrder(unsigned from_order, unsigned to_order) noexcept; /** + * Moves a song to a new position in the "order" list before + * the given one. + * + * @return the new order number of the given "from" song + */ + unsigned MoveOrderBefore(unsigned from_order, + unsigned to_order) noexcept; + + /** + * Moves a song to a new position in the "order" list after + * the given one. + * + * @return the new order number of the given "from" song + */ + unsigned MoveOrderAfter(unsigned from_order, + unsigned to_order) noexcept; + + /** * Moves a song to a new position. */ void MovePostion(unsigned from, unsigned to) noexcept; |