| 305 | } |
| 306 | |
| 307 | Variant MUtils::UnboxVariant(MObject* value) |
| 308 | { |
| 309 | if (value == nullptr) |
| 310 | return Variant::Null; |
| 311 | const auto& stdTypes = *StdTypesContainer::Instance(); |
| 312 | MClass* klass = MCore::Object::GetClass(value); |
| 313 | |
| 314 | MType* mType = klass->GetType(); |
| 315 | const MTypes mTypes = MCore::Type::GetType(mType); |
| 316 | void* unboxed = MCore::Object::Unbox(value); |
| 317 | |
| 318 | // Fast type detection for in-built types |
| 319 | switch (mTypes) |
| 320 | { |
| 321 | case MTypes::Void: |
| 322 | return Variant(VariantType(VariantType::Void)); |
| 323 | case MTypes::Boolean: |
| 324 | return *static_cast<bool*>(unboxed); |
| 325 | case MTypes::I1: |
| 326 | return *static_cast<int8*>(unboxed); |
| 327 | case MTypes::U1: |
| 328 | return *static_cast<uint8*>(unboxed); |
| 329 | case MTypes::I2: |
| 330 | return *static_cast<int16*>(unboxed); |
| 331 | case MTypes::U2: |
| 332 | return *static_cast<uint16*>(unboxed); |
| 333 | case MTypes::Char: |
| 334 | return *static_cast<Char*>(unboxed); |
| 335 | case MTypes::I4: |
| 336 | return *static_cast<int32*>(unboxed); |
| 337 | case MTypes::U4: |
| 338 | return *static_cast<uint32*>(unboxed); |
| 339 | case MTypes::I8: |
| 340 | return *static_cast<int64*>(unboxed); |
| 341 | case MTypes::U8: |
| 342 | return *static_cast<uint64*>(unboxed); |
| 343 | case MTypes::R4: |
| 344 | return *static_cast<float*>(unboxed); |
| 345 | case MTypes::R8: |
| 346 | return *static_cast<double*>(unboxed); |
| 347 | case MTypes::String: |
| 348 | return Variant(MUtils::ToString((MString*)value)); |
| 349 | case MTypes::Ptr: |
| 350 | return *static_cast<void**>(unboxed); |
| 351 | case MTypes::ValueType: |
| 352 | if (klass == stdTypes.GuidClass) |
| 353 | return Variant(*static_cast<Guid*>(unboxed)); |
| 354 | if (klass == stdTypes.Vector2Class) |
| 355 | return *static_cast<Vector2*>(unboxed); |
| 356 | if (klass == stdTypes.Vector3Class) |
| 357 | return *static_cast<Vector3*>(unboxed); |
| 358 | if (klass == stdTypes.Vector4Class) |
| 359 | return *static_cast<Vector4*>(unboxed); |
| 360 | if (klass == Int2::TypeInitializer.GetClass()) |
| 361 | return *static_cast<Int2*>(unboxed); |
| 362 | if (klass == Int3::TypeInitializer.GetClass()) |
| 363 | return *static_cast<Int3*>(unboxed); |
| 364 | if (klass == Int4::TypeInitializer.GetClass()) |
nothing calls this directly
no test coverage detected