2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
6 #include "ChangesIterator.h"
12 #include <Directory.h>
19 //#define TRACE_CHANGES_ITERATOR
20 #ifdef TRACE_CHANGES_ITERATOR
21 # define TRACE(x...) printf(x)
27 ChangesIterator::ChangesIterator(const Model
* model
)
32 fRecurseDirs(model
->fRecurseDirs
),
33 fRecurseLinks(model
->fRecurseLinks
),
34 fSkipDotDirs(model
->fSkipDotDirs
),
35 fTextOnly(model
->fTextOnly
)
40 ChangesIterator::~ChangesIterator()
46 ChangesIterator::IsValid() const
48 return fPathMap
.InitCheck() == B_OK
;
53 ChangesIterator::GetNextName(char* buffer
)
56 PathMap::Iterator iterator
= fPathMap
.GetIterator();
58 while (index
< fIteratorIndex
&& iterator
.HasNext()) {
63 if (iterator
.HasNext()) {
64 const PathMap::Entry
& entry
= iterator
.Next();
65 sprintf(buffer
, "%s", entry
.key
.GetString());
76 ChangesIterator::NotifyNegatives() const
86 ChangesIterator::EntryAdded(const char* path
)
89 if (fPathMap
.ContainsKey(key
))
92 TRACE("added: %s\n", path
);
94 fPathMap
.Put(key
, ENTRY_ADDED
);
99 ChangesIterator::EntryRemoved(const char* path
)
101 HashString
key(path
);
102 if (fPathMap
.ContainsKey(key
)) {
103 TRACE("ignoring: %s\n", path
);
104 fPathMap
.Remove(key
);
110 ChangesIterator::EntryChanged(const char* path
)
112 HashString
key(path
);
113 if (fPathMap
.ContainsKey(key
) && fPathMap
.Get(key
) == ENTRY_ADDED
)
116 TRACE("changed: %s\n", path
);
118 fPathMap
.Put(key
, ENTRY_CHANGED
);
123 ChangesIterator::IsEmpty() const
125 PathMap::Iterator iterator
= fPathMap
.GetIterator();
126 return !iterator
.HasNext();
130 ChangesIterator::PrintToStream() const
132 printf("ChangesIterator contents:\n");
133 PathMap::Iterator iterator
= fPathMap
.GetIterator();
134 while (iterator
.HasNext()) {
135 const PathMap::Entry
& entry
= iterator
.Next();
137 switch (entry
.value
) {
151 printf("entry: %s - %s\n", entry
.key
.GetString(), value
);