autofill_scanner.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2013 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#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_
6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/strings/string16.h"
12
13namespace autofill {
14
15class AutofillField;
16
17// A helper class for parsing a stream of |AutofillField|'s with lookahead.
18class AutofillScanner {
19 public:
20  explicit AutofillScanner(std::vector<AutofillField*>& fields);
21  ~AutofillScanner();
22
23  // Advances the cursor by one step, if possible.
24  void Advance();
25
26  // Returns the current field in the stream, or |NULL| if there are no more
27  // fields in the stream.
28  AutofillField* Cursor() const;
29
30  // Returns |true| if the cursor has reached the end of the stream.
31  bool IsEnd() const;
32
33  // Restores the most recently saved cursor. See also |SaveCursor()|.
34  void Rewind();
35
36  // Repositions the cursor to the specified |index|. See also |SaveCursor()|.
37  void RewindTo(size_t index);
38
39  // Saves and returns the current cursor position. See also |Rewind()| and
40  // |RewindTo()|.
41  size_t SaveCursor();
42
43 private:
44  // Indicates the current position in the stream, represented as a vector.
45  std::vector<AutofillField*>::const_iterator cursor_;
46
47  // The most recently saved cursor.
48  std::vector<AutofillField*>::const_iterator saved_cursor_;
49
50  // The beginning pointer for the stream.
51  const std::vector<AutofillField*>::iterator begin_;
52
53  // The past-the-end pointer for the stream.
54  const std::vector<AutofillField*>::iterator end_;
55
56  DISALLOW_COPY_AND_ASSIGN(AutofillScanner);
57};
58
59}  // namespace autofill
60
61#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_SCANNER_H_
62