libsaria: Create iterator functions for the library

I use these to fill in the UI list for the library.  I think this will
be easier to use (and cleaner) than passing a function pointer to a
for_each loop.
This commit is contained in:
Bryan Schumaker 2011-12-29 12:08:32 -05:00
parent 0fa608c90f
commit 2fd41ff4d7
4 changed files with 48 additions and 1 deletions

View File

@ -12,6 +12,14 @@ namespace libsaria
{
namespace library
{
namespace iter
{
void reset();
libsaria::Track *next();
bool end();
} /* Namespace: iter */
struct PathInfo {
string path;
unsigned int size;

View File

@ -0,0 +1,34 @@
#include <libsaria/track.h>
#include <libsaria/library.h>
#include "list.h"
#include <list>
using namespace std;
list<libsaria::Track *>::iterator it;
namespace libsaria
{
namespace library
{
void iter::reset()
{
it = track_list.begin();
}
libsaria::Track *iter::next()
{
libsaria::Track *track = *it;
it++;
return track;
}
bool iter::end()
{
return it == track_list.end();
}
} /* Namespace: library */
}; /* Namespace: libsaria */

View File

@ -6,7 +6,7 @@
#include <list>
using namespace std;
static list<libsaria::Track *> track_list;
list<libsaria::Track *> track_list;
static bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
{

View File

@ -1,6 +1,11 @@
#ifndef LIBSARIA_LIBRARY_LIST_H
#define LIBSARIA_LIBRARY_LIST_H
#include <list>
using namespace std;
extern list<libsaria::Track *> track_list;
namespace libsaria
{
namespace library