libsaria: Create a library path iterator
This makes it easier to loop over all the library paths without needing to know anything about implementation. I modified the update functions to use the new way, so it should be ready for use by the UI. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
12b193cc80
commit
1daa12ee81
|
@ -10,6 +10,9 @@ using namespace std;
|
|||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
class LibraryPath;
|
||||
|
||||
namespace library
|
||||
{
|
||||
|
||||
|
@ -20,6 +23,13 @@ namespace libsaria
|
|||
bool end();
|
||||
} /* Namespace: iter */
|
||||
|
||||
namespace pathiter
|
||||
{
|
||||
void reset();
|
||||
libsaria::LibraryPath *next();
|
||||
bool end();
|
||||
}
|
||||
|
||||
struct PathInfo {
|
||||
string path;
|
||||
unsigned int size;
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright Bryan Schumaker 2012
|
||||
|
||||
#include "library.h"
|
||||
|
||||
static list<libsaria::LibraryPath>::iterator it;
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
namespace library
|
||||
{
|
||||
|
||||
void pathiter::reset()
|
||||
{
|
||||
it = path_list.begin();
|
||||
}
|
||||
|
||||
libsaria::LibraryPath *pathiter::next()
|
||||
{
|
||||
libsaria::LibraryPath *path = &(*it);
|
||||
it++;
|
||||
return path;
|
||||
}
|
||||
|
||||
bool pathiter::end()
|
||||
{
|
||||
return it == path_list.end();
|
||||
}
|
||||
|
||||
} /* Namespace: library */
|
||||
}; /* Namespace: libsaria */
|
|
@ -10,10 +10,10 @@ using namespace std;
|
|||
|
||||
list<libsaria::LibraryPath> path_list;
|
||||
|
||||
static void do_update(list<libsaria::LibraryPath>::iterator it)
|
||||
static void do_update(libsaria::LibraryPath *path)
|
||||
{
|
||||
it->validate();
|
||||
it->update();
|
||||
path->validate();
|
||||
path->update();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
|
@ -28,17 +28,20 @@ namespace libsaria
|
|||
|
||||
void library::update()
|
||||
{
|
||||
list<LibraryPath>::iterator it;
|
||||
for (it = path_list.begin(); it != path_list.end(); it++)
|
||||
do_update(it);
|
||||
pathiter::reset();
|
||||
while (!pathiter::end())
|
||||
do_update(pathiter::next());
|
||||
}
|
||||
|
||||
void library::update_path(string dir)
|
||||
{
|
||||
list<LibraryPath>::iterator it;
|
||||
for (it = path_list.begin(); it != path_list.end(); it++) {
|
||||
if (it->get_path() == dir)
|
||||
do_update(it);
|
||||
LibraryPath *path;
|
||||
|
||||
pathiter::reset();
|
||||
while (!pathiter::end()) {
|
||||
path = pathiter::next();
|
||||
if (path->get_path() == dir)
|
||||
do_update(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue