OLD | NEW |
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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 | 14 |
15 namespace json_schema_compiler { | 15 namespace json_schema_compiler { |
16 | 16 |
17 namespace util { | 17 namespace util { |
18 | 18 |
19 // Populates the item |out| from the value |from|. These are used by template | 19 // Populates the item |out| from the value |from|. These are used by template |
20 // specializations of |Get(Optional)ArrayFromList|. | 20 // specializations of |Get(Optional)ArrayFromList|. |
21 bool PopulateItem(const base::Value& from, int* out); | 21 bool PopulateItem(const base::Value& from, int* out); |
22 bool PopulateItem(const base::Value& from, bool* out); | 22 bool PopulateItem(const base::Value& from, bool* out); |
23 bool PopulateItem(const base::Value& from, double* out); | 23 bool PopulateItem(const base::Value& from, double* out); |
24 bool PopulateItem(const base::Value& from, std::string* out); | 24 bool PopulateItem(const base::Value& from, std::string* out); |
| 25 bool PopulateItem(const base::Value& from, std::vector<char>* out); |
25 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out); | 26 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out); |
26 bool PopulateItem(const base::Value& from, | 27 bool PopulateItem(const base::Value& from, |
27 linked_ptr<base::DictionaryValue>* out); | 28 linked_ptr<base::DictionaryValue>* out); |
28 | 29 |
29 // This template is used for types generated by tools/json_schema_compiler. | 30 // This template is used for types generated by tools/json_schema_compiler. |
30 template <class T> | 31 template <class T> |
31 bool PopulateItem(const base::Value& from, linked_ptr<T>* out) { | 32 bool PopulateItem(const base::Value& from, linked_ptr<T>* out) { |
32 const base::DictionaryValue* dict = nullptr; | 33 const base::DictionaryValue* dict = nullptr; |
33 if (!from.GetAsDictionary(&dict)) | 34 if (!from.GetAsDictionary(&dict)) |
34 return false; | 35 return false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 68 } |
68 return true; | 69 return true; |
69 } | 70 } |
70 | 71 |
71 // Appends a Value newly created from |from| to |out|. These used by template | 72 // Appends a Value newly created from |from| to |out|. These used by template |
72 // specializations of |Set(Optional)ArrayToList|. | 73 // specializations of |Set(Optional)ArrayToList|. |
73 void AddItemToList(const int from, base::ListValue* out); | 74 void AddItemToList(const int from, base::ListValue* out); |
74 void AddItemToList(const bool from, base::ListValue* out); | 75 void AddItemToList(const bool from, base::ListValue* out); |
75 void AddItemToList(const double from, base::ListValue* out); | 76 void AddItemToList(const double from, base::ListValue* out); |
76 void AddItemToList(const std::string& from, base::ListValue* out); | 77 void AddItemToList(const std::string& from, base::ListValue* out); |
| 78 void AddItemToList(const std::vector<char>& from, base::ListValue* out); |
77 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out); | 79 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out); |
78 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, | 80 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, |
79 base::ListValue* out); | 81 base::ListValue* out); |
80 | 82 |
81 // This template is used for types generated by tools/json_schema_compiler. | 83 // This template is used for types generated by tools/json_schema_compiler. |
82 template <class T> | 84 template <class T> |
83 void AddItemToList(const linked_ptr<T>& from, base::ListValue* out) { | 85 void AddItemToList(const linked_ptr<T>& from, base::ListValue* out) { |
84 out->Append(from->ToValue().release()); | 86 out->Append(from->ToValue().release()); |
85 } | 87 } |
86 | 88 |
(...skipping 28 matching lines...) Expand all Loading... |
115 if (from.get()) | 117 if (from.get()) |
116 return CreateValueFromArray(*from); | 118 return CreateValueFromArray(*from); |
117 return scoped_ptr<base::Value>(); | 119 return scoped_ptr<base::Value>(); |
118 } | 120 } |
119 | 121 |
120 std::string ValueTypeToString(base::Value::Type type); | 122 std::string ValueTypeToString(base::Value::Type type); |
121 | 123 |
122 } // namespace util | 124 } // namespace util |
123 } // namespace json_schema_compiler | 125 } // namespace json_schema_compiler |
124 | 126 |
125 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ | 127 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
OLD | NEW |