Variant XMLElement::GetVariantValue(VariantType type) const { Variant ret; if (type == VAR_RESOURCEREF) ret = GetResourceRef(); else if (type == VAR_RESOURCEREFLIST) ret = GetResourceRefList(); else if (type == VAR_VARIANTVECTOR) ret = GetVariantVector(); else if (type == VAR_VARIANTMAP) ret = GetVariantMap(); else ret.FromString(type, GetAttributeCString("value")); return ret; }
template <> VariantVector Variant::Get<VariantVector>() const { return GetVariantVector(); }
void JSONValue::GetVariantValue(Variant& variant, VariantType type) const { switch (type) { case VAR_BOOL: variant = GetBool(); return; case VAR_INT: variant = GetInt(); return; case VAR_FLOAT: variant = GetFloat(); return; case VAR_DOUBLE: variant = GetDouble(); return; case VAR_STRING: variant = GetString(); return; case VAR_VARIANTVECTOR: { VariantVector vector; GetVariantVector(vector); variant = vector; } return; case VAR_VARIANTMAP: { VariantMap map; GetVariantMap(map); variant = map; } return; case VAR_RESOURCEREF: { ResourceRef ref; Vector<String> values = GetString().Split(';'); if (values.Size() == 2) { ref.type_ = values[0]; ref.name_ = values[1]; } variant = ref; } return; case VAR_RESOURCEREFLIST: { ResourceRefList refList; Vector<String> values = GetString().Split(';'); if (values.Size() >= 1) { refList.type_ = values[0]; refList.names_.Resize(values.Size() - 1); for (unsigned i = 1; i < values.Size(); ++i) refList.names_[i - 1] = values[i]; } variant = refList; } return; case VAR_STRINGVECTOR: { StringVector vector; for (unsigned i = 0; i < Size(); ++i) vector.Push((*this)[i].GetString()); variant = vector; } return; default: variant.FromString(type, GetString()); return; } }