*
* @since 2.0
*
- * The %IJsonValue interface abstracts a Json value class of a Json value type (string, bool, number, array, object, and null type).
+ * The %IJsonValue interface abstracts a Json value class of a %Json value type (string, bool, number, array, object, and null type).
* @n
* For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/web/json_namespace.htm">JSON Guide</a>.
*/
* @since 2.0
*
* @return An error code
- * @exception E_SUCCESS The method is successful.
- * @exception E_SYSTEM A system error has occurred.
- * @exception E_INVALID_OPERATION This instance has already been constructed.
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM This exception exists only for historical reason.
*/
result Construct(void);
* @since 2.0
*
* @return The JSON type
- * @see JsonType
*/
JsonType GetType(void) const;
* @param[in] count The number of elements to be read
* @param[out] index The index of the element
* @exception E_SUCCESS The method is successful.
- * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
- * - The specified index is outside the bounds of the data structure. @n
- * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0. @n
+ * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
+ * - The specified index is outside the bounds of the data structure.
+ * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0.
* - The specified @c count is either greater than the number of elements starting from @c startIndex or less than @c 0.
- * @exception E_OBJ_NOT_FOUND The @c pJsonValue is not found.
+ * @exception E_OBJ_NOT_FOUND The @c pJsonValue is not found.
* @see LastIndexOf()
*/
virtual result IndexOf(IJsonValue* const& pJsonValue, int startIndex, int count, int& index) const;
virtual result LastIndexOf(IJsonValue* const& pJsonValue, int& index) const;
/**
- * Checks whether the list contains the specified @c JsonValue.
+ * Checks whether the list contains the specified @c pJsonValue.
*
* @since 2.0
*
- * @return @c true if the specified @c JsonValue is present in the list, @n
+ * @return @c true if the specified @c pJsonValue is present in the list, @n
* else @c false
* @param[in] pJsonValue A pointer to the JsonValue class to be located
*/
virtual bool Contains(IJsonValue* const& pJsonValue) const;
/**
- * Checks whether value of the specified instance equals to value of the current instance of @c %JsonArray.
+ * Checks whether value of the specified instance equals to value of the current instance of %JsonArray.
*
* @since 2.0
*
* @return @c true if value of the current instance equals to value of the specified instance, @n
- * else @c false
- * @param[in] obj The element to be compared with the current instance of @c %JsonArray
- * @remarks The method returns @c false if the specified element is not @c %JsonArray.
- * @see Object::Equals()
+ * else @c false @n
+ * @param[in] obj The element to be compared with the current instance of %JsonArray @n
+ * If the specified @c obj is not %JsonArray, this method returns @c false.
+ * @see Tizen::Base::Object::Equals()
*/
virtual bool Equals(const Object& obj) const;
* @since 2.0
*
* @return An error code
- * @param[in] pJsonValue A pointer to the %JsonValue class to be removed
- * @param[in] deallocate Set to @c true to deallocate the @c JsonValue, @n
+ * @param[in] pJsonValue A pointer to the JsonValue class to be removed
+ * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
* else @c false
* @exception E_SUCCESS The method is successful.
* @exception E_OBJ_NOT_FOUND The @c pJsonValue is not found.
*
* @return An error code
* @param[in] collection The collection to be removed from this list
- * @param[in] deallocate Set to @c true to deallocate the @c JsonValues, @n
+ * @param[in] deallocate Set to @c true to deallocate the JsonValues, @n
* else @c false
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation. @n
virtual result RemoveItems(const Tizen::Base::Collection::ICollectionT<IJsonValue*>& collection, bool deallocate = false);
/**
- * Removes an element from the specified location.
+ * Removes an element from the specified location. @n
+ * The elements that follow the deleted element move up the list to occupy the empty location.
*
* @since 2.0
*
* @return An error code
* @param[in] index The index of the element to be removed
- * @param[in] deallocate Set to @c true to deallocate the @c JsonValue, @n
+ * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
* else @c false
* @exception E_SUCCESS The method is successful.
* @exception E_OUT_OF_RANGE The specified 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.
- * @remarks The elements that follow the deleted element move up the list to occupy the empty location.
*/
virtual result RemoveAt(int index, bool deallocate = false);
/**
- * Removes all the elements within a specified range.
+ * Removes all the elements within a specified range. @n
+ * The elements that follow the deleted elements move up the list to occupy the empty locations.
*
* @since 2.0
*
* @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
* else @c false
* @exception E_SUCCESS The method is successful.
- * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
- * - The specified index is outside the bounds. @n
- * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0. @n
+ * @exception E_OUT_OF_RANGE Either of the following conditions has occurred:
+ * - The specified index is outside the bounds of the list.
+ * - The specified @c startIndex is either greater than or equal to the number of elements or less than @c 0.
* - The specified @c count is either greater than the number of elements starting from @c startIndex or less than @c 0.
- * @remarks The elements that follow the deleted elements move up the list to occupy the empty locations.
*/
virtual result RemoveItems(int startIndex, int count, bool deallocate = false);
* @param[in] index The index at which the element must be set
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG A specified input parameter is invalid.
- * @exception E_OUT_OF_RANGE The specified 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.
+ * @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.
* @see GetAt()
*/
virtual result SetAt(IJsonValue* const& pJsonValue, int index);
* @return An error code
* @param[in] pJsonValue A pointer to the JsonValue class to be set
* @param[in] index The index at which the element must be set
- * @param[in] deallocate Set to @c true to deallocate the @c JsonValue, @n
+ * @param[in] deallocate Set to @c true to deallocate the JsonValue, @n
* else @c false
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG A specified input parameter is invalid.
- * @exception E_OUT_OF_RANGE The specified 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.
+ * @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.
* @see GetAt()
*/
virtual result SetAt(IJsonValue* const& pJsonValue, int index, bool deallocate);
*
* @since 2.0
*
- * @return A new cloned %JsonArray
- * @exception E_SUCCESS The memory is successful.
- * @exception E_SYSTEM A system error has occurred.
+ * @return A new cloned %JsonArray or null if it fails to allocate the instance
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OUT_OF_MEMORY The memory is insufficient.
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
*/
JsonArray* CloneN(void) const;
virtual ~JsonBool(void);
/**
- * Gets the type of this class (always JSON_BOOL).
+ * Gets the type of this class (always @c JSON_BOOL).
*
* @since 2.0
*
* @since 2.0
*
* @return @c true if the value of the current instance equals the value of the specified instance, @n
- else @c false
- * @param[in] obj The object to compare with the current instance of %JsonNull
- * @remarks The method returns @c false if the specified object is not %JsonNull.
- * @see Object::Equals()
+ * else @c false
+ * @param[in] obj The object to compare with the current instance of %JsonNull @n
+ * The method returns @c false if the specified @c obj is not %JsonNull.
+ * @see Tizen::Base::Object::Equals()
*/
virtual bool Equals(const Object& obj) const;
virtual int GetHashCode(void) const;
/**
- * Gets the type of the object (Always JSON_NULL)
+ * Gets the type of the object (Always @c JSON_NULL)
*
* @since 2.0
*
* @since 2.0
*
* @return The type of JSON number
- * @see JsonType
*/
JsonType GetType(void) const;
*
* @return An error code
* @exception E_SUCCESS The method is successful.
- * @exception E_SYSTEM A system error has occurred.
- * @exception E_INVALID_OPERATION The Construct() method cannot be called twice.
+ * @exception E_SYSTEM This exception exists only for historical reason.
*/
result Construct(void);
* @since 2.0
*
* @return The type of the JSON object
- * @see JsonType
*/
JsonType GetType(void) const;
* @return @c true if the value of the current instance equals the value of the specified instance, @n
else @c false
* @param[in] obj The object to compare @n
- * This object is compared with the current instance of %JsonObject.
- * @remarks This method returns @c false if the specified object is not of type JSON object.
- * @see Object::Equals()
+ * This object is compared with the current instance of %JsonObject. @n
+ * This method returns @c false if the specified @c obj is not of type JSON object.
+ * @see Tizen::Base::Object::Equals()
*/
- virtual bool Equals(const Object& obj) const;
+ virtual bool Equals(const Object& obj) const;
/**
* Gets the hash value of the current instance.
*
* @since 2.0
*
- * @return a new cloned %JsonObject
- * @exception E_SUCCESS The memory is successful.
- * @exception E_SYSTEM A system error has occurred.
+ * @return A new cloned %JsonArray or null if it fails to allocate the instance
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_OUT_OF_MEMORY The memory is insufficient.
+ * @remarks The specific error code can be accessed using the GetLastResult() method.
*/
JsonObject* CloneN(void) const;
* @param[in] filePath The path of the JSON-encoded file
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The specified file path is incorrect, or the file is not found.
- * @exception E_INVALID_DATA The input JSON data is invalid.
+ * @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty
* @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
- * @exception E_UNKNOWN An unknown error has occurred.
- *
+ * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
+ * @exception E_FILE_NOT_FOUND The specified filePath cannot be found.
+ * @exception E_SYSTEM The method cannot proceed due to a severe system error.
* @remarks The specific error code can be accessed using the GetLastResult() method.
*/
static IJsonValue* ParseN(const Tizen::Base::String& filePath);
* @param[in] pBuffer A JSON-encoded buffer
* @param[in] bufferLength A JSON-encoded buffer length
* @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
+ * - The specified @c pBuffer is @c null. @n
+ * - The specified bufferLength is zero or negative.
* @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
* @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
- * @exception E_UNKNOWN An unknown error has occurred.
*
* @remarks The specific error code can be accessed using the GetLastResult() method.
*/
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_DATA The input JSON data is invalid, or the buffer is empty.
* @exception E_MAX_EXCEEDED The input JSON data exceeds the maximum length.
- * @exception E_UNKNOWN An unknown error has occurred.
*
* @remarks The specific error code can be accessed using the GetLastResult() method.
*/
* @since 2.0
*
* @return The type of the JSON string
- * @see JsonType
*/
JsonType GetType(void) const;
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_DATA The specified @c pValue is @c null.
* @exception E_INVALID_ARG The specified @c filePath is incorrect.
- * @exception E_FAILURE The method has failed.
+ * @exception E_ILLEGAL_ACCESS Access is denied due to insufficient permission.
+ * @exception E_STORAGE_FULL The disk space is full.
+ * @exception E_SYSTEM The method cannot proceed due to a severe system error.
*/
static result Compose(const IJsonValue* pValue, Tizen::Base::String& filePath);
* @since 2.0
*
* @param[in] pValue JSON value to be encoded.
- * @param[in] bufferLength Json encoded data buffer length.
- * @param[out] pBuffer The buffer with Json encoded data.
+ * @param[in] bufferLength JSON encoded data buffer length.
+ * @param[out] pBuffer The buffer with JSON encoded data.
* @return An error code
* @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG Either of the following conditions has occurred: @n
+ * - The specified @c pBuffer is @c null. @n
+ * - The specified bufferLength is negative.
* @exception E_INVALID_DATA The specified @c pValue is @c null.
- * @exception E_FAILURE The method has failed.
*/
static result Compose(const IJsonValue* pValue, void* pBuffer, int bufferLength);
* @since 2.0
*
* @param[in] pValue JSON value to be encoded.
- * @param[out] buffer The buffer with JSON-encoded data
+ * @param[out] buffer The buffer with JSON-encoded data @n
+ * The specified @c buffer has to be constructed with a non-zero capacity before calling this method.
* @return An error code
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_DATA The specified @c pValue is @c null.
- * @exception E_FAILURE The method has failed.
- * @remarks ByteBuffer parameter has to be constructed with a non zero capacity before calling this method.
*/
static result Compose(const IJsonValue* pValue, Tizen::Base::ByteBuffer& buffer);
return true;
}
- //if number of key value pairs are same, we can compare element by element else they are not equal
int count = GetCount();
- SysTryReturn(NID_WEB_JSON, count == pOther->GetCount(), false, E_SUCCESS, "[%s] count is not same in JsonArrays", GetErrorMessage(E_SUCCESS));
+ if (count != pOther->GetCount())
+ {
+ SysLog(NID_WEB_JSON, "count mismatch, [%d] and [%d]", count, pOther->GetCount());
+ return false;
+ }
for (int i = 0; i < count; i++)
{
{
ClearLastResult();
- unique_ptr<JsonArray, AllElementsDeleter> pJsonArray(new (std::nothrow) JsonArray());
- SysTryReturn(NID_WEB_JSON, pJsonArray.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
- result r = pJsonArray->Construct();
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ JsonArray* pJsonArray = new (std::nothrow) JsonArray();
+ SysTryReturn(NID_WEB_JSON, pJsonArray, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
IJsonValue* pValue = null;
IJsonValue* pNewValue = null;
+ result r = pJsonArray->Construct();
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
for (int i = 0; i < GetCount(); i++)
{
r = GetAt(i, pValue);
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
switch (pValue->GetType())
{
case JSON_TYPE_STRING:
pNewValue = new (std::nothrow) JsonString(static_cast<JsonString*>(pValue)->GetPointer());
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_NUMBER:
pNewValue = new (std::nothrow) JsonNumber(static_cast<JsonNumber*>(pValue)->ToDouble());
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_OBJECT:
pNewValue = static_cast<JsonObject*>(pValue)->CloneN();
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_ARRAY:
pNewValue = static_cast<JsonArray*>(pValue)->CloneN();
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_BOOL:
pNewValue = new (std::nothrow) JsonBool(static_cast<JsonBool*>(pValue)->ToBool());
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_NULL:
pNewValue = new (std::nothrow) JsonNull();
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
default:
SysAssertf(false, "unknown Json type.");
break;
}
+ SysTryCatch(NID_WEB_JSON, pNewValue, r = E_OUT_OF_MEMORY, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
r = pJsonArray->Add(pNewValue);
- if (IsFailed(r))
- {
- _JsonUtils::DeallocateItem(pNewValue);
- SysLogException(NID_WEB_JSON, r, "[%s] Propagated.", GetErrorMessage(r));
- return null;
- }
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
}
- return pJsonArray.release();
+ return pJsonArray;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pNewValue);
+ _JsonUtils::DeallocateItem(pJsonArray);
+
+ SetLastResult(r);
+
+ return null;
}
result
Compare(const StringKey& obj1, const StringKey& obj2, int& cmp) const
{
- SysTryReturnResult(NID_WEB_JSON, obj1 && obj2, E_INVALID_ARG, "Input parameters are null");
+ SysTryReturnResult(NID_WEB_JSON, obj1 && obj2, E_INVALID_ARG, "Invalid argument(s) used. (null)");
if (*obj1 == *obj2)
{
//Create comparer and provider to be given to HashMap
unique_ptr<_JsonObjectComparer> pJsonObjectComparer(new (std::nothrow) _JsonObjectComparer());
- SysTryReturnResult(NID_WEB_JSON, pJsonObjectComparer.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturnResult(NID_WEB_JSON, pJsonObjectComparer.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
unique_ptr<_JsonObjectHashCodeProvider> pJsonObjectHashCodeProvider(new (std::nothrow) _JsonObjectHashCodeProvider());
- SysTryReturnResult(NID_WEB_JSON, pJsonObjectHashCodeProvider.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryReturnResult(NID_WEB_JSON, pJsonObjectHashCodeProvider.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
//base class construct called to make hashmap ready
result r = HashMapT<const String*, IJsonValue*>::Construct(0, 0.0, *pJsonObjectHashCodeProvider, *pJsonObjectComparer);
}
int count = GetCount();
- //if number of key value pairs are same, we can compare element by element else they are not equal
- SysTryReturn(NID_WEB_JSON, count == pOther->GetCount(), false, E_SUCCESS, "[%s] pair count is not same in jsonobjects", GetErrorMessage(E_SUCCESS));
+ if (count != pOther->GetCount())
+ {
+ SysLog(NID_WEB_JSON, "count mismatch, [%d] and [%d]", count, pOther->GetCount());
+ return false;
+ }
if (count == 0)
{
SysTryReturn(NID_WEB_JSON, r == E_SUCCESS && pValue, r, r, "[%s] Propagating.", GetErrorMessage(r));
unique_ptr<JsonKeyList> pKeyList(GetKeysN());
- SysTryReturnResult(NID_WEB_JSON, pKeyList.get(), E_OBJ_NOT_FOUND, "[%s] Propagating.", GetErrorMessage(E_OBJ_NOT_FOUND));
+ SysTryReturn(NID_WEB_JSON, pKeyList.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
//Remove from Base class
r = HashMapT<const String*, IJsonValue*>::Remove(pKey);
SysTryReturnResult(NID_WEB_JSON, pKey && pJsonValue, E_INVALID_ARG, "Input Argument is null");
int count = GetCount();
- SysTryReturnResult(NID_WEB_JSON, count > 0, E_OBJ_NOT_FOUND, "number of elements are zero");
+ SysTryReturnResult(NID_WEB_JSON, count > 0, E_OBJ_NOT_FOUND, "Count is zero");
result r = E_OBJ_NOT_FOUND;
IJsonValue* pValue = null;
{
ClearLastResult();
- result r = E_SUCCESS;
-
- unique_ptr<JsonObject, AllElementsDeleter> pJsonObject(new (std::nothrow) JsonObject());
+ JsonObject* pJsonObject = new (std::nothrow) JsonObject();
SysTryReturn(NID_WEB_JSON, pJsonObject, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
- r = pJsonObject->Construct();
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
const String* pKey = null;
IJsonValue* pValue = null;
unique_ptr<String> pNewKey;
IJsonValue* pNewValue = null;
unique_ptr<JsonMapEnumerator> pMapEnum(GetMapEnumeratorN());
+ result r = pJsonObject->Construct();
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
if (pMapEnum.get())
{
while (pMapEnum->MoveNext() == E_SUCCESS)
{
r = pMapEnum->GetKey(pKey);
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
r = pMapEnum->GetValue(pValue);
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
pNewKey = unique_ptr<String>(new (std::nothrow) String(*pKey));
- SysTryReturn(NID_WEB_JSON, pNewKey.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ SysTryCatch(NID_WEB_JSON, pNewKey.get(), r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed.");
switch (pValue->GetType())
{
case JSON_TYPE_STRING:
pNewValue = new (std::nothrow) JsonString(static_cast<JsonString*>(pValue)->String::GetPointer());
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_NUMBER:
pNewValue = new (std::nothrow) JsonNumber(static_cast<JsonNumber*>(pValue)->ToDouble());
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_OBJECT:
pNewValue = static_cast<JsonObject*>(pValue)->CloneN();
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_ARRAY:
pNewValue = static_cast<JsonArray*>(pValue)->CloneN();
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_BOOL:
pNewValue = new (std::nothrow) JsonBool(static_cast<JsonBool*>(pValue)->ToBool());
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
case JSON_TYPE_NULL:
pNewValue = new (std::nothrow) JsonNull();
- SysTryReturn(NID_WEB_JSON, pNewValue, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
break;
default:
SysAssertf(false, "unknown Json type.");
break;
}
+ SysTryCatch(NID_WEB_JSON, pNewValue, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
r = pJsonObject->Add(pNewKey.get(), pNewValue);
- if (IsFailed(r))
- {
- _JsonUtils::DeallocateItem(pNewValue);
- SysLogException(NID_WEB_JSON, r, "[%s] Propagated.", GetErrorMessage(r));
- return null;
- }
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
pNewKey.release();
}
}
+ return pJsonObject;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pNewValue);
+ _JsonUtils::DeallocateItem(pJsonObject);
+
+ SetLastResult(r);
- return pJsonObject.release();
+ return null;
}
file.Seek(FILESEEKPOSITION_BEGIN, 0);
size = file.Read(pBuffer.get(), size);
- r = GetLastResult();
- SysTryReturn(NID_WEB_JSON, size > 0, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturn(NID_WEB_JSON, size > 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
unique_ptr<_JsonParserImpl> pParserImpl(_JsonParserImpl::CreateInstanceN());
SysTryReturn(NID_WEB_JSON, pParserImpl.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
switch (__pJsonData[__parserPosition])
{
case '{':
- pRoot = ParseObjectN();
SysLog(NID_WEB_JSON, "root is object");
+ pRoot = ParseObjectN();
break;
case '[':
+ SysLog(NID_WEB_JSON, "root is Array");
pRoot = ParseArrayN();
- SysLog(NID_WEB_JSON, "root is array");
break;
default:
SysLogException(NID_WEB_JSON, E_INVALID_DATA, "[E_INVALID_DATA] root is malformed [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
SysTryCatch(NID_WEB_JSON, __pJsonData[__parserPosition] == '\0', , E_INVALID_DATA,
"[E_INVALID_DATA] Expected EOF, Invalid character [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
}
+
return pRoot;
CATCH:
_JsonUtils::DeallocateItem(pRoot);
+
SetLastResult(E_INVALID_DATA);
+
return null;
}
{
SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
- unique_ptr<JsonObject, AllElementsDeleter> pJsonObject(new (std::nothrow) JsonObject());
- SysTryReturn(NID_WEB_JSON, pJsonObject.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ JsonObject* pJsonObject = new (std::nothrow) JsonObject();
+ SysTryReturn(NID_WEB_JSON, pJsonObject, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
result r = pJsonObject->Construct();
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
if (__pJsonData[__parserPosition] == '}')
{
GoToNextTokenPosition(true);
- return pJsonObject.release();
+ return pJsonObject;
}
while (true)
{
//add key value pair
r = AddPairToObject(*pJsonObject);
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
if (__pJsonData[__parserPosition] != ',')
{
break;
}
- SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
+ SysTryCatch(NID_WEB_JSON, GoToNextTokenPosition(true), r = E_INVALID_DATA, r, "[E_INVALID_DATA] object incomplete at [%d]", __parserPosition);
}
- SysTryReturn(NID_WEB_JSON, __pJsonData[__parserPosition] == '}', null, E_INVALID_DATA, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ SysTryCatch(NID_WEB_JSON, __pJsonData[__parserPosition] == '}', r = E_INVALID_DATA, r, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
GoToNextTokenPosition(true);
- return pJsonObject.release();
+
+ return pJsonObject;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pJsonObject);
+
+ SetLastResult(r);
+
+ return null;
}
{
SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] array incomplete at [%d]", __parserPosition);
- unique_ptr<JsonArray, AllElementsDeleter> pJsonArray(new (std::nothrow) JsonArray());
- SysTryReturn(NID_WEB_JSON, pJsonArray.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+ JsonArray* pJsonArray = new (std::nothrow) JsonArray();
+ SysTryReturn(NID_WEB_JSON, pJsonArray, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
result r = pJsonArray->Construct();
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
if (__pJsonData[__parserPosition] == ']')
{
GoToNextTokenPosition(true);
- return pJsonArray.release();
+ return pJsonArray;
}
while (true)
{
//add value to array
r = AddValueToArray(*pJsonArray);
- SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryCatch(NID_WEB_JSON, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
if (__pJsonData[__parserPosition] != ',')
{
break;
}
- SysTryReturn(NID_WEB_JSON, GoToNextTokenPosition(true), null, E_INVALID_DATA, "[E_INVALID_DATA] array incomplete at [%d]", __parserPosition);
+ SysTryCatch(NID_WEB_JSON, GoToNextTokenPosition(true), r = E_INVALID_DATA, r, "[E_INVALID_DATA] array incomplete at [%d]", __parserPosition);
}
- SysTryReturn(NID_WEB_JSON, __pJsonData[__parserPosition] == ']', null, E_INVALID_DATA, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
+ SysTryCatch(NID_WEB_JSON, __pJsonData[__parserPosition] == ']', r = E_INVALID_DATA, r, "[E_INVALID_DATA] data malfored [%c] at [%d]", __pJsonData[__parserPosition], __parserPosition);
GoToNextTokenPosition(true);
- return pJsonArray.release();
+
+ return pJsonArray;
+
+CATCH:
+ _JsonUtils::DeallocateItem(pJsonArray);
+
+ SetLastResult(r);
+
+ return null;
}
SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(output));
- r = GetLastResult();
- SysTryReturn(NID_WEB_JSON, pText.get(), r, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturn(NID_WEB_JSON, pText.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
int charCount = strlen(pText.get());
charCount = (charCount <= bufferLength) ? charCount : bufferLength;
SysTryReturn(NID_WEB_JSON, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(output));
- r = GetLastResult();
- SysTryReturn(NID_WEB_JSON, pByteBuf.get(), r, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturn(NID_WEB_JSON, pByteBuf.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
if (buffer.GetPointer())
{
JsonObject* pObject = static_cast<JsonObject*>(pValue);
unique_ptr<JsonMapEnumerator> pMapEnum(pObject->GetMapEnumeratorN());
- r = GetLastResult();
- SysTryReturn(NID_WEB_JSON, pMapEnum.get(), r, r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturn(NID_WEB_JSON, pMapEnum.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
int itemCount = pObject->GetCount();