Instrumental test for BookmarksBridge. It currently tests these functionalities:...
[chromium-blink-merge.git] / tools / gn / deps_iterator.h
blob5fc3c01e019f33eff2e9714bc4fb9fbf8d6d1fd4
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_DEPS_ITERATOR_H_
6 #define TOOLS_GN_DEPS_ITERATOR_H_
8 #include "base/basictypes.h"
9 #include "tools/gn/label_ptr.h"
11 class Target;
13 // Iterates over the deps of a target.
15 // Since there are multiple kinds of deps, this iterator allows looping over
16 // each one in one loop.
17 class DepsIterator {
18 public:
19 enum LinkedOnly {
20 LINKED_ONLY,
23 // Iterate over public, private, and data deps.
24 explicit DepsIterator(const Target* t);
26 // Iterate over the public and private linked deps, but not the data deps.
27 DepsIterator(const Target* t, LinkedOnly);
29 // Returns true when there are no more targets.
30 bool done() const {
31 return !vect_stack_[0];
34 // Advance to the next position. This assumes !done().
36 // For internal use, this function tolerates an initial index equal to the
37 // length of the current vector. In this case, it will advance to the next
38 // one.
39 void Advance();
41 // The current dependency.
42 const LabelTargetPair& pair() const {
43 DCHECK_LT(current_index_, vect_stack_[0]->size());
44 return (*vect_stack_[0])[current_index_];
47 // The pointer to the current dependency.
48 const Target* target() const { return pair().ptr; }
50 // The label of the current dependency.
51 const Label& label() const { return pair().label; }
53 private:
54 const LabelTargetVector* vect_stack_[3];
56 size_t current_index_;
58 DISALLOW_COPY_AND_ASSIGN(DepsIterator);
61 #endif // TOOLS_GN_DEPS_ITERATOR_H_