2008-02-19 18:06:52 +00:00
|
|
|
/* Copyright (c) 2008, Avian Contributors
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
#ifndef FINDER_H
|
|
|
|
#define FINDER_H
|
2007-06-07 00:30:16 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
2007-07-20 14:36:31 +00:00
|
|
|
#include "system.h"
|
2008-01-13 22:05:08 +00:00
|
|
|
#include "allocator.h"
|
2007-06-07 00:30:16 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
namespace vm {
|
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
class Finder {
|
2007-06-07 00:30:16 +00:00
|
|
|
public:
|
2008-11-21 23:20:35 +00:00
|
|
|
class IteratorImp {
|
|
|
|
public:
|
|
|
|
virtual const char* next(unsigned* size) = 0;
|
|
|
|
virtual void dispose() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Iterator {
|
|
|
|
public:
|
|
|
|
Iterator(Finder* finder):
|
|
|
|
it(finder->iterator()),
|
|
|
|
current(it->next(¤tSize))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Iterator() {
|
|
|
|
it->dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasMore() {
|
2008-11-28 04:44:04 +00:00
|
|
|
if (current) return true;
|
|
|
|
current = it->next(¤tSize);
|
2008-11-21 23:20:35 +00:00
|
|
|
return current != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* next(unsigned* size) {
|
2008-11-28 04:44:04 +00:00
|
|
|
if (hasMore()) {
|
2008-11-21 23:20:35 +00:00
|
|
|
*size = currentSize;
|
2008-11-28 04:44:04 +00:00
|
|
|
const char* v = current;
|
|
|
|
current = 0;
|
2008-11-21 23:20:35 +00:00
|
|
|
return v;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IteratorImp* it;
|
|
|
|
const char* current;
|
|
|
|
unsigned currentSize;
|
|
|
|
};
|
|
|
|
|
2008-11-23 23:58:01 +00:00
|
|
|
virtual IteratorImp* iterator() = 0;
|
2007-09-17 00:13:36 +00:00
|
|
|
virtual System::Region* find(const char* name) = 0;
|
2007-08-10 23:45:47 +00:00
|
|
|
virtual bool exists(const char* name) = 0;
|
2007-08-27 13:46:17 +00:00
|
|
|
virtual const char* path() = 0;
|
2007-07-20 14:36:31 +00:00
|
|
|
virtual void dispose() = 0;
|
2007-06-07 00:30:16 +00:00
|
|
|
};
|
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
Finder*
|
2008-03-31 03:43:43 +00:00
|
|
|
makeFinder(System* s, const char* path, const char* bootLibrary);
|
2007-07-20 14:36:31 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
} // namespace vm
|
|
|
|
|
2007-08-10 23:45:47 +00:00
|
|
|
#endif//FINDER_H
|