From 9e3399b619edae15818c64917688484362395003 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 5 Jun 2014 11:04:55 -0400 Subject: [PATCH] deck: Reintroduce deck :: get() This function turned out to be really useful for the gui. Signed-off-by: Anna Schumaker --- DESIGN | 4 ++++ core/deck.cpp | 12 ++++++++++++ include/core/deck.h | 2 ++ tests/deck.cpp | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/DESIGN b/DESIGN index 5b1fb7f1..2aba3337 100644 --- a/DESIGN +++ b/DESIGN @@ -1273,6 +1273,10 @@ Deck: Return the index of the queue in the deck or deck.size() if 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(); Find the first enabled queue on the deck and return the track given by queue->next(). diff --git a/core/deck.cpp b/core/deck.cpp index 2b6c3b5c..013845f5 100644 --- a/core/deck.cpp +++ b/core/deck.cpp @@ -187,6 +187,18 @@ unsigned int deck :: index(Queue *queue) return queue_deck.size(); } +Queue *deck :: get(unsigned int index) +{ + std::list::iterator it; + + for (it = queue_deck.begin(); it != queue_deck.end(); it++) { + if (index == 0) + return &(*it); + index--; + } + return NULL; +} + Track *deck :: next() { Track *track = NULL; diff --git a/include/core/deck.h b/include/core/deck.h index b6cca7b9..a4775d7e 100644 --- a/include/core/deck.h +++ b/include/core/deck.h @@ -33,7 +33,9 @@ namespace deck Queue *create(bool); void destroy(Queue *); void move(Queue *, unsigned int); + unsigned int index(Queue *); + Queue *get(unsigned int); Track *next(); Track *prev(); diff --git a/tests/deck.cpp b/tests/deck.cpp index 0dd579a5..339f1d46 100644 --- a/tests/deck.cpp +++ b/tests/deck.cpp @@ -74,12 +74,14 @@ static void test_create_mv_destroy() test_equal(q1->has_flag(Q_ENABLED), true); test_equal(q1->has_flag(Q_RANDOM), true); test_equal(deck :: index(q1), (unsigned)2); + test_equal(deck :: get(2), q1); q2 = deck :: create(false); test_not_equal(q2, Q_NULL); test_equal(q2->has_flag(Q_ENABLED), true); test_equal(q2->has_flag(Q_RANDOM), false); test_equal(deck :: index(q2), (unsigned)3); + test_equal(deck :: get(3), q2); deck :: move(q1, 3); test_equal(deck :: index(q1), (unsigned)3); @@ -98,6 +100,8 @@ static void test_create_mv_destroy() deck :: destroy(q2); test_equal(n, (unsigned)2); test_equal(deck :: index(q2), (unsigned)2); + + test_equal(deck :: get(3), Q_NULL); } static void test_next_prev()