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 BASE_JSON_JSON_VALUE_CONVERTER_H_ | 5 #ifndef BASE_JSON_JSON_VALUE_CONVERTER_H_ |
6 #define BASE_JSON_JSON_VALUE_CONVERTER_H_ | 6 #define BASE_JSON_JSON_VALUE_CONVERTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/base_export.h" |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 | 20 |
20 // JSONValueConverter converts a JSON value into a C++ struct in a | 21 // JSONValueConverter converts a JSON value into a C++ struct in a |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 private: | 131 private: |
131 FieldType StructType::* field_pointer_; | 132 FieldType StructType::* field_pointer_; |
132 scoped_ptr<ValueConverter<FieldType> > value_converter_; | 133 scoped_ptr<ValueConverter<FieldType> > value_converter_; |
133 DISALLOW_COPY_AND_ASSIGN(FieldConverter); | 134 DISALLOW_COPY_AND_ASSIGN(FieldConverter); |
134 }; | 135 }; |
135 | 136 |
136 template <typename FieldType> | 137 template <typename FieldType> |
137 class BasicValueConverter; | 138 class BasicValueConverter; |
138 | 139 |
139 template <> | 140 template <> |
140 class BasicValueConverter<int> : public ValueConverter<int> { | 141 class BASE_EXPORT BasicValueConverter<int> : public ValueConverter<int> { |
141 public: | 142 public: |
142 BasicValueConverter() {} | 143 BasicValueConverter() {} |
143 | 144 |
144 virtual bool Convert(const base::Value& value, int* field) const override { | 145 bool Convert(const base::Value& value, int* field) const override; |
145 return value.GetAsInteger(field); | |
146 } | |
147 | 146 |
148 private: | 147 private: |
149 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); | 148 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); |
150 }; | 149 }; |
151 | 150 |
152 template <> | 151 template <> |
153 class BasicValueConverter<std::string> : public ValueConverter<std::string> { | 152 class BASE_EXPORT BasicValueConverter<std::string> |
| 153 : public ValueConverter<std::string> { |
154 public: | 154 public: |
155 BasicValueConverter() {} | 155 BasicValueConverter() {} |
156 | 156 |
157 virtual bool Convert( | 157 bool Convert(const base::Value& value, std::string* field) const override; |
158 const base::Value& value, std::string* field) const override { | |
159 return value.GetAsString(field); | |
160 } | |
161 | 158 |
162 private: | 159 private: |
163 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); | 160 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); |
164 }; | 161 }; |
165 | 162 |
166 template <> | 163 template <> |
167 class BasicValueConverter<string16> : public ValueConverter<string16> { | 164 class BASE_EXPORT BasicValueConverter<string16> |
| 165 : public ValueConverter<string16> { |
168 public: | 166 public: |
169 BasicValueConverter() {} | 167 BasicValueConverter() {} |
170 | 168 |
171 virtual bool Convert( | 169 bool Convert(const base::Value& value, string16* field) const override; |
172 const base::Value& value, string16* field) const override { | |
173 return value.GetAsString(field); | |
174 } | |
175 | 170 |
176 private: | 171 private: |
177 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); | 172 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); |
178 }; | 173 }; |
179 | 174 |
180 template <> | 175 template <> |
181 class BasicValueConverter<double> : public ValueConverter<double> { | 176 class BASE_EXPORT BasicValueConverter<double> : public ValueConverter<double> { |
182 public: | 177 public: |
183 BasicValueConverter() {} | 178 BasicValueConverter() {} |
184 | 179 |
185 virtual bool Convert(const base::Value& value, double* field) const override { | 180 bool Convert(const base::Value& value, double* field) const override; |
186 return value.GetAsDouble(field); | |
187 } | |
188 | 181 |
189 private: | 182 private: |
190 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); | 183 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); |
191 }; | 184 }; |
192 | 185 |
193 template <> | 186 template <> |
194 class BasicValueConverter<bool> : public ValueConverter<bool> { | 187 class BASE_EXPORT BasicValueConverter<bool> : public ValueConverter<bool> { |
195 public: | 188 public: |
196 BasicValueConverter() {} | 189 BasicValueConverter() {} |
197 | 190 |
198 virtual bool Convert(const base::Value& value, bool* field) const override { | 191 bool Convert(const base::Value& value, bool* field) const override; |
199 return value.GetAsBoolean(field); | |
200 } | |
201 | 192 |
202 private: | 193 private: |
203 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); | 194 DISALLOW_COPY_AND_ASSIGN(BasicValueConverter); |
204 }; | 195 }; |
205 | 196 |
206 template <typename FieldType> | 197 template <typename FieldType> |
207 class ValueFieldConverter : public ValueConverter<FieldType> { | 198 class ValueFieldConverter : public ValueConverter<FieldType> { |
208 public: | 199 public: |
209 typedef bool(*ConvertFunc)(const base::Value* value, FieldType* field); | 200 typedef bool(*ConvertFunc)(const base::Value* value, FieldType* field); |
210 | 201 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 509 |
519 private: | 510 private: |
520 ScopedVector<internal::FieldConverterBase<StructType> > fields_; | 511 ScopedVector<internal::FieldConverterBase<StructType> > fields_; |
521 | 512 |
522 DISALLOW_COPY_AND_ASSIGN(JSONValueConverter); | 513 DISALLOW_COPY_AND_ASSIGN(JSONValueConverter); |
523 }; | 514 }; |
524 | 515 |
525 } // namespace base | 516 } // namespace base |
526 | 517 |
527 #endif // BASE_JSON_JSON_VALUE_CONVERTER_H_ | 518 #endif // BASE_JSON_JSON_VALUE_CONVERTER_H_ |
OLD | NEW |