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

#include "DataId.h"

BEGIN_TEG_NAMESPACE();

SmartPointer<IData> DataID::resolve(std::map<std::string, SmartPointer<IData>>& variables) {
	// Search in the local variables and then in the gloabal variables
	if (variables.find(value) != variables.end()) return variables[value];

	const int nFiles = static_cast<int> (SceneFileManagement::GetInstance().sceneFiles.size());
	std::list<SceneFile>::iterator it = SceneFileManagement::GetInstance().sceneFiles.begin();
	std::list<SceneFile>::iterator end = SceneFileManagement::GetInstance().sceneFiles.end();
	for (int i = 0; i < nFiles; ++i, ++it) {
		if (it->variables.find(value) != it->variables.end())
			return it->variables[value];
	}

	PRINT_LOG(TYPE_ERROR, "Error: %s : undeclared identifier", value.c_str());
	return NULL;
}

END_TEG_NAMESPACE();
