blob: 8349a4b225eb5e1548e9598ff112676ccbe36581 [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <memory>
#include <string>
#include "shill/accessor_interface.h"
#include "shill/error.h"
namespace shill {
// An iterator wrapper class to hide the details of what kind of data structure
// we're using to store key/value pairs for properties. It is intended for use
// with PropertyStore and always advances to the next readable property.
template <class V>
class ReadablePropertyConstIterator {
~ReadablePropertyConstIterator() = default;
bool AtEnd() const { return it_ == collection_.end(); }
void Advance() {
if (!AtEnd()) {
do {
} while (MustAdvance());
const std::string& Key() const { return it_->first; }
const V& value() const { return value_; }
friend class PropertyStore;
explicit ReadablePropertyConstIterator(const AccessorMap<V>& collection)
: collection_(collection), it_(collection_.begin()), value_() {
if (MustAdvance()) {
bool MustAdvance() { return !AtEnd() && !RetrieveCurrentValue(); }
bool RetrieveCurrentValue() {
Error error;
value_ = it_->second->Get(&error);
return error.IsSuccess();
const AccessorMap<V>& collection_;
typename AccessorMap<V>::const_iterator it_;
V value_;
} // namespace shill