* 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;
|
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)
|
ChangesIterator::ChangesIterator(const Model* model)
|
||||||
: FileIterator(),
|
: FileIterator(),
|
||||||
fPathMap(),
|
fPathMap(),
|
||||||
@@ -46,8 +55,10 @@ ChangesIterator::GetNextName(char* buffer)
|
|||||||
// TODO: inefficient
|
// TODO: inefficient
|
||||||
PathMap::Iterator iterator = fPathMap.GetIterator();
|
PathMap::Iterator iterator = fPathMap.GetIterator();
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
while (index < fIteratorIndex && iterator.HasNext())
|
while (index < fIteratorIndex && iterator.HasNext()) {
|
||||||
iterator.Next();
|
iterator.Next();
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
if (iterator.HasNext()) {
|
if (iterator.HasNext()) {
|
||||||
const PathMap::Entry& entry = iterator.Next();
|
const PathMap::Entry& entry = iterator.Next();
|
||||||
@@ -78,6 +89,8 @@ ChangesIterator::EntryAdded(const char* path)
|
|||||||
if (fPathMap.ContainsKey(key))
|
if (fPathMap.ContainsKey(key))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
TRACE("added: %s\n", path);
|
||||||
|
|
||||||
fPathMap.Put(key, ENTRY_ADDED);
|
fPathMap.Put(key, ENTRY_ADDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,12 +101,17 @@ ChangesIterator::EntryRemoved(const char* path)
|
|||||||
HashString key(path);
|
HashString key(path);
|
||||||
if (fPathMap.ContainsKey(key)) {
|
if (fPathMap.ContainsKey(key)) {
|
||||||
uint32 mode = fPathMap.Get(key);
|
uint32 mode = fPathMap.Get(key);
|
||||||
if (mode == ENTRY_ADDED)
|
if (mode == ENTRY_ADDED) {
|
||||||
|
TRACE("ignoring: %s\n", path);
|
||||||
fPathMap.Remove(key);
|
fPathMap.Remove(key);
|
||||||
else if (mode != ENTRY_REMOVED)
|
return;
|
||||||
fPathMap.Put(key, ENTRY_REMOVED);
|
} else if (mode == ENTRY_REMOVED)
|
||||||
} else
|
return;
|
||||||
fPathMap.Put(key, ENTRY_REMOVED);
|
}
|
||||||
|
|
||||||
|
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)
|
if (fPathMap.ContainsKey(key) && fPathMap.Get(key) == ENTRY_ADDED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
TRACE("changed: %s\n", path);
|
||||||
|
|
||||||
fPathMap.Put(key, ENTRY_CHANGED);
|
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 EntryRemoved(const char* path);
|
||||||
void EntryChanged(const char* path);
|
void EntryChanged(const char* path);
|
||||||
|
|
||||||
|
bool IsEmpty() const;
|
||||||
|
void PrintToStream() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef HashMap<HashString, uint32> PathMap;
|
typedef HashMap<HashString, uint32> PathMap;
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
Reference in New Issue
Block a user