OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ | 5 #ifndef CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ |
6 #define CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ | 6 #define CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 | 13 |
14 class JSONStringValueSerializer : public ValueSerializer { | 14 class JSONStringValueSerializer : public ValueSerializer { |
15 public: | 15 public: |
16 // json_string is the string that will be source of the deserialization | 16 // json_string is the string that will be source of the deserialization |
17 // or the destination of the serialization. The caller of the constructor | 17 // or the destination of the serialization. The caller of the constructor |
18 // retains ownership of the string. | 18 // retains ownership of the string. |
19 JSONStringValueSerializer(std::string* json_string) | 19 explicit JSONStringValueSerializer(std::string* json_string) |
20 : json_string_(json_string), | 20 : json_string_(json_string), |
21 initialized_with_const_string_(false), | 21 initialized_with_const_string_(false), |
22 pretty_print_(false), | 22 pretty_print_(false), |
23 allow_trailing_comma_(false) { | 23 allow_trailing_comma_(false) { |
24 } | 24 } |
25 | 25 |
26 // This version allows initialization with a const string reference for | 26 // This version allows initialization with a const string reference for |
27 // deserialization only. | 27 // deserialization only. |
28 JSONStringValueSerializer(const std::string& json_string) | 28 explicit JSONStringValueSerializer(const std::string& json_string) |
29 : json_string_(&const_cast<std::string&>(json_string)), | 29 : json_string_(&const_cast<std::string&>(json_string)), |
30 initialized_with_const_string_(true), | 30 initialized_with_const_string_(true), |
31 pretty_print_(false), | 31 pretty_print_(false), |
32 allow_trailing_comma_(false) { | 32 allow_trailing_comma_(false) { |
33 } | 33 } |
34 | 34 |
35 ~JSONStringValueSerializer(); | 35 ~JSONStringValueSerializer(); |
36 | 36 |
37 // Attempt to serialize the data structure represented by Value into | 37 // Attempt to serialize the data structure represented by Value into |
38 // JSON. If the return value is true, the result will have been written | 38 // JSON. If the return value is true, the result will have been written |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // returned value. | 90 // returned value. |
91 Value* Deserialize(std::string* error_message); | 91 Value* Deserialize(std::string* error_message); |
92 | 92 |
93 private: | 93 private: |
94 FilePath json_file_path_; | 94 FilePath json_file_path_; |
95 | 95 |
96 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); | 96 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); |
97 }; | 97 }; |
98 | 98 |
99 #endif // CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ | 99 #endif // CHROME_COMMON_JSON_VALUE_SERIALIZER_H_ |
OLD | NEW |