Пример #1
0
VError VJSONCloner::CloneObject( const VJSONObject *inObject, VJSONValue& outValue)
{
    VError err = VE_OK;

    if (inObject == NULL)
    {
        outValue.SetUndefined();
    }
    else
    {
        try
        {
            VJSONValue value;
            std::pair<MapOfValueByObject::iterator,bool> i = fClonedObjects.insert( MapOfValueByObject::value_type( inObject, value));
            if (i.second)
            {
                // not already cloned
                err = inObject->Clone( i.first->second, *this);
            }
            outValue = i.first->second;
        }
        catch(...)
        {
            outValue.SetUndefined();
            err = vThrowError( VE_MEMORY_FULL);
        }
    }
    return err;
}
Пример #2
0
bool VJSFunction::GetResultAsJSONValue( VJSONValue& outResult) const
{
	if (fException != NULL)
	{
		outResult.SetUndefined();
		return false;
	}
	return fResult.GetJSONValue( outResult, &fException);
}
Пример #3
0
VJSONValue VJSONObject::GetProperty( const VString& inName) const
{
	VJSONValue value;
	EJSONStatus status = EJSON_unhandled;

	if (fImpl != NULL)
	{
		status = fImpl->IJSON_GetProperty( this, inName, value);
		if (status == EJSON_error)
			value.SetUndefined();
	}

	if (status == EJSON_unhandled)
	{
		MapType::const_iterator i = fMap.find( inName);
		if (i != fMap.end())
			value = i->second.first;
	}
	
	return value;
}
Пример #4
0
VError VJSONBinaryImporter::GetValue(VJSONValue& outVal)
{
	VError err = VE_OK;
	sBYTE btype = *((uBYTE*)fCurPtr);
	++fCurPtr;
	switch (btype)
	{
		case JSON_null:
			outVal.SetNull();
			break;

		case JSON_undefined:
			outVal.SetUndefined();
			break;

		case JSON_true:
			outVal.SetBool(true);
			break;

		case JSON_false:
			outVal.SetBool(false);
			break;

		case JSON_string:
			{
				VString s;
				sLONG len = *((sLONG*)fCurPtr);
				fCurPtr += 4;
				s.FromBlock(fCurPtr, len * 2, VTC_UTF_16);
				fCurPtr += (len * 2);
				outVal.SetString(s);
			}
			break;

		case JSON_date:
			{
				VTime dd;
				sLONG8 ll = *((sLONG8*)fCurPtr);
				fCurPtr += 8;
				dd.FromMilliseconds(ll);
				outVal.SetTime(dd);
			}
			break;

		case JSON_number:
			{
				Real rr = *((Real*)fCurPtr);
				fCurPtr += sizeof(Real);
				outVal.SetNumber(rr);
			}
			break;

		case JSON_object:
			{
				if (*((sWORD*)fCurPtr) == -2)
				{
					outVal.SetUndefined();
				}
				else
				{
					VJSONObject* obj = new VJSONObject();
					sWORD len;
					do
					{
						len = *((sWORD*)fCurPtr);
						fCurPtr += 2;
						if (len >= 0)
						{
							VString name;
							name.FromBlock(fCurPtr, (sLONG)len * 2, VTC_UTF_16);
							fCurPtr += ((sLONG)len * 2);
							VJSONValue val;
							err = GetValue(val);
							obj->SetProperty(name, val);
						}
					} while (err == VE_OK && len != -1);
					outVal.SetObject(obj);
					QuickReleaseRefCountable(obj);
				}
			}
			break;

		case JSON_array:
			{
				sLONG count = *((sLONG*)fCurPtr);
				fCurPtr += 4;
				if (count == -2)
				{
					outVal.SetUndefined();
				}
				else
				{
					VJSONArray* arr = new VJSONArray();
					for (sLONG i = 0; i < count && err == VE_OK; ++i)
					{
						VJSONValue val;
						err = GetValue(val);
						arr->Push(val);
					}
					outVal.SetArray(arr);
					QuickReleaseRefCountable(arr);
				}
			}
			break;

		default:
			xbox_assert(false);
			break;
	}
	return err;
}
Пример #5
0
VError VValue::GetJSONValue(VJSONValue& outJSONValue, bool /*allowDates*/) const
{
	outJSONValue.SetUndefined();
	return vThrowError( VE_UNIMPLEMENTED);
}