// __author__ = Juan Carlos De Abreu (jcabreur@gmail.com)

#include "DataFunction.h"
#include "../SceneFile.h"
#include "../DataTypes.h"

BEGIN_TEG_NAMESPACE();

SmartPointer<IData> Function::resolve(std::map<std::string, SmartPointer<IData>>& variables) {
	// Execute all the instructions of the function with out delete the definition of eah ...
	return NULL;
}

SmartPointer<IData> Function::call(std::vector<SmartPointer<IData>> param_) {
	// Check if the number of param is the same 
	const int nParamNeeded = static_cast<int> (param.size());
	const int nParamPassed = static_cast<int> (param_.size());
	if (nParamNeeded != nParamPassed) return NULL;

	// The fist thing is copy all the parameters in the map of variables
	// create a new instance to avoid modify the origial value, this means that
	// all the values are passed by value
	std::map<std::string, SmartPointer<IData>> variables;
	for (int i = 0; i < nParamNeeded; ++i) {
		// I will supposse that here the param only are values ...
		// This works if I want that the values are passed by reference
		variables[param[i]] = param_[i];
	}

	// Do all the instrucctions
	const int nInst = static_cast<int> (inst.size());
	for (int i = 0; i < nInst; ++i) {
		SmartPointer<IData> tmp = inst[i]->resolve(variables);
		if (tmp != NULL && tmp->type == IData::DATA_VECTOR) {}
		if (SceneFileManagement::GetInstance().isReturning) {
		  SceneFileManagement::GetInstance().isReturning = false;
		  return tmp;
		}
	}

	return NULL;
}

END_TEG_NAMESPACE();
