Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: tools/json_schema_compiler/util.h

Issue 2816513002: Revert of Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | ui/app_list/search/history_data_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_ 5 #ifndef TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_
6 #define TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_ 6 #define TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return true; 95 return true;
96 } 96 }
97 97
98 // Populates |out| with |list|. Returns false if there is no list at the 98 // Populates |out| with |list|. Returns false if there is no list at the
99 // specified key or if the list has anything other than |T|. 99 // specified key or if the list has anything other than |T|.
100 template <class T> 100 template <class T>
101 bool PopulateArrayFromList(const base::ListValue& list, std::vector<T>* out) { 101 bool PopulateArrayFromList(const base::ListValue& list, std::vector<T>* out) {
102 out->clear(); 102 out->clear();
103 T item; 103 T item;
104 for (const auto& value : list) { 104 for (const auto& value : list) {
105 if (!PopulateItem(value, &item)) 105 if (!PopulateItem(*value, &item))
106 return false; 106 return false;
107 // T might not be movable, but in that case it should be copyable, and this 107 // T might not be movable, but in that case it should be copyable, and this
108 // will still work. 108 // will still work.
109 out->push_back(std::move(item)); 109 out->push_back(std::move(item));
110 } 110 }
111 111
112 return true; 112 return true;
113 } 113 }
114 114
115 // Populates |out| with |list|. Returns false and sets |error| if there is no 115 // Populates |out| with |list|. Returns false and sets |error| if there is no
116 // list at the specified key or if the list has anything other than |T|. 116 // list at the specified key or if the list has anything other than |T|.
117 template <class T> 117 template <class T>
118 bool PopulateArrayFromList(const base::ListValue& list, 118 bool PopulateArrayFromList(const base::ListValue& list,
119 std::vector<T>* out, 119 std::vector<T>* out,
120 base::string16* error) { 120 base::string16* error) {
121 out->clear(); 121 out->clear();
122 T item; 122 T item;
123 for (const auto& value : list) { 123 for (const auto& value : list) {
124 if (!PopulateItem(value, &item, error)) 124 if (!PopulateItem(*value, &item, error))
125 return false; 125 return false;
126 out->push_back(std::move(item)); 126 out->push_back(std::move(item));
127 } 127 }
128 128
129 return true; 129 return true;
130 } 130 }
131 131
132 // Creates a new vector containing |list| at |out|. Returns 132 // Creates a new vector containing |list| at |out|. Returns
133 // true on success or if there is nothing at the specified key. Returns false 133 // true on success or if there is nothing at the specified key. Returns false
134 // if anything other than a list of |T| is at the specified key. 134 // if anything other than a list of |T| is at the specified key.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 template <class T> 207 template <class T>
208 std::unique_ptr<base::Value> CreateValueFromOptionalArray( 208 std::unique_ptr<base::Value> CreateValueFromOptionalArray(
209 const std::unique_ptr<std::vector<T>>& from) { 209 const std::unique_ptr<std::vector<T>>& from) {
210 return from ? CreateValueFromArray(*from) : nullptr; 210 return from ? CreateValueFromArray(*from) : nullptr;
211 } 211 }
212 212
213 } // namespace util 213 } // namespace util
214 } // namespace json_schema_compiler 214 } // namespace json_schema_compiler
215 215
216 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_ 216 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | ui/app_list/search/history_data_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698