Beispiel #1
0
bool canSerializeField(const GMetaArchiveConfig & config, IMetaAccessible * accessible, IMetaService * service)
{
	if(accessible == NULL) {
		return false;
	}

	if(! accessible->canGet()) {
		return false;
	}
	if(! accessible->canSet()) {
		return false;
	}

	GMetaType metaType = metaGetItemType(accessible);
	if(! canSerializeMetaType(metaType)) {
		return false;
	}

	if(metaType.getBaseName() != NULL) {
		GScopedInterface<IMetaClass> metaClass(service->findClassByName(metaType.getBaseName()));
		if(! canSerializeObject(config, metaClass.get())) {
			return false;
		}
	}

	return canSerializeItem(config, accessible);
}
Beispiel #2
0
GVariant GMetaCore::cast(const GVariant & instance, IMetaClass * targetMetaClass)
{
	GVariant value = getVariantRealValue(instance);
	GMetaType type = getVariantRealMetaType(instance);
	
	if(canFromVariant<void *>(value) && type.getBaseName() != NULL) {
		GScopedInterface<IMetaService> metaService(this->scriptObject->getMetaService());
		GScopedInterface<IMetaClass> sourceClass(metaService->findClassByName(type.getBaseName()));
		if(sourceClass) {
			void * ptr = objectAddressFromVariant(instance);
			void * oldPtr = ptr;
			if(ptr != NULL) {
				GMetaType targetType;
				if(targetMetaClass != NULL) {
					ptr = metaCastToDerived(oldPtr, sourceClass.get(), targetMetaClass);
					if(ptr == NULL) {
						ptr = metaCastToBase(oldPtr, sourceClass.get(), targetMetaClass);
					}
					targetType = metaGetItemType(targetMetaClass);
				}
				else {
					GScopedInterface<IMetaClass> derivedClass(findAppropriateDerivedClass(oldPtr, sourceClass.get(), &ptr));
					if(derivedClass) {
						targetType = metaGetItemType(derivedClass.get());
					}
					else {
						ptr = NULL;
					}
				}

				if(ptr != NULL) {
					targetType.addPointer();
					return createTypedVariant(pointerToObjectVariant(ptr), targetType);
				}
			}
		}
	}

	return (void *)0;
}
Beispiel #3
0
GScriptValue doCreateScriptValueFromVariant(
		const GContextPointer & context,
		const GVariant & value,
		const GMetaType & type,
		const bool transferOwnership
	)
{
	const GVariantType vt = static_cast<GVariantType>((GVtType)value.getType() & ~(GVtType)GVariantType::maskByReference);

	if(! type.isEmpty() && type.getPointerDimension() <= 1) {
		GScopedInterface<IMetaTypedItem> typedItem(context->getService()->findTypedItemByName(type.getBaseName()));
		if(typedItem) {
			GASSERT_MSG(!! metaIsClass(typedItem->getCategory()), "Unknown type");

			return GScriptValue::fromObject(value, gdynamic_cast<IMetaClass *>(typedItem.get()), transferOwnership, metaTypeToCV(type));
		}
		else {
			if(vtIsInterface(vt)) {
				IObject * obj = fromVariant<IObject *>(value);
				if(IMetaClass * metaClass = dynamic_cast<IMetaClass *>(obj)) {
					return GScriptValue::fromClass(metaClass);
				}
			}
		}
	}

	return GScriptValue::fromPrimary(value);
}