* Added convenience methods for debugging.
* Added better tracing support. * GetNextName() was not incrementing the index when iterating to the next entry and was therefor broken if the object managed more than one entry. * Made a small simplification in EntryRemoved(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26934 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,6 +15,15 @@
|
||||
|
||||
using std::nothrow;
|
||||
|
||||
|
||||
//#define TRACE_CHANGES_ITERATOR
|
||||
#ifdef TRACE_CHANGES_ITERATOR
|
||||
# define TRACE(x...) printf(x)
|
||||
#else
|
||||
# define TRACE(x...)
|
||||
#endif
|
||||
|
||||
|
||||
ChangesIterator::ChangesIterator(const Model* model)
|
||||
: FileIterator(),
|
||||
fPathMap(),
|
||||
@@ -46,8 +55,10 @@ ChangesIterator::GetNextName(char* buffer)
|
||||
// TODO: inefficient
|
||||
PathMap::Iterator iterator = fPathMap.GetIterator();
|
||||
int32 index = 0;
|
||||
while (index < fIteratorIndex && iterator.HasNext())
|
||||
while (index < fIteratorIndex && iterator.HasNext()) {
|
||||
iterator.Next();
|
||||
index++;
|
||||
}
|
||||
|
||||
if (iterator.HasNext()) {
|
||||
const PathMap::Entry& entry = iterator.Next();
|
||||
@@ -78,6 +89,8 @@ ChangesIterator::EntryAdded(const char* path)
|
||||
if (fPathMap.ContainsKey(key))
|
||||
return;
|
||||
|
||||
TRACE("added: %s\n", path);
|
||||
|
||||
fPathMap.Put(key, ENTRY_ADDED);
|
||||
}
|
||||
|
||||
@@ -88,12 +101,17 @@ ChangesIterator::EntryRemoved(const char* path)
|
||||
HashString key(path);
|
||||
if (fPathMap.ContainsKey(key)) {
|
||||
uint32 mode = fPathMap.Get(key);
|
||||
if (mode == ENTRY_ADDED)
|
||||
if (mode == ENTRY_ADDED) {
|
||||
TRACE("ignoring: %s\n", path);
|
||||
fPathMap.Remove(key);
|
||||
else if (mode != ENTRY_REMOVED)
|
||||
fPathMap.Put(key, ENTRY_REMOVED);
|
||||
} else
|
||||
fPathMap.Put(key, ENTRY_REMOVED);
|
||||
return;
|
||||
} else if (mode == ENTRY_REMOVED)
|
||||
return;
|
||||
}
|
||||
|
||||
TRACE("removed: %s\n", path);
|
||||
|
||||
fPathMap.Put(key, ENTRY_REMOVED);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,5 +122,42 @@ ChangesIterator::EntryChanged(const char* path)
|
||||
if (fPathMap.ContainsKey(key) && fPathMap.Get(key) == ENTRY_ADDED)
|
||||
return;
|
||||
|
||||
TRACE("changed: %s\n", path);
|
||||
|
||||
fPathMap.Put(key, ENTRY_CHANGED);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ChangesIterator::IsEmpty() const
|
||||
{
|
||||
PathMap::Iterator iterator = fPathMap.GetIterator();
|
||||
return !iterator.HasNext();
|
||||
}
|
||||
|
||||
void
|
||||
ChangesIterator::PrintToStream() const
|
||||
{
|
||||
printf("ChangesIterator contents:\n");
|
||||
PathMap::Iterator iterator = fPathMap.GetIterator();
|
||||
while (iterator.HasNext()) {
|
||||
const PathMap::Entry& entry = iterator.Next();
|
||||
const char* value;
|
||||
switch (entry.value) {
|
||||
case ENTRY_ADDED:
|
||||
value = "ADDED";
|
||||
break;
|
||||
case ENTRY_REMOVED:
|
||||
value = "REMOVED";
|
||||
break;
|
||||
case ENTRY_CHANGED:
|
||||
value = "CHANGED";
|
||||
break;
|
||||
default:
|
||||
value = "???";
|
||||
break;
|
||||
}
|
||||
printf("entry: %s - %s\n", entry.key.GetString(), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ public:
|
||||
void EntryRemoved(const char* path);
|
||||
void EntryChanged(const char* path);
|
||||
|
||||
bool IsEmpty() const;
|
||||
void PrintToStream() const;
|
||||
|
||||
private:
|
||||
typedef HashMap<HashString, uint32> PathMap;
|
||||
enum {
|
||||
|
||||
Reference in New Issue
Block a user