OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/values.h" | 5 #include "base/values.h" |
6 | 6 |
7 #include "base/float_util.h" | 7 #include "base/float_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 delete copy; | 51 delete copy; |
52 return NULL; | 52 return NULL; |
53 } | 53 } |
54 | 54 |
55 default: | 55 default: |
56 // For everything else, just make a copy. | 56 // For everything else, just make a copy. |
57 return node->DeepCopy(); | 57 return node->DeepCopy(); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 // A small functor for comparing Values for std::find_if and similar. | |
62 class CompareValues { | |
Mattias Nissler (ping if slow)
2011/09/15 13:40:39
Maybe ValueEquals? It isn't really useful as a com
pastarmovj
2011/09/16 08:03:49
Done. Actually picked something even more specific
| |
63 public: | |
64 CompareValues(const Value& first) : first_(first) { } | |
65 | |
66 bool operator ()(const Value* second) const { | |
67 return first_.Equals(second); | |
68 } | |
69 | |
70 private: | |
71 const Value& first_; | |
Mattias Nissler (ping if slow)
2011/09/15 13:40:39
In chromium, we'd usually use a pointer for this.
pastarmovj
2011/09/16 08:03:49
Done.
| |
72 }; | |
73 | |
61 } // namespace | 74 } // namespace |
62 | 75 |
63 namespace base { | 76 namespace base { |
64 | 77 |
65 ///////////////////// Value //////////////////// | 78 ///////////////////// Value //////////////////// |
66 | 79 |
67 Value::~Value() { | 80 Value::~Value() { |
68 } | 81 } |
69 | 82 |
70 // static | 83 // static |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 | 871 |
859 bool ListValue::Insert(size_t index, Value* in_value) { | 872 bool ListValue::Insert(size_t index, Value* in_value) { |
860 DCHECK(in_value); | 873 DCHECK(in_value); |
861 if (index > list_.size()) | 874 if (index > list_.size()) |
862 return false; | 875 return false; |
863 | 876 |
864 list_.insert(list_.begin() + index, in_value); | 877 list_.insert(list_.begin() + index, in_value); |
865 return true; | 878 return true; |
866 } | 879 } |
867 | 880 |
881 ListValue::const_iterator ListValue::Find(const Value& value) const { | |
882 CompareValues compare(value); | |
883 return std::find_if(list_.begin(), list_.end(), compare); | |
884 } | |
885 | |
868 bool ListValue::GetAsList(ListValue** out_value) { | 886 bool ListValue::GetAsList(ListValue** out_value) { |
869 if (out_value) | 887 if (out_value) |
870 *out_value = this; | 888 *out_value = this; |
871 return true; | 889 return true; |
872 } | 890 } |
873 | 891 |
874 bool ListValue::GetAsList(const ListValue** out_value) const { | 892 bool ListValue::GetAsList(const ListValue** out_value) const { |
875 if (out_value) | 893 if (out_value) |
876 *out_value = this; | 894 *out_value = this; |
877 return true; | 895 return true; |
(...skipping 24 matching lines...) Expand all Loading... | |
902 if (lhs_it != end() || rhs_it != other_list->end()) | 920 if (lhs_it != end() || rhs_it != other_list->end()) |
903 return false; | 921 return false; |
904 | 922 |
905 return true; | 923 return true; |
906 } | 924 } |
907 | 925 |
908 ValueSerializer::~ValueSerializer() { | 926 ValueSerializer::~ValueSerializer() { |
909 } | 927 } |
910 | 928 |
911 } // namespace base | 929 } // namespace base |
OLD | NEW |