| Index: tools/gn/deps_iterator.h
|
| diff --git a/tools/gn/deps_iterator.h b/tools/gn/deps_iterator.h
|
| index 5fc3c01e019f33eff2e9714bc4fb9fbf8d6d1fd4..1c3a75e141747c3faa5e86bb0e3f8db5255853a3 100644
|
| --- a/tools/gn/deps_iterator.h
|
| +++ b/tools/gn/deps_iterator.h
|
| @@ -10,52 +10,64 @@
|
|
|
| class Target;
|
|
|
| -// Iterates over the deps of a target.
|
| +// Provides an iterator for iterating over multiple LabelTargetVectors to
|
| +// make it convenient to iterate over all deps of a target.
|
| //
|
| -// Since there are multiple kinds of deps, this iterator allows looping over
|
| -// each one in one loop.
|
| +// This works by maintaining a simple stack of vectors (since we have a fixed
|
| +// number of deps types). When the stack is empty, we've reached the end. This
|
| +// means that the default-constructed iterator == end() for any sequence.
|
| class DepsIterator {
|
| public:
|
| - enum LinkedOnly {
|
| - LINKED_ONLY,
|
| - };
|
| + // Creates an empty iterator.
|
| + DepsIterator();
|
|
|
| - // Iterate over public, private, and data deps.
|
| - explicit DepsIterator(const Target* t);
|
| + // Iterate over the deps in the given vectors. If passing less than three,
|
| + // pad with nulls.
|
| + DepsIterator(const LabelTargetVector* a,
|
| + const LabelTargetVector* b,
|
| + const LabelTargetVector* c);
|
|
|
| - // Iterate over the public and private linked deps, but not the data deps.
|
| - DepsIterator(const Target* t, LinkedOnly);
|
| -
|
| - // Returns true when there are no more targets.
|
| - bool done() const {
|
| - return !vect_stack_[0];
|
| - }
|
| -
|
| - // Advance to the next position. This assumes !done().
|
| + // Prefix increment operator. This assumes there are more items (i.e.
|
| + // *this != DepsIterator()).
|
| //
|
| // For internal use, this function tolerates an initial index equal to the
|
| // length of the current vector. In this case, it will advance to the next
|
| // one.
|
| - void Advance();
|
| + DepsIterator& operator++();
|
|
|
| - // The current dependency.
|
| - const LabelTargetPair& pair() const {
|
| + // Comparison for STL-based loops.
|
| + bool operator!=(const DepsIterator& other) {
|
| + return current_index_ != other.current_index_ ||
|
| + vect_stack_[0] != other.vect_stack_[0] ||
|
| + vect_stack_[1] != other.vect_stack_[1] ||
|
| + vect_stack_[2] != other.vect_stack_[2];
|
| + }
|
| +
|
| + // Dereference operator for STL-compatible iterators.
|
| + const LabelTargetPair& operator*() const {
|
| DCHECK_LT(current_index_, vect_stack_[0]->size());
|
| return (*vect_stack_[0])[current_index_];
|
| }
|
|
|
| - // The pointer to the current dependency.
|
| - const Target* target() const { return pair().ptr; }
|
| -
|
| - // The label of the current dependency.
|
| - const Label& label() const { return pair().label; }
|
| -
|
| private:
|
| const LabelTargetVector* vect_stack_[3];
|
|
|
| size_t current_index_;
|
| +};
|
| +
|
| +// Provides a virtual container implementing begin() and end() for a
|
| +// sequence of deps. This can then be used in range-based for loops.
|
| +class DepsIteratorRange {
|
| + public:
|
| + explicit DepsIteratorRange(const DepsIterator& b);
|
| + ~DepsIteratorRange();
|
| +
|
| + const DepsIterator& begin() const { return begin_; }
|
| + const DepsIterator& end() const { return end_; }
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(DepsIterator);
|
| + private:
|
| + DepsIterator begin_;
|
| + DepsIterator end_;
|
| };
|
|
|
| #endif // TOOLS_GN_DEPS_ITERATOR_H_
|
|
|