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. 4 5 #include "gn/deps_iterator.h" 6 7 #include "gn/target.h" 8 DepsIterator()9DepsIterator::DepsIterator() : current_index_(0) { 10 vect_stack_[0] = nullptr; 11 vect_stack_[1] = nullptr; 12 vect_stack_[2] = nullptr; 13 } 14 DepsIterator(const LabelTargetVector * a,const LabelTargetVector * b,const LabelTargetVector * c)15DepsIterator::DepsIterator(const LabelTargetVector* a, 16 const LabelTargetVector* b, 17 const LabelTargetVector* c) 18 : current_index_(0) { 19 vect_stack_[0] = a; 20 vect_stack_[1] = b; 21 vect_stack_[2] = c; 22 23 if (vect_stack_[0] && vect_stack_[0]->empty()) 24 operator++(); 25 } 26 27 // Advance to the next position. This assumes there are more vectors. 28 // 29 // For internal use, this function tolerates an initial index equal to the 30 // length of the current vector. In this case, it will advance to the next 31 // one. operator ++()32DepsIterator& DepsIterator::operator++() { 33 DCHECK(vect_stack_[0]); 34 35 current_index_++; 36 if (current_index_ >= vect_stack_[0]->size()) { 37 // Advance to next vect. Shift the elements left by one. 38 vect_stack_[0] = vect_stack_[1]; 39 vect_stack_[1] = vect_stack_[2]; 40 vect_stack_[2] = nullptr; 41 42 current_index_ = 0; 43 44 if (vect_stack_[0] && vect_stack_[0]->empty()) 45 operator++(); 46 } 47 return *this; 48 } 49 DepsIteratorRange(const DepsIterator & b)50DepsIteratorRange::DepsIteratorRange(const DepsIterator& b) 51 : begin_(b), end_() {} 52 53 DepsIteratorRange::~DepsIteratorRange() = default; 54