| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef JSONValues_h | 31 #ifndef JSONValues_h |
| 32 #define JSONValues_h | 32 #define JSONValues_h |
| 33 | 33 |
| 34 #include "platform/PlatformExport.h" |
| 34 #include "wtf/Forward.h" | 35 #include "wtf/Forward.h" |
| 35 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
| 36 #include "wtf/RefCounted.h" | 37 #include "wtf/RefCounted.h" |
| 37 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
| 38 #include "wtf/text/StringHash.h" | 39 #include "wtf/text/StringHash.h" |
| 39 #include "wtf/text/WTFString.h" | 40 #include "wtf/text/WTFString.h" |
| 40 | 41 |
| 41 namespace WebCore { | 42 namespace WebCore { |
| 42 | 43 |
| 43 class JSONArray; | 44 class JSONArray; |
| 44 class JSONObject; | 45 class JSONObject; |
| 45 | 46 |
| 46 class JSONValue : public RefCounted<JSONValue> { | 47 class PLATFORM_EXPORT JSONValue : public RefCounted<JSONValue> { |
| 47 public: | 48 public: |
| 48 static const int maxDepth = 1000; | 49 static const int maxDepth = 1000; |
| 49 | 50 |
| 50 JSONValue() : m_type(TypeNull) { } | 51 JSONValue() : m_type(TypeNull) { } |
| 51 virtual ~JSONValue() { } | 52 virtual ~JSONValue() { } |
| 52 | 53 |
| 53 static PassRefPtr<JSONValue> null() | 54 static PassRefPtr<JSONValue> null() |
| 54 { | 55 { |
| 55 return adoptRef(new JSONValue()); | 56 return adoptRef(new JSONValue()); |
| 56 } | 57 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 String toJSONString() const; | 85 String toJSONString() const; |
| 85 virtual void writeJSON(StringBuilder* output) const; | 86 virtual void writeJSON(StringBuilder* output) const; |
| 86 | 87 |
| 87 protected: | 88 protected: |
| 88 explicit JSONValue(Type type) : m_type(type) { } | 89 explicit JSONValue(Type type) : m_type(type) { } |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 Type m_type; | 92 Type m_type; |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 class JSONBasicValue : public JSONValue { | 95 class PLATFORM_EXPORT JSONBasicValue : public JSONValue { |
| 95 public: | 96 public: |
| 96 | 97 |
| 97 static PassRefPtr<JSONBasicValue> create(bool value) | 98 static PassRefPtr<JSONBasicValue> create(bool value) |
| 98 { | 99 { |
| 99 return adoptRef(new JSONBasicValue(value)); | 100 return adoptRef(new JSONBasicValue(value)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 static PassRefPtr<JSONBasicValue> create(int value) | 103 static PassRefPtr<JSONBasicValue> create(int value) |
| 103 { | 104 { |
| 104 return adoptRef(new JSONBasicValue(value)); | 105 return adoptRef(new JSONBasicValue(value)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 122 explicit JSONBasicValue(bool value) : JSONValue(TypeBoolean), m_boolValue(va
lue) { } | 123 explicit JSONBasicValue(bool value) : JSONValue(TypeBoolean), m_boolValue(va
lue) { } |
| 123 explicit JSONBasicValue(int value) : JSONValue(TypeNumber), m_doubleValue((d
ouble)value) { } | 124 explicit JSONBasicValue(int value) : JSONValue(TypeNumber), m_doubleValue((d
ouble)value) { } |
| 124 explicit JSONBasicValue(double value) : JSONValue(TypeNumber), m_doubleValue
(value) { } | 125 explicit JSONBasicValue(double value) : JSONValue(TypeNumber), m_doubleValue
(value) { } |
| 125 | 126 |
| 126 union { | 127 union { |
| 127 bool m_boolValue; | 128 bool m_boolValue; |
| 128 double m_doubleValue; | 129 double m_doubleValue; |
| 129 }; | 130 }; |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 class JSONString : public JSONValue { | 133 class PLATFORM_EXPORT JSONString : public JSONValue { |
| 133 public: | 134 public: |
| 134 static PassRefPtr<JSONString> create(const String& value) | 135 static PassRefPtr<JSONString> create(const String& value) |
| 135 { | 136 { |
| 136 return adoptRef(new JSONString(value)); | 137 return adoptRef(new JSONString(value)); |
| 137 } | 138 } |
| 138 | 139 |
| 139 static PassRefPtr<JSONString> create(const char* value) | 140 static PassRefPtr<JSONString> create(const char* value) |
| 140 { | 141 { |
| 141 return adoptRef(new JSONString(value)); | 142 return adoptRef(new JSONString(value)); |
| 142 } | 143 } |
| 143 | 144 |
| 144 virtual bool asString(String* output) const; | 145 virtual bool asString(String* output) const; |
| 145 | 146 |
| 146 virtual void writeJSON(StringBuilder* output) const; | 147 virtual void writeJSON(StringBuilder* output) const; |
| 147 | 148 |
| 148 private: | 149 private: |
| 149 explicit JSONString(const String& value) : JSONValue(TypeString), m_stringVa
lue(value) { } | 150 explicit JSONString(const String& value) : JSONValue(TypeString), m_stringVa
lue(value) { } |
| 150 explicit JSONString(const char* value) : JSONValue(TypeString), m_stringValu
e(value) { } | 151 explicit JSONString(const char* value) : JSONValue(TypeString), m_stringValu
e(value) { } |
| 151 | 152 |
| 152 String m_stringValue; | 153 String m_stringValue; |
| 153 }; | 154 }; |
| 154 | 155 |
| 155 class JSONObjectBase : public JSONValue { | 156 class PLATFORM_EXPORT JSONObjectBase : public JSONValue { |
| 156 private: | 157 private: |
| 157 typedef HashMap<String, RefPtr<JSONValue> > Dictionary; | 158 typedef HashMap<String, RefPtr<JSONValue> > Dictionary; |
| 158 | 159 |
| 159 public: | 160 public: |
| 160 typedef Dictionary::iterator iterator; | 161 typedef Dictionary::iterator iterator; |
| 161 typedef Dictionary::const_iterator const_iterator; | 162 typedef Dictionary::const_iterator const_iterator; |
| 162 | 163 |
| 163 virtual PassRefPtr<JSONObject> asObject(); | 164 virtual PassRefPtr<JSONObject> asObject(); |
| 164 JSONObject* openAccessors(); | 165 JSONObject* openAccessors(); |
| 165 | 166 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 int size() const { return m_data.size(); } | 203 int size() const { return m_data.size(); } |
| 203 | 204 |
| 204 protected: | 205 protected: |
| 205 JSONObjectBase(); | 206 JSONObjectBase(); |
| 206 | 207 |
| 207 private: | 208 private: |
| 208 Dictionary m_data; | 209 Dictionary m_data; |
| 209 Vector<String> m_order; | 210 Vector<String> m_order; |
| 210 }; | 211 }; |
| 211 | 212 |
| 212 class JSONObject : public JSONObjectBase { | 213 class PLATFORM_EXPORT JSONObject : public JSONObjectBase { |
| 213 public: | 214 public: |
| 214 static PassRefPtr<JSONObject> create() | 215 static PassRefPtr<JSONObject> create() |
| 215 { | 216 { |
| 216 return adoptRef(new JSONObject()); | 217 return adoptRef(new JSONObject()); |
| 217 } | 218 } |
| 218 | 219 |
| 219 using JSONObjectBase::asObject; | 220 using JSONObjectBase::asObject; |
| 220 | 221 |
| 221 using JSONObjectBase::setBoolean; | 222 using JSONObjectBase::setBoolean; |
| 222 using JSONObjectBase::setNumber; | 223 using JSONObjectBase::setNumber; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 235 | 236 |
| 236 using JSONObjectBase::remove; | 237 using JSONObjectBase::remove; |
| 237 | 238 |
| 238 using JSONObjectBase::begin; | 239 using JSONObjectBase::begin; |
| 239 using JSONObjectBase::end; | 240 using JSONObjectBase::end; |
| 240 | 241 |
| 241 using JSONObjectBase::size; | 242 using JSONObjectBase::size; |
| 242 }; | 243 }; |
| 243 | 244 |
| 244 | 245 |
| 245 class JSONArrayBase : public JSONValue { | 246 class PLATFORM_EXPORT JSONArrayBase : public JSONValue { |
| 246 public: | 247 public: |
| 247 typedef Vector<RefPtr<JSONValue> >::iterator iterator; | 248 typedef Vector<RefPtr<JSONValue> >::iterator iterator; |
| 248 typedef Vector<RefPtr<JSONValue> >::const_iterator const_iterator; | 249 typedef Vector<RefPtr<JSONValue> >::const_iterator const_iterator; |
| 249 | 250 |
| 250 virtual PassRefPtr<JSONArray> asArray(); | 251 virtual PassRefPtr<JSONArray> asArray(); |
| 251 | 252 |
| 252 unsigned length() const { return m_data.size(); } | 253 unsigned length() const { return m_data.size(); } |
| 253 | 254 |
| 254 protected: | 255 protected: |
| 255 ~JSONArrayBase(); | 256 ~JSONArrayBase(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 273 const_iterator begin() const { return m_data.begin(); } | 274 const_iterator begin() const { return m_data.begin(); } |
| 274 const_iterator end() const { return m_data.end(); } | 275 const_iterator end() const { return m_data.end(); } |
| 275 | 276 |
| 276 protected: | 277 protected: |
| 277 JSONArrayBase(); | 278 JSONArrayBase(); |
| 278 | 279 |
| 279 private: | 280 private: |
| 280 Vector<RefPtr<JSONValue> > m_data; | 281 Vector<RefPtr<JSONValue> > m_data; |
| 281 }; | 282 }; |
| 282 | 283 |
| 283 class JSONArray : public JSONArrayBase { | 284 class PLATFORM_EXPORT JSONArray : public JSONArrayBase { |
| 284 public: | 285 public: |
| 285 static PassRefPtr<JSONArray> create() | 286 static PassRefPtr<JSONArray> create() |
| 286 { | 287 { |
| 287 return adoptRef(new JSONArray()); | 288 return adoptRef(new JSONArray()); |
| 288 } | 289 } |
| 289 | 290 |
| 290 using JSONArrayBase::asArray; | 291 using JSONArrayBase::asArray; |
| 291 | 292 |
| 292 using JSONArrayBase::pushBoolean; | 293 using JSONArrayBase::pushBoolean; |
| 293 using JSONArrayBase::pushInt; | 294 using JSONArrayBase::pushInt; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 385 |
| 385 inline void JSONArrayBase::pushArray(PassRefPtr<JSONArray> value) | 386 inline void JSONArrayBase::pushArray(PassRefPtr<JSONArray> value) |
| 386 { | 387 { |
| 387 ASSERT(value); | 388 ASSERT(value); |
| 388 m_data.append(value); | 389 m_data.append(value); |
| 389 } | 390 } |
| 390 | 391 |
| 391 } // namespace WebCore | 392 } // namespace WebCore |
| 392 | 393 |
| 393 #endif // !defined(JSONValues_h) | 394 #endif // !defined(JSONValues_h) |
| OLD | NEW |