本文整理汇总了C++中JSONValue::IsNull方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONValue::IsNull方法的具体用法?C++ JSONValue::IsNull怎么用?C++ JSONValue::IsNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONValue
的用法示例。
在下文中一共展示了JSONValue::IsNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadJSON
bool Animatable::LoadJSON(const JSONValue& source, bool setInstanceDefault)
{
if (!Serializable::LoadJSON(source, setInstanceDefault))
return false;
SetObjectAnimation(0);
attributeAnimationInfos_.Clear();
JSONValue value = source.Get("objectanimation");
if (!value.IsNull())
{
SharedPtr<ObjectAnimation> objectAnimation(new ObjectAnimation(context_));
if (!objectAnimation->LoadJSON(value))
return false;
SetObjectAnimation(objectAnimation);
}
JSONValue attributeAnimationValue = source.Get("attributeanimation");
if (attributeAnimationValue.IsNull())
return true;
if (!attributeAnimationValue.IsObject())
{
URHO3D_LOGWARNING("'attributeanimation' value is present in JSON data, but is not a JSON object; skipping it");
return true;
}
const JSONObject& attributeAnimationObject = attributeAnimationValue.GetObject();
for (JSONObject::ConstIterator it = attributeAnimationObject.Begin(); it != attributeAnimationObject.End(); it++)
{
String name = it->first_;
JSONValue value = it->second_;
SharedPtr<ValueAnimation> attributeAnimation(new ValueAnimation(context_));
if (!attributeAnimation->LoadJSON(it->second_))
return false;
String wrapModeString = source.Get("wrapmode").GetString();
WrapMode wrapMode = WM_LOOP;
for (int i = 0; i <= WM_CLAMP; ++i)
{
if (wrapModeString == wrapModeNames[i])
{
wrapMode = (WrapMode)i;
break;
}
}
float speed = value.Get("speed").GetFloat();
SetAttributeAnimation(name, attributeAnimation, wrapMode, speed);
it++;
}
return true;
}
示例2: GetVariant
Variant JSONValue::GetVariant(unsigned index) const
{
// Get child for variant
JSONValue child = GetChild(index, JSON_OBJECT);
if (child.IsNull())
return Variant::EMPTY;
// Get type
VariantType type = Variant::GetTypeFromName(child.GetString("type"));
// Get value
return child.GetVariantValue("value", type);
}
示例3: LoadJSON
bool ObjectAnimation::LoadJSON(const JSONValue& source)
{
attributeAnimationInfos_.Clear();
JSONValue attributeAnimationsValue = source.Get("attributeanimations");
if (attributeAnimationsValue.IsNull())
return true;
if (!attributeAnimationsValue.IsObject())
return true;
const JSONObject& attributeAnimationsObject = attributeAnimationsValue.GetObject();
for (JSONObject::ConstIterator it = attributeAnimationsObject.Begin(); it != attributeAnimationsObject.End(); it++)
{
String name = it->first_;
JSONValue value = it->second_;
SharedPtr<ValueAnimation> animation(new ValueAnimation(context_));
if (!animation->LoadJSON(value))
return false;
String wrapModeString = value.Get("wrapmode").GetString();
WrapMode wrapMode = WM_LOOP;
for (int i = 0; i <= WM_CLAMP; ++i)
{
if (wrapModeString == wrapModeNames[i])
{
wrapMode = (WrapMode)i;
break;
}
}
float speed = value.Get("speed").GetFloat();
AddAttributeAnimation(name, animation, wrapMode, speed);
}
return true;
}
示例4: BeginLoad
bool Animation::BeginLoad(Deserializer& source)
{
unsigned memoryUse = sizeof(Animation);
// Check ID
if (source.ReadFileID() != "UANI")
{
URHO3D_LOGERROR(source.GetName() + " is not a valid animation file");
return false;
}
// Read name and length
animationName_ = source.ReadString();
animationNameHash_ = animationName_;
length_ = source.ReadFloat();
tracks_.Clear();
unsigned tracks = source.ReadUInt();
memoryUse += tracks * sizeof(AnimationTrack);
// Read tracks
for (unsigned i = 0; i < tracks; ++i)
{
AnimationTrack* newTrack = CreateTrack(source.ReadString());
newTrack->channelMask_ = source.ReadUByte();
unsigned keyFrames = source.ReadUInt();
newTrack->keyFrames_.Resize(keyFrames);
memoryUse += keyFrames * sizeof(AnimationKeyFrame);
// Read keyframes of the track
for (unsigned j = 0; j < keyFrames; ++j)
{
AnimationKeyFrame& newKeyFrame = newTrack->keyFrames_[j];
newKeyFrame.time_ = source.ReadFloat();
if (newTrack->channelMask_ & CHANNEL_POSITION)
newKeyFrame.position_ = source.ReadVector3();
if (newTrack->channelMask_ & CHANNEL_ROTATION)
newKeyFrame.rotation_ = source.ReadQuaternion();
if (newTrack->channelMask_ & CHANNEL_SCALE)
newKeyFrame.scale_ = source.ReadVector3();
}
}
// Optionally read triggers from an XML file
ResourceCache* cache = GetSubsystem<ResourceCache>();
String xmlName = ReplaceExtension(GetName(), ".xml");
SharedPtr<XMLFile> file(cache->GetTempResource<XMLFile>(xmlName, false));
if (file)
{
XMLElement rootElem = file->GetRoot();
XMLElement triggerElem = rootElem.GetChild("trigger");
while (triggerElem)
{
if (triggerElem.HasAttribute("normalizedtime"))
AddTrigger(triggerElem.GetFloat("normalizedtime"), true, triggerElem.GetVariant());
else if (triggerElem.HasAttribute("time"))
AddTrigger(triggerElem.GetFloat("time"), false, triggerElem.GetVariant());
triggerElem = triggerElem.GetNext("trigger");
}
memoryUse += triggers_.Size() * sizeof(AnimationTriggerPoint);
SetMemoryUse(memoryUse);
return true;
}
// Optionally read triggers from a JSON file
String jsonName = ReplaceExtension(GetName(), ".json");
SharedPtr<JSONFile> jsonFile(cache->GetTempResource<JSONFile>(jsonName, false));
if (jsonFile)
{
const JSONValue& rootVal = jsonFile->GetRoot();
JSONArray triggerArray = rootVal.Get("triggers").GetArray();
for (unsigned i = 0; i < triggerArray.Size(); i++)
{
const JSONValue& triggerValue = triggerArray.At(i);
JSONValue normalizedTimeValue = triggerValue.Get("normalizedTime");
if (!normalizedTimeValue.IsNull())
AddTrigger(normalizedTimeValue.GetFloat(), true, triggerValue.GetVariant());
else
{
JSONValue timeVal = triggerValue.Get("time");
if (!timeVal.IsNull())
AddTrigger(timeVal.GetFloat(), false, triggerValue.GetVariant());
}
}
memoryUse += triggers_.Size() * sizeof(AnimationTriggerPoint);
SetMemoryUse(memoryUse);
return true;
}
SetMemoryUse(memoryUse);
return true;
}