Index: tools/json_schema_compiler/util.h |
diff --git a/tools/json_schema_compiler/util.h b/tools/json_schema_compiler/util.h |
index 3365a4f69f6cb6e1177ce6f40fd0100d5cce278e..220ba80c77df5e3af43d5d2cca7fa347487d291a 100644 |
--- a/tools/json_schema_compiler/util.h |
+++ b/tools/json_schema_compiler/util.h |
@@ -2,13 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
-#define TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
+#ifndef TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_ |
+#define TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_ |
+#include <memory> |
#include <string> |
+#include <utility> |
#include <vector> |
-#include "base/memory/scoped_ptr.h" |
#include "base/values.h" |
namespace json_schema_compiler { |
@@ -17,7 +18,7 @@ namespace util { |
// Populates the item |out| from the value |from|. These are used by template |
// specializations of |Get(Optional)ArrayFromList|. |
-bool PopulateItem(const base::Value& from, scoped_ptr<base::Value>* out); |
+bool PopulateItem(const base::Value& from, std::unique_ptr<base::Value>* out); |
bool PopulateItem(const base::Value& from, int* out); |
bool PopulateItem(const base::Value& from, int* out, base::string16* error); |
@@ -34,20 +35,20 @@ bool PopulateItem(const base::Value& from, |
std::vector<char>* out, |
base::string16* error); |
bool PopulateItem(const base::Value& from, |
- scoped_ptr<base::Value>* out, |
+ std::unique_ptr<base::Value>* out, |
base::string16* error); |
-bool PopulateItem(const base::Value& from, scoped_ptr<base::Value>* out); |
+bool PopulateItem(const base::Value& from, std::unique_ptr<base::Value>* out); |
// This template is used for types generated by tools/json_schema_compiler. |
template <class T> |
-bool PopulateItem(const base::Value& from, scoped_ptr<T>* out) { |
+bool PopulateItem(const base::Value& from, std::unique_ptr<T>* out) { |
const base::DictionaryValue* dict = nullptr; |
if (!from.GetAsDictionary(&dict)) |
return false; |
- scoped_ptr<T> obj(new T()); |
+ std::unique_ptr<T> obj(new T()); |
if (!T::Populate(*dict, obj.get())) |
return false; |
- *out = scoped_ptr<T>(obj.release()); |
+ *out = std::move(obj); |
return true; |
} |
@@ -68,15 +69,15 @@ bool PopulateItem(const base::Value& from, T* out) { |
// error generation enabled. |
template <class T> |
bool PopulateItem(const base::Value& from, |
- scoped_ptr<T>* out, |
+ std::unique_ptr<T>* out, |
base::string16* error) { |
const base::DictionaryValue* dict = nullptr; |
if (!from.GetAsDictionary(&dict)) |
return false; |
- scoped_ptr<T> obj(new T()); |
+ std::unique_ptr<T> obj(new T()); |
if (!T::Populate(*dict, obj.get(), error)) |
return false; |
- *out = scoped_ptr<T>(obj.release()); |
+ *out = std::move(obj); |
return true; |
} |
@@ -133,7 +134,7 @@ bool PopulateArrayFromList(const base::ListValue& list, |
// if anything other than a list of |T| is at the specified key. |
template <class T> |
bool PopulateOptionalArrayFromList(const base::ListValue& list, |
- scoped_ptr<std::vector<T>>* out) { |
+ std::unique_ptr<std::vector<T>>* out) { |
out->reset(new std::vector<T>()); |
if (!PopulateArrayFromList(list, out->get())) { |
out->reset(); |
@@ -144,7 +145,7 @@ bool PopulateOptionalArrayFromList(const base::ListValue& list, |
template <class T> |
bool PopulateOptionalArrayFromList(const base::ListValue& list, |
- scoped_ptr<std::vector<T>>* out, |
+ std::unique_ptr<std::vector<T>>* out, |
base::string16* error) { |
out->reset(new std::vector<T>()); |
if (!PopulateArrayFromList(list, out->get(), error)) { |
@@ -161,13 +162,14 @@ void AddItemToList(const bool from, base::ListValue* out); |
void AddItemToList(const double from, base::ListValue* out); |
void AddItemToList(const std::string& from, base::ListValue* out); |
void AddItemToList(const std::vector<char>& from, base::ListValue* out); |
-void AddItemToList(const scoped_ptr<base::Value>& from, base::ListValue* out); |
-void AddItemToList(const scoped_ptr<base::DictionaryValue>& from, |
+void AddItemToList(const std::unique_ptr<base::Value>& from, |
+ base::ListValue* out); |
+void AddItemToList(const std::unique_ptr<base::DictionaryValue>& from, |
base::ListValue* out); |
// This template is used for types generated by tools/json_schema_compiler. |
template <class T> |
-void AddItemToList(const scoped_ptr<T>& from, base::ListValue* out) { |
+void AddItemToList(const std::unique_ptr<T>& from, base::ListValue* out) { |
out->Append(from->ToValue()); |
} |
@@ -189,25 +191,25 @@ void PopulateListFromArray(const std::vector<T>& from, base::ListValue* out) { |
// Set |out| to the the contents of |from| if |from| is not null. Requires |
// PopulateItem to be implemented for |T|. |
template <class T> |
-void PopulateListFromOptionalArray(const scoped_ptr<std::vector<T>>& from, |
+void PopulateListFromOptionalArray(const std::unique_ptr<std::vector<T>>& from, |
base::ListValue* out) { |
- if (from.get()) |
+ if (from) |
PopulateListFromArray(*from, out); |
} |
template <class T> |
-scoped_ptr<base::Value> CreateValueFromArray(const std::vector<T>& from) { |
- base::ListValue* list = new base::ListValue(); |
- PopulateListFromArray(from, list); |
- return scoped_ptr<base::Value>(list); |
+std::unique_ptr<base::Value> CreateValueFromArray(const std::vector<T>& from) { |
+ std::unique_ptr<base::ListValue> list(new base::ListValue()); |
+ PopulateListFromArray(from, list.get()); |
+ return std::move(list); |
} |
template <class T> |
-scoped_ptr<base::Value> CreateValueFromOptionalArray( |
- const scoped_ptr<std::vector<T>>& from) { |
- if (from.get()) |
+std::unique_ptr<base::Value> CreateValueFromOptionalArray( |
+ const std::unique_ptr<std::vector<T>>& from) { |
+ if (from) |
return CreateValueFromArray(*from); |
- return scoped_ptr<base::Value>(); |
+ return nullptr; |
} |
std::string ValueTypeToString(base::Value::Type type); |
@@ -215,4 +217,4 @@ std::string ValueTypeToString(base::Value::Type type); |
} // namespace util |
} // namespace json_schema_compiler |
-#endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
+#endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H_ |