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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 static PassRefPtr<JSONBasicValue> create(int value) | 109 static PassRefPtr<JSONBasicValue> create(int value) |
110 { | 110 { |
111 return adoptRef(new JSONBasicValue(value)); | 111 return adoptRef(new JSONBasicValue(value)); |
112 } | 112 } |
113 | 113 |
114 static PassRefPtr<JSONBasicValue> create(double value) | 114 static PassRefPtr<JSONBasicValue> create(double value) |
115 { | 115 { |
116 return adoptRef(new JSONBasicValue(value)); | 116 return adoptRef(new JSONBasicValue(value)); |
117 } | 117 } |
118 | 118 |
119 virtual bool asBoolean(bool* output) const OVERRIDE; | 119 virtual bool asBoolean(bool* output) const override; |
120 virtual bool asNumber(double* output) const OVERRIDE; | 120 virtual bool asNumber(double* output) const override; |
121 virtual bool asNumber(long* output) const OVERRIDE; | 121 virtual bool asNumber(long* output) const override; |
122 virtual bool asNumber(int* output) const OVERRIDE; | 122 virtual bool asNumber(int* output) const override; |
123 virtual bool asNumber(unsigned long* output) const OVERRIDE; | 123 virtual bool asNumber(unsigned long* output) const override; |
124 virtual bool asNumber(unsigned* output) const OVERRIDE; | 124 virtual bool asNumber(unsigned* output) const override; |
125 | 125 |
126 virtual void writeJSON(StringBuilder* output) const OVERRIDE; | 126 virtual void writeJSON(StringBuilder* output) const override; |
127 | 127 |
128 private: | 128 private: |
129 explicit JSONBasicValue(bool value) : JSONValue(TypeBoolean), m_boolValue(va
lue) { } | 129 explicit JSONBasicValue(bool value) : JSONValue(TypeBoolean), m_boolValue(va
lue) { } |
130 explicit JSONBasicValue(int value) : JSONValue(TypeNumber), m_doubleValue((d
ouble)value) { } | 130 explicit JSONBasicValue(int value) : JSONValue(TypeNumber), m_doubleValue((d
ouble)value) { } |
131 explicit JSONBasicValue(double value) : JSONValue(TypeNumber), m_doubleValue
(value) { } | 131 explicit JSONBasicValue(double value) : JSONValue(TypeNumber), m_doubleValue
(value) { } |
132 | 132 |
133 union { | 133 union { |
134 bool m_boolValue; | 134 bool m_boolValue; |
135 double m_doubleValue; | 135 double m_doubleValue; |
136 }; | 136 }; |
137 }; | 137 }; |
138 | 138 |
139 class PLATFORM_EXPORT JSONString : public JSONValue { | 139 class PLATFORM_EXPORT JSONString : public JSONValue { |
140 public: | 140 public: |
141 static PassRefPtr<JSONString> create(const String& value) | 141 static PassRefPtr<JSONString> create(const String& value) |
142 { | 142 { |
143 return adoptRef(new JSONString(value)); | 143 return adoptRef(new JSONString(value)); |
144 } | 144 } |
145 | 145 |
146 static PassRefPtr<JSONString> create(const char* value) | 146 static PassRefPtr<JSONString> create(const char* value) |
147 { | 147 { |
148 return adoptRef(new JSONString(value)); | 148 return adoptRef(new JSONString(value)); |
149 } | 149 } |
150 | 150 |
151 virtual bool asString(String* output) const OVERRIDE; | 151 virtual bool asString(String* output) const override; |
152 | 152 |
153 virtual void writeJSON(StringBuilder* output) const OVERRIDE; | 153 virtual void writeJSON(StringBuilder* output) const override; |
154 | 154 |
155 private: | 155 private: |
156 explicit JSONString(const String& value) : JSONValue(TypeString), m_stringVa
lue(value) { } | 156 explicit JSONString(const String& value) : JSONValue(TypeString), m_stringVa
lue(value) { } |
157 explicit JSONString(const char* value) : JSONValue(TypeString), m_stringValu
e(value) { } | 157 explicit JSONString(const char* value) : JSONValue(TypeString), m_stringValu
e(value) { } |
158 | 158 |
159 String m_stringValue; | 159 String m_stringValue; |
160 }; | 160 }; |
161 | 161 |
162 class PLATFORM_EXPORT JSONObjectBase : public JSONValue { | 162 class PLATFORM_EXPORT JSONObjectBase : public JSONValue { |
163 private: | 163 private: |
164 typedef HashMap<String, RefPtr<JSONValue> > Dictionary; | 164 typedef HashMap<String, RefPtr<JSONValue> > Dictionary; |
165 | 165 |
166 public: | 166 public: |
167 typedef Dictionary::iterator iterator; | 167 typedef Dictionary::iterator iterator; |
168 typedef Dictionary::const_iterator const_iterator; | 168 typedef Dictionary::const_iterator const_iterator; |
169 | 169 |
170 virtual PassRefPtr<JSONObject> asObject() OVERRIDE; | 170 virtual PassRefPtr<JSONObject> asObject() override; |
171 JSONObject* openAccessors(); | 171 JSONObject* openAccessors(); |
172 | 172 |
173 virtual void writeJSON(StringBuilder* output) const OVERRIDE; | 173 virtual void writeJSON(StringBuilder* output) const override; |
174 | 174 |
175 protected: | 175 protected: |
176 virtual ~JSONObjectBase(); | 176 virtual ~JSONObjectBase(); |
177 | 177 |
178 virtual bool asObject(RefPtr<JSONObject>* output) OVERRIDE; | 178 virtual bool asObject(RefPtr<JSONObject>* output) override; |
179 | 179 |
180 void setBoolean(const String& name, bool); | 180 void setBoolean(const String& name, bool); |
181 void setNumber(const String& name, double); | 181 void setNumber(const String& name, double); |
182 void setString(const String& name, const String&); | 182 void setString(const String& name, const String&); |
183 void setValue(const String& name, PassRefPtr<JSONValue>); | 183 void setValue(const String& name, PassRefPtr<JSONValue>); |
184 void setObject(const String& name, PassRefPtr<JSONObject>); | 184 void setObject(const String& name, PassRefPtr<JSONObject>); |
185 void setArray(const String& name, PassRefPtr<JSONArray>); | 185 void setArray(const String& name, PassRefPtr<JSONArray>); |
186 | 186 |
187 iterator find(const String& name); | 187 iterator find(const String& name); |
188 const_iterator find(const String& name) const; | 188 const_iterator find(const String& name) const; |
189 bool getBoolean(const String& name, bool* output) const; | 189 bool getBoolean(const String& name, bool* output) const; |
190 template<class T> bool getNumber(const String& name, T* output) const | 190 template<class T> bool getNumber(const String& name, T* output) const |
191 { | 191 { |
192 RefPtr<JSONValue> value = get(name); | 192 RefPtr<JSONValue> value = get(name); |
193 if (!value) | 193 if (!value) |
194 return false; | 194 return false; |
195 return value->asNumber(output); | 195 return value->asNumber(output); |
196 } | 196 } |
197 bool getString(const String& name, String* output) const; | 197 bool getString(const String& name, String* output) const; |
198 PassRefPtr<JSONObject> getObject(const String& name) const; | 198 PassRefPtr<JSONObject> getObject(const String& name) const; |
199 PassRefPtr<JSONArray> getArray(const String& name) const; | 199 PassRefPtr<JSONArray> getArray(const String& name) const; |
200 PassRefPtr<JSONValue> get(const String& name) const; | 200 PassRefPtr<JSONValue> get(const String& name) const; |
201 | 201 |
202 void remove(const String& name); | 202 void remove(const String& name); |
203 | 203 |
204 virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const
OVERRIDE; | 204 virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const
override; |
205 | 205 |
206 iterator begin() { return m_data.begin(); } | 206 iterator begin() { return m_data.begin(); } |
207 iterator end() { return m_data.end(); } | 207 iterator end() { return m_data.end(); } |
208 const_iterator begin() const { return m_data.begin(); } | 208 const_iterator begin() const { return m_data.begin(); } |
209 const_iterator end() const { return m_data.end(); } | 209 const_iterator end() const { return m_data.end(); } |
210 | 210 |
211 int size() const { return m_data.size(); } | 211 int size() const { return m_data.size(); } |
212 | 212 |
213 protected: | 213 protected: |
214 JSONObjectBase(); | 214 JSONObjectBase(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 249 |
250 using JSONObjectBase::size; | 250 using JSONObjectBase::size; |
251 }; | 251 }; |
252 | 252 |
253 | 253 |
254 class PLATFORM_EXPORT JSONArrayBase : public JSONValue { | 254 class PLATFORM_EXPORT JSONArrayBase : public JSONValue { |
255 public: | 255 public: |
256 typedef Vector<RefPtr<JSONValue> >::iterator iterator; | 256 typedef Vector<RefPtr<JSONValue> >::iterator iterator; |
257 typedef Vector<RefPtr<JSONValue> >::const_iterator const_iterator; | 257 typedef Vector<RefPtr<JSONValue> >::const_iterator const_iterator; |
258 | 258 |
259 virtual PassRefPtr<JSONArray> asArray() OVERRIDE; | 259 virtual PassRefPtr<JSONArray> asArray() override; |
260 | 260 |
261 unsigned length() const { return m_data.size(); } | 261 unsigned length() const { return m_data.size(); } |
262 | 262 |
263 virtual void writeJSON(StringBuilder* output) const OVERRIDE; | 263 virtual void writeJSON(StringBuilder* output) const override; |
264 | 264 |
265 protected: | 265 protected: |
266 virtual ~JSONArrayBase(); | 266 virtual ~JSONArrayBase(); |
267 | 267 |
268 virtual bool asArray(RefPtr<JSONArray>* output) OVERRIDE; | 268 virtual bool asArray(RefPtr<JSONArray>* output) override; |
269 | 269 |
270 void pushBoolean(bool); | 270 void pushBoolean(bool); |
271 void pushInt(int); | 271 void pushInt(int); |
272 void pushNumber(double); | 272 void pushNumber(double); |
273 void pushString(const String&); | 273 void pushString(const String&); |
274 void pushValue(PassRefPtr<JSONValue>); | 274 void pushValue(PassRefPtr<JSONValue>); |
275 void pushObject(PassRefPtr<JSONObject>); | 275 void pushObject(PassRefPtr<JSONObject>); |
276 void pushArray(PassRefPtr<JSONArray>); | 276 void pushArray(PassRefPtr<JSONArray>); |
277 | 277 |
278 PassRefPtr<JSONValue> get(size_t index); | 278 PassRefPtr<JSONValue> get(size_t index); |
279 | 279 |
280 virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const
OVERRIDE; | 280 virtual void prettyWriteJSONInternal(StringBuilder* output, int depth) const
override; |
281 | 281 |
282 iterator begin() { return m_data.begin(); } | 282 iterator begin() { return m_data.begin(); } |
283 iterator end() { return m_data.end(); } | 283 iterator end() { return m_data.end(); } |
284 const_iterator begin() const { return m_data.begin(); } | 284 const_iterator begin() const { return m_data.begin(); } |
285 const_iterator end() const { return m_data.end(); } | 285 const_iterator end() const { return m_data.end(); } |
286 | 286 |
287 protected: | 287 protected: |
288 JSONArrayBase(); | 288 JSONArrayBase(); |
289 | 289 |
290 private: | 290 private: |
(...skipping 19 matching lines...) Expand all Loading... |
310 | 310 |
311 using JSONArrayBase::get; | 311 using JSONArrayBase::get; |
312 | 312 |
313 using JSONArrayBase::begin; | 313 using JSONArrayBase::begin; |
314 using JSONArrayBase::end; | 314 using JSONArrayBase::end; |
315 }; | 315 }; |
316 | 316 |
317 } // namespace blink | 317 } // namespace blink |
318 | 318 |
319 #endif // !defined(JSONValues_h) | 319 #endif // !defined(JSONValues_h) |
OLD | NEW |