Queue: add "noexcept"
This commit is contained in:
parent
2f32df1f09
commit
a6910313b4
@ -21,7 +21,7 @@
|
||||
#include "Queue.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
|
||||
Queue::Queue(unsigned _max_length)
|
||||
Queue::Queue(unsigned _max_length) noexcept
|
||||
:max_length(_max_length),
|
||||
items(new Item[max_length]),
|
||||
order(new unsigned[max_length]),
|
||||
@ -29,7 +29,7 @@ Queue::Queue(unsigned _max_length)
|
||||
{
|
||||
}
|
||||
|
||||
Queue::~Queue()
|
||||
Queue::~Queue() noexcept
|
||||
{
|
||||
Clear();
|
||||
|
||||
@ -79,7 +79,7 @@ Queue::ModifyAtOrder(unsigned _order) noexcept
|
||||
}
|
||||
|
||||
unsigned
|
||||
Queue::Append(DetachedSong &&song, uint8_t priority)
|
||||
Queue::Append(DetachedSong &&song, uint8_t priority) noexcept
|
||||
{
|
||||
assert(!IsFull());
|
||||
|
||||
@ -295,7 +295,7 @@ queue_sort_order_by_priority(Queue *queue,
|
||||
}
|
||||
|
||||
void
|
||||
Queue::ShuffleOrderRange(unsigned start, unsigned end)
|
||||
Queue::ShuffleOrderRange(unsigned start, unsigned end) noexcept
|
||||
{
|
||||
assert(random);
|
||||
assert(start <= end);
|
||||
@ -310,7 +310,7 @@ Queue::ShuffleOrderRange(unsigned start, unsigned end)
|
||||
* priority group.
|
||||
*/
|
||||
void
|
||||
Queue::ShuffleOrderRangeWithPriority(unsigned start, unsigned end)
|
||||
Queue::ShuffleOrderRangeWithPriority(unsigned start, unsigned end) noexcept
|
||||
{
|
||||
assert(random);
|
||||
assert(start <= end);
|
||||
@ -344,13 +344,13 @@ Queue::ShuffleOrderRangeWithPriority(unsigned start, unsigned end)
|
||||
}
|
||||
|
||||
void
|
||||
Queue::ShuffleOrder()
|
||||
Queue::ShuffleOrder() noexcept
|
||||
{
|
||||
ShuffleOrderRangeWithPriority(0, length);
|
||||
}
|
||||
|
||||
void
|
||||
Queue::ShuffleOrderFirst(unsigned start, unsigned end)
|
||||
Queue::ShuffleOrderFirst(unsigned start, unsigned end) noexcept
|
||||
{
|
||||
rand.AutoCreate();
|
||||
|
||||
@ -359,7 +359,7 @@ Queue::ShuffleOrderFirst(unsigned start, unsigned end)
|
||||
}
|
||||
|
||||
void
|
||||
Queue::ShuffleOrderLast(unsigned start, unsigned end)
|
||||
Queue::ShuffleOrderLast(unsigned start, unsigned end) noexcept
|
||||
{
|
||||
rand.AutoCreate();
|
||||
|
||||
@ -368,7 +368,7 @@ Queue::ShuffleOrderLast(unsigned start, unsigned end)
|
||||
}
|
||||
|
||||
void
|
||||
Queue::ShuffleRange(unsigned start, unsigned end)
|
||||
Queue::ShuffleRange(unsigned start, unsigned end) noexcept
|
||||
{
|
||||
assert(start <= end);
|
||||
assert(end <= length);
|
||||
@ -418,7 +418,7 @@ Queue::CountSamePriority(unsigned start_order, uint8_t priority) const noexcept
|
||||
|
||||
bool
|
||||
Queue::SetPriority(unsigned position, uint8_t priority, int after_order,
|
||||
bool reorder)
|
||||
bool reorder) noexcept
|
||||
{
|
||||
assert(position < length);
|
||||
|
||||
@ -478,7 +478,7 @@ Queue::SetPriority(unsigned position, uint8_t priority, int after_order,
|
||||
|
||||
bool
|
||||
Queue::SetPriorityRange(unsigned start_position, unsigned end_position,
|
||||
uint8_t priority, int after_order)
|
||||
uint8_t priority, int after_order) noexcept
|
||||
{
|
||||
assert(start_position <= end_position);
|
||||
assert(end_position <= length);
|
||||
|
@ -103,18 +103,18 @@ struct Queue {
|
||||
/** random number generator for shuffle and random mode */
|
||||
LazyRandomEngine rand;
|
||||
|
||||
explicit Queue(unsigned max_length);
|
||||
explicit Queue(unsigned max_length) noexcept;
|
||||
|
||||
/**
|
||||
* Deinitializes a queue object. It does not free the queue
|
||||
* pointer itself.
|
||||
*/
|
||||
~Queue();
|
||||
~Queue() noexcept;
|
||||
|
||||
Queue(const Queue &) = delete;
|
||||
Queue &operator=(const Queue &) = delete;
|
||||
|
||||
unsigned GetLength() const {
|
||||
unsigned GetLength() const noexcept {
|
||||
assert(length <= max_length);
|
||||
|
||||
return length;
|
||||
@ -123,14 +123,14 @@ struct Queue {
|
||||
/**
|
||||
* Determine if the queue is empty, i.e. there are no songs.
|
||||
*/
|
||||
bool IsEmpty() const {
|
||||
bool IsEmpty() const noexcept {
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the maximum number of songs has been reached.
|
||||
*/
|
||||
bool IsFull() const {
|
||||
bool IsFull() const noexcept {
|
||||
assert(length <= max_length);
|
||||
|
||||
return length >= max_length;
|
||||
@ -139,23 +139,22 @@ struct Queue {
|
||||
/**
|
||||
* Is that a valid position number?
|
||||
*/
|
||||
bool IsValidPosition(unsigned position) const {
|
||||
bool IsValidPosition(unsigned position) const noexcept {
|
||||
return position < length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is that a valid order number?
|
||||
*/
|
||||
bool IsValidOrder(unsigned _order) const {
|
||||
bool IsValidOrder(unsigned _order) const noexcept {
|
||||
return _order < length;
|
||||
}
|
||||
|
||||
int IdToPosition(unsigned id) const {
|
||||
int IdToPosition(unsigned id) const noexcept {
|
||||
return id_table.IdToPosition(id);
|
||||
}
|
||||
|
||||
int PositionToId(unsigned position) const
|
||||
{
|
||||
int PositionToId(unsigned position) const noexcept {
|
||||
assert(position < length);
|
||||
|
||||
return items[position].id;
|
||||
@ -187,20 +186,20 @@ struct Queue {
|
||||
return items[position].priority;
|
||||
}
|
||||
|
||||
const Item &GetOrderItem(unsigned i) const {
|
||||
const Item &GetOrderItem(unsigned i) const noexcept {
|
||||
assert(IsValidOrder(i));
|
||||
|
||||
return items[OrderToPosition(i)];
|
||||
}
|
||||
|
||||
uint8_t GetOrderPriority(unsigned i) const {
|
||||
uint8_t GetOrderPriority(unsigned i) const noexcept {
|
||||
return GetOrderItem(i).priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the song at the specified position.
|
||||
*/
|
||||
DetachedSong &Get(unsigned position) const {
|
||||
DetachedSong &Get(unsigned position) const noexcept {
|
||||
assert(position < length);
|
||||
|
||||
return *items[position].song;
|
||||
@ -209,7 +208,7 @@ struct Queue {
|
||||
/**
|
||||
* Returns the song at the specified order number.
|
||||
*/
|
||||
DetachedSong &GetOrder(unsigned _order) const {
|
||||
DetachedSong &GetOrder(unsigned _order) const noexcept {
|
||||
return Get(OrderToPosition(_order));
|
||||
}
|
||||
|
||||
@ -217,7 +216,8 @@ struct Queue {
|
||||
* Is the song at the specified position newer than the specified
|
||||
* version?
|
||||
*/
|
||||
bool IsNewerAtPosition(unsigned position, uint32_t _version) const {
|
||||
bool IsNewerAtPosition(unsigned position,
|
||||
uint32_t _version) const noexcept {
|
||||
assert(position < length);
|
||||
|
||||
return _version > version ||
|
||||
@ -245,7 +245,7 @@ struct Queue {
|
||||
* IncrementVersion() after all modifications have been made.
|
||||
* number.
|
||||
*/
|
||||
void ModifyAtPosition(unsigned position) {
|
||||
void ModifyAtPosition(unsigned position) noexcept {
|
||||
assert(position < length);
|
||||
|
||||
items[position].version = version;
|
||||
@ -268,7 +268,7 @@ struct Queue {
|
||||
*
|
||||
* @param priority the priority of this new queue item
|
||||
*/
|
||||
unsigned Append(DetachedSong &&song, uint8_t priority);
|
||||
unsigned Append(DetachedSong &&song, uint8_t priority) noexcept;
|
||||
|
||||
/**
|
||||
* Swaps two songs, addressed by their position.
|
||||
@ -278,7 +278,7 @@ struct Queue {
|
||||
/**
|
||||
* Swaps two songs, addressed by their order number.
|
||||
*/
|
||||
void SwapOrders(unsigned order1, unsigned order2) {
|
||||
void SwapOrders(unsigned order1, unsigned order2) noexcept {
|
||||
std::swap(order[order1], order[order2]);
|
||||
}
|
||||
|
||||
@ -330,7 +330,7 @@ struct Queue {
|
||||
/**
|
||||
* Initializes the "order" array, and restores "normal" order.
|
||||
*/
|
||||
void RestoreOrder() {
|
||||
void RestoreOrder() noexcept {
|
||||
for (unsigned i = 0; i < length; ++i)
|
||||
order[i] = i;
|
||||
}
|
||||
@ -339,43 +339,44 @@ struct Queue {
|
||||
* Shuffle the order of items in the specified range, ignoring
|
||||
* their priorities.
|
||||
*/
|
||||
void ShuffleOrderRange(unsigned start, unsigned end);
|
||||
void ShuffleOrderRange(unsigned start, unsigned end) noexcept;
|
||||
|
||||
/**
|
||||
* Shuffle the order of items in the specified range, taking their
|
||||
* priorities into account.
|
||||
*/
|
||||
void ShuffleOrderRangeWithPriority(unsigned start, unsigned end);
|
||||
void ShuffleOrderRangeWithPriority(unsigned start,
|
||||
unsigned end) noexcept;
|
||||
|
||||
/**
|
||||
* Shuffles the virtual order of songs, but does not move them
|
||||
* physically. This is used in random mode.
|
||||
*/
|
||||
void ShuffleOrder();
|
||||
void ShuffleOrder() noexcept;
|
||||
|
||||
void ShuffleOrderFirst(unsigned start, unsigned end);
|
||||
void ShuffleOrderFirst(unsigned start, unsigned end) noexcept;
|
||||
|
||||
/**
|
||||
* Shuffles the virtual order of the last song in the specified
|
||||
* (order) range. This is used in random mode after a song has been
|
||||
* appended by queue_append().
|
||||
*/
|
||||
void ShuffleOrderLast(unsigned start, unsigned end);
|
||||
void ShuffleOrderLast(unsigned start, unsigned end) noexcept;
|
||||
|
||||
/**
|
||||
* Shuffles a (position) range in the queue. The songs are physically
|
||||
* shuffled, not by using the "order" mapping.
|
||||
*/
|
||||
void ShuffleRange(unsigned start, unsigned end);
|
||||
void ShuffleRange(unsigned start, unsigned end) noexcept;
|
||||
|
||||
bool SetPriority(unsigned position, uint8_t priority, int after_order,
|
||||
bool reorder=true);
|
||||
bool reorder=true) noexcept;
|
||||
|
||||
bool SetPriorityRange(unsigned start_position, unsigned end_position,
|
||||
uint8_t priority, int after_order);
|
||||
uint8_t priority, int after_order) noexcept;
|
||||
|
||||
private:
|
||||
void MoveItemTo(unsigned from, unsigned to) {
|
||||
void MoveItemTo(unsigned from, unsigned to) noexcept {
|
||||
unsigned from_id = items[from].id;
|
||||
|
||||
items[to] = items[from];
|
||||
|
Loading…
Reference in New Issue
Block a user