Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 1 | // 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 | |
| 13 | namespace 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. |
| 18 | template <class V> |
| 19 | class 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 | |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 29 | const V &Value() const { return it_->second->Get(); } |
Chris Masone | a8a2c25 | 2011-06-27 22:16:30 -0700 | [diff] [blame] | 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_ |