blob: 9c52d5af9b5e6de19794a2878d0a08170485bcef [file] [log] [blame]
Chris Masonea8a2c252011-06-27 22:16:30 -07001// Copyright (c) 2011 The Chromium OS 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 SHILL_PROPERTY_ITERATOR_
6#define SHILL_PROPERTY_ITERATOR_
7
8#include <map>
9#include <string>
10
11#include "shill/accessor_interface.h"
12
13namespace shill {
14
15// An iterator wrapper class to hide the details of what kind of data structure
16// we're using to store key/value pairs for properties.
17// Intended for use with PropertyStore.
18template <class V>
19class PropertyConstIterator {
20 public:
21 virtual ~PropertyConstIterator() {}
22
23 void Advance() { ++it_; }
24
25 bool AtEnd() { return it_ == collection_.end(); }
26
27 const std::string &Key() const { return it_->first; }
28
29 const V &Value() { return it_->second->Get(); }
30
31 private:
32 friend class PropertyStore;
33
34 typedef std::tr1::shared_ptr<AccessorInterface<V> > VAccessorPtr;
35
36 explicit PropertyConstIterator(
37 const typename std::map<std::string, VAccessorPtr> &collection)
38 : collection_(collection),
39 it_(collection_.begin()) {
40 }
41
42 const typename std::map<std::string, VAccessorPtr> &collection_;
43 typename std::map<std::string, VAccessorPtr>::const_iterator it_;
44};
45
46
47
48} // namespace shill
49
50#endif // SHILL_PROPERTY_ITERATOR_