Exemple #1
0
Plugin* PluginManager::getPluginFromClass(const Class* klass)
{
	for( size_t i = 0; i < plugins.size(); i++ )
	{
		Plugin* plugin = plugins[i];
		if(ClassGetType(plugin) == klass) return plugin;
	}

	return nullptr;
}
Exemple #2
0
void ReflectionWalk(const Object* object, ReflectionContext* context)
{
	if( !context ) return;

	Class* objectClass = ClassGetType(object);
	if( !objectClass ) return;

	context->object = (Object*) object;
	context->objectClass = objectClass;
	context->composite = objectClass;
	
	ReflectionWalkType(context, objectClass);
}
Exemple #3
0
static void ReflectionWalkArray(ReflectionContext* context)
{
	const Field* field = context->field;
	std::vector<byte>& array = *(std::vector<byte>*) context->address;

	uint16 elementSize = ReflectionArrayGetElementSize(context->field);
	uint32 arraySize = array.size() / elementSize;

	context->arraySize = arraySize;
	context->walkArray(context, ReflectionWalkType::Begin);
		
	for(size_t i = 0; i < arraySize; i++)
	{
		void* address = (&array[0] + i * elementSize);
		
		context->elementAddress = address;
		
		if(FieldIsPointer(field) && !ReflectionWalkPointer(context))
			continue;

		Object* object = context->object;
		Type* type = context->type;

		context->object = (Object*) context->elementAddress;
		context->type = field->type;

		bool isObject = ClassInherits((Class*) context->type, ObjectGetType());
		if( isObject ) context->type = ClassGetType(context->object);

		if( isObject && !context->type )
		{
			LogDebug("Could not get type out of object");
			return;
		}

		context->walkArray(context, ReflectionWalkType::ElementBegin);
		ReflectionWalkType(context, context->type);
		context->walkArray(context, ReflectionWalkType::ElementEnd);

		context->object = object;
		context->type = type;
	}

	context->walkArray(context, ReflectionWalkType::End);
}
Exemple #4
0
void ReflectionWalkCompositeField(ReflectionContext* context)
{
	const Field* field = context->field;

	if( !FieldIsSerializable(field) )
	{
		LogDebug("Ignoring field '%s'", field->name);
		return;
	}

	void* address = context->address;
	void* elementAddress = context->elementAddress;
	Type* type = context->type;
	Object* object = context->object;

 	context->address = ClassGetFieldAddress(context->object, field);
	context->elementAddress = context->address;
	context->type = field->type;

	if( ReflectionIsComposite(field->type) )
		context->object = (Object*) context->address;

	if( FieldIsPointer(field) && !ReflectionWalkPointer(context) )
		goto exit;

	context->walkCompositeField(context, ReflectionWalkType::Begin);

	ReflectionWalkFunction handleSerialize = nullptr;
	
	if (ReflectionIsComposite(field->type))
		HandleFindSerializeFunction(context, (Class*) field->type);

	// Check for custom handle serialize functions.
	if( FieldIsHandle(field) && handleSerialize )
	{
		handleSerialize(context, ReflectionWalkType::Element);
	}
	else if( field->serialize )
	{
		field->serialize(context, ReflectionWalkType::Element);
	}
	else if( FieldIsArray(field) )
	{
		ReflectionWalkArray(context);
	}
	else if( FieldIsPointer(field) )
	{
		Object* object = context->object;
		Type* type = context->type;

		context->type = ClassGetType(context->object);
		ReflectionWalkType(context, context->type);

		context->type = type;
		context->object = object;
	}
	else
	{
		ReflectionWalkType(context, field->type);
	}

	context->walkCompositeField(context, ReflectionWalkType::End);

exit:

	context->address = address;
	context->elementAddress = elementAddress;
	context->type = type;
	context->object = object;
}