Home | History | Annotate | Download | only in policy
      1 // Copyright (c) 2011 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 "chrome/browser/policy/policy_map.h"
      6 
      7 #include <algorithm>
      8 
      9 #include "base/stl_util-inl.h"
     10 
     11 namespace policy {
     12 
     13 PolicyMap::PolicyMap() {
     14 }
     15 
     16 PolicyMap::~PolicyMap() {
     17   Clear();
     18 }
     19 
     20 const Value* PolicyMap::Get(ConfigurationPolicyType policy) const {
     21   PolicyMapType::const_iterator entry = map_.find(policy);
     22   return entry == map_.end() ? NULL : entry->second;
     23 }
     24 
     25 void PolicyMap::Set(ConfigurationPolicyType policy, Value* value) {
     26   std::swap(map_[policy], value);
     27   delete value;
     28 }
     29 
     30 void PolicyMap::Erase(ConfigurationPolicyType policy) {
     31   const const_iterator entry = map_.find(policy);
     32   if (entry != map_.end()) {
     33     delete entry->second;
     34     map_.erase(entry->first);
     35   }
     36 }
     37 
     38 void PolicyMap::Swap(PolicyMap* other) {
     39   map_.swap(other->map_);
     40 }
     41 
     42 bool PolicyMap::Equals(const PolicyMap& other) const {
     43   return other.map_.size() == map_.size() &&
     44       std::equal(map_.begin(), map_.end(), other.map_.begin(), MapEntryEquals);
     45 }
     46 
     47 bool PolicyMap::empty() const {
     48   return map_.empty();
     49 }
     50 
     51 size_t PolicyMap::size() const {
     52   return map_.size();
     53 }
     54 
     55 PolicyMap::const_iterator PolicyMap::begin() const {
     56   return map_.begin();
     57 }
     58 
     59 PolicyMap::const_iterator PolicyMap::end() const {
     60   return map_.end();
     61 }
     62 
     63 void PolicyMap::Clear() {
     64   STLDeleteValues(&map_);
     65 }
     66 
     67 // static
     68 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a,
     69                                const PolicyMap::PolicyMapType::value_type& b) {
     70   return a.first == b.first && Value::Equals(a.second, b.second);
     71 }
     72 
     73 }  // namespace policy
     74