deck: Reintroduce deck :: get()

This function turned out to be really useful for the gui.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-06-05 11:04:55 -04:00
parent eb777c04f1
commit 9e3399b619
4 changed files with 22 additions and 0 deletions

4
DESIGN
View File

@ -1273,6 +1273,10 @@ Deck:
Return the index of the queue in the deck or deck.size() if Return the index of the queue in the deck or deck.size() if
the queue is not currently in the deck. the queue is not currently in the deck.
Queue *deck :: get(unsigned int index);
Return the queue at the requested index, or NULL if no queue
is found.
Track *deck :: next(); Track *deck :: next();
Find the first enabled queue on the deck and return the track Find the first enabled queue on the deck and return the track
given by queue->next(). given by queue->next().

View File

@ -187,6 +187,18 @@ unsigned int deck :: index(Queue *queue)
return queue_deck.size(); return queue_deck.size();
} }
Queue *deck :: get(unsigned int index)
{
std::list<TempQueue>::iterator it;
for (it = queue_deck.begin(); it != queue_deck.end(); it++) {
if (index == 0)
return &(*it);
index--;
}
return NULL;
}
Track *deck :: next() Track *deck :: next()
{ {
Track *track = NULL; Track *track = NULL;

View File

@ -33,7 +33,9 @@ namespace deck
Queue *create(bool); Queue *create(bool);
void destroy(Queue *); void destroy(Queue *);
void move(Queue *, unsigned int); void move(Queue *, unsigned int);
unsigned int index(Queue *); unsigned int index(Queue *);
Queue *get(unsigned int);
Track *next(); Track *next();
Track *prev(); Track *prev();

View File

@ -74,12 +74,14 @@ static void test_create_mv_destroy()
test_equal(q1->has_flag(Q_ENABLED), true); test_equal(q1->has_flag(Q_ENABLED), true);
test_equal(q1->has_flag(Q_RANDOM), true); test_equal(q1->has_flag(Q_RANDOM), true);
test_equal(deck :: index(q1), (unsigned)2); test_equal(deck :: index(q1), (unsigned)2);
test_equal(deck :: get(2), q1);
q2 = deck :: create(false); q2 = deck :: create(false);
test_not_equal(q2, Q_NULL); test_not_equal(q2, Q_NULL);
test_equal(q2->has_flag(Q_ENABLED), true); test_equal(q2->has_flag(Q_ENABLED), true);
test_equal(q2->has_flag(Q_RANDOM), false); test_equal(q2->has_flag(Q_RANDOM), false);
test_equal(deck :: index(q2), (unsigned)3); test_equal(deck :: index(q2), (unsigned)3);
test_equal(deck :: get(3), q2);
deck :: move(q1, 3); deck :: move(q1, 3);
test_equal(deck :: index(q1), (unsigned)3); test_equal(deck :: index(q1), (unsigned)3);
@ -98,6 +100,8 @@ static void test_create_mv_destroy()
deck :: destroy(q2); deck :: destroy(q2);
test_equal(n, (unsigned)2); test_equal(n, (unsigned)2);
test_equal(deck :: index(q2), (unsigned)2); test_equal(deck :: index(q2), (unsigned)2);
test_equal(deck :: get(3), Q_NULL);
} }
static void test_next_prev() static void test_next_prev()