2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebJsonJsonArray.h
20 * @brief This is the header file for the %JsonArray class.
22 * This header file contains the declarations of the %JsonArray class.
24 #ifndef _FWEB_JSON_JSON_ARRAY_H_
25 #define _FWEB_JSON_JSON_ARRAY_H_
27 #include <FBaseColArrayListT.h>
28 #include <FBaseColICollectionT.h>
29 #include <FWebJsonIJsonValue.h>
32 #pragma clang diagnostic push
33 #pragma clang diagnostic ignored "-Woverloaded-virtual"
36 namespace Tizen { namespace Web { namespace Json
39 }}} // Tizen::Web::Json
41 namespace Tizen { namespace Web { namespace Json
46 * @brief This class represents the JSON value of type array.
50 * @final This class is not intended for extension.
52 * The %JsonArray class represents the JSON value of type array.
54 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
56 * The following example demonstrates how to create and initialize a %JsonArray instance and how to use its methods.
59 * #include <FWebJson.h>
61 * using namespace Tizen::Base;
62 * using namespace Tizen::Base::Collection;
63 * using namespace Tizen::Web::Json;
66 * MyClass::JsonArraySample(void)
68 * // Creates an instance of JsonArray
69 * JsonArray *pJsonArray = new JsonArray();
71 * // Must call Construct() for JasonArray
72 * pJsonArray->Construct();
74 * // Creates value instances
75 * JsonString *pJsonstr = new JsonString(L"myname");
76 * JsonNumber *pJsonNum = new JsonNumber(99);
77 * JsonBool *pJsonBool = new JsonBool(true);
79 * // Adds the string to the JsonArray
80 * pJsonArray->Add(pJsonstr);
81 * // Adds the number to the JsonArray
82 * pJsonArray->Add(pJsonNum);
83 * // Adds the boolean to the JsonArray
84 * pJsonArray->Add(pJsonBool);
86 * // Gets the value at the given position(index) in the JsonArray
87 * IJsonValue* pValue = null;
88 * pJsonArray->GetAt(0, pValue);
90 * // Finds the index of the given value in the JsonArray
91 * JsonString *pJsonstrcheck = new JsonString(L"myname");
93 * pJsonArray->IndexOf(pJsonstrcheck, index);
95 * // Uses enumerator to access elements in the JsonArray
96 * IEnumeratorT<IJsonValue*>* pEnum = pJsonArray->GetEnumeratorN();
99 * while( pEnum->MoveNext() == E_SUCCESS )
101 * IJsonValue* pJsonValue = null;
103 * //Uses the pJsonValue
104 * pEnum->GetCurrent( pJsonValue );
109 * // Removes the value in the JsonArray
110 * pJsonArray->RemoveAt(index, true);
112 * // Removes all the remaining values
113 * pJsonArray->RemoveAll(true);
118 class _OSP_EXPORT_ JsonArray
120 , public Tizen::Base::Collection::ArrayListT<IJsonValue*>
124 * The object is not fully constructed after this constructor is called. @n
125 * For full construction, the Construct() method must be called right after calling this constructor.
132 * This destructor overrides Tizen::Base::Object::~Object().
136 virtual ~JsonArray(void);
139 * Initializes this instance of %JsonArray.
143 * @return An error code
144 * @exception E_SUCCESS The method is successful.
145 * @exception E_SYSTEM This exception exists only for historical reasons.
147 result Construct(void);
150 * Returns the type of this class. @n
151 * In this case, it is always @c JSON_ARRAY.
155 * @return The JSON type
157 JsonType GetType(void) const;
160 * Adds the specified element to end of the list.
164 * @return An error code
165 * @param[in] pJsonValue A pointer to JsonValue to add to the list
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_INVALID_ARG The specified input parameter is invalid.
170 virtual result Add(IJsonValue* const& pJsonValue);
173 * Searches for an element in this list. @n
174 * Gets the index of the element if it is found.
178 * @return An error code
179 * @param[in] pJsonValue A pointer to the JsonValue class to locate
180 * @param[out] index The index of the element
181 * @exception E_SUCCESS The method is successful.
182 * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
185 virtual result IndexOf(IJsonValue* const& pJsonValue, int& index) const;
188 * Searches for an element starting from the specified @c index. @n
189 * Gets the index of the element if it is found.
193 * @return An error code
194 * @param[in] pJsonValue A pointer to the JsonValue class to locate
195 * @param[in] startIndex The starting index for the search @n
196 * It must be less than the number of elements in the array.
197 * @param[out] index The index of the element
198 * @exception E_SUCCESS The method is successful.
199 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or the specified @c startIndex is either equal to or greater than the number of elements or less than @c 0.
200 * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
203 virtual result IndexOf(IJsonValue* const& pJsonValue, int startIndex, int& index) const;
206 * Searches for an element within the specified range. @n
207 * Gets the index of the element if it is found.
211 * @return An error code
212 * @param[in] pJsonValue A pointer to the JsonValue class to locate
213 * @param[in] startIndex The starting index of the range
214 * @param[in] count The number of elements to read
215 * @param[out] index The index of the element
216 * @exception E_SUCCESS The method is successful.
217 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
218 * - The specified @c index is outside the bounds of the data structure.
219 * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0.
220 * - The specified @c count is either greater than the number of elements starting from @c startIndex or less than @c 0.
221 * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
224 virtual result IndexOf(IJsonValue* const& pJsonValue, int startIndex, int count, int& index) const;
227 * Searches for the last occurrence of an element in this list. @n
228 * Gets the index of the element if it is found.
232 * @return An error code
233 * @param[in] pJsonValue A pointer to the JsonValue class to locate
234 * @param[out] index The index of the last occurrence of the specified element
235 * @exception E_SUCCESS The method is successful.
236 * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
239 virtual result LastIndexOf(IJsonValue* const& pJsonValue, int& index) const;
242 * Checks whether the list contains the specified @c pJsonValue.
246 * @return @c true if the specified @c pJsonValue is present in the list, @n
248 * @param[in] pJsonValue A pointer to the JsonValue class to locate
250 virtual bool Contains(IJsonValue* const& pJsonValue) const;
253 * Checks whether value of the specified instance equals to value of the current instance of %JsonArray.
257 * @return @c true if value of the current instance equals to value of the specified instance, @n
259 * @param[in] obj The element to compare with the current instance of %JsonArray @n
260 * If the specified element is not %JsonArray, this method returns @c false.
261 * @see Tizen::Base::Object::Equals()
263 virtual bool Equals(const Object& obj) const;
266 * Gets the hash value of the current instance.
270 * @return An integer value indicating the hash value of the current instance
271 * @remarks The two equal instances must return the same hash value. For better performance,
272 * the used hash function must generate a random distribution for all inputs.
273 * The default implementation of this method returns the address of the current instance.
275 virtual int GetHashCode(void) const;
278 * Removes the first occurrence of the specified element.
282 * @return An error code
283 * @param[in] pJsonValue A pointer to the JsonValue class to remove
284 * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
286 * @exception E_SUCCESS The method is successful.
287 * @exception E_OBJ_NOT_FOUND The specified @c pJsonValue is not found.
292 virtual result Remove(IJsonValue* const& pJsonValue, bool deallocate = false);
295 * Removes all the elements of the specified @c collection from the list.
299 * @return An error code
300 * @param[in] collection The collection to remove from this list
301 * @param[in] deallocate Set to @c true to deallocate the JsonValues, @n
303 * @exception E_SUCCESS The method is successful.
304 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation. @n
305 * The @c collection is modified during the operation of this method.
307 virtual result RemoveItems(const Tizen::Base::Collection::ICollectionT<IJsonValue*>& collection, bool deallocate = false);
310 * Removes an element from a specified location. @n
311 * The elements that follow the deleted element move up the list to occupy the empty location.
315 * @return An error code
316 * @param[in] index The index of the element to remove
317 * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
319 * @exception E_SUCCESS The method is successful.
320 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or the specified @c index is greater than or equal to the number of elements or less than @c 0.
322 virtual result RemoveAt(int index, bool deallocate = false);
325 * Removes all the elements within a specified range. @n
326 * The elements that follow the deleted elements move up the list to occupy the empty locations.
330 * @return An error code
331 * @param[in] startIndex The starting index of the range
332 * @param[in] count The number of elements to remove
333 * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
335 * @exception E_SUCCESS The method is successful.
336 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
337 * - The specified @c startIndex is outside the bounds of the list.
338 * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0.
339 * - The specified @c count is either greater than the number of elements starting from @c startIndex or less than @c 0.
341 virtual result RemoveItems(int startIndex, int count, bool deallocate = false);
344 * Removes all the elements in the %JsonArray class.
348 * @param[in] deallocate Set to @c true to deallocate all the elements, @n
351 virtual void RemoveAll(bool deallocate = false);
354 * Replaces the element at the specified @c index with the specified element.
358 * @return An error code
359 * @param[in] pJsonValue A pointer to the JsonValue class to set
360 * @param[in] index The index at which the element must be set
361 * @exception E_SUCCESS The method is successful.
362 * @exception E_INVALID_ARG A specified input parameter is invalid.
363 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or the specified @c index is either equal to or greater than the number of elements or less than @c 0.
366 virtual result SetAt(IJsonValue* const& pJsonValue, int index);
369 * Replaces the element at the specified @c index with the specified element.
373 * @return An error code
374 * @param[in] pJsonValue A pointer to the JsonValue class to set
375 * @param[in] index The index at which the element must be set
376 * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
378 * @exception E_SUCCESS The method is successful.
379 * @exception E_INVALID_ARG A specified input parameter is invalid.
380 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or the specified @c index is either equal to or greater than the number of elements or less than @c 0.
383 virtual result SetAt(IJsonValue* const& pJsonValue, int index, bool deallocate);
386 * Returns a new cloned %JsonArray instance.
390 * @return A new cloned %JsonArray or @c null if it fails to allocate the instance
391 * @exception E_SUCCESS The method is successful.
392 * @exception E_OUT_OF_MEMORY The memory is insufficient.
393 * @remarks The specific error code can be accessed using the GetLastResult() method.
395 JsonArray* CloneN(void) const;
399 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
401 // @param[in] item The instance of the %JsonArray class to copy from
402 // @remarks This constructor is hidden.
404 JsonArray(const JsonArray& item);
407 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
409 // @param[in] item The instance of the %JsonArray class to assign from
410 // @remarks This operator is hidden.
412 JsonArray& operator =(const JsonArray& item);
415 _JsonArrayImpl* __pJsonArrayImpl;
417 friend class _JsonArrayImpl;
420 }}} // Tizen::Web::Json
421 #endif // _FWEB_JSON_JSON_ARRAY_H_
424 #pragma clang diagnostic pop