/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: src/sgx/scripting/scriptmanager.cpp

*/

#include "sgx/core/types/types.hpp"
#include "sgx/core/stl/stl.hpp"
#include "sgx/core/helpers/trace.hpp"
#include "sgx/scripting/scripting.hpp"

CSGXScriptingManager  *CSGXScriptingManager::ms_pSingleton;

CSGXScriptingManager::CSGXScriptingManager()
{
}

CSGXScriptingManager::~CSGXScriptingManager()
{
}

CSGXScriptingManager *CSGXScriptingManager::get()
{
	if (!ms_pSingleton) {
		ms_pSingleton = new CSGXScriptingManager;
	}
	return ms_pSingleton;
}

tBOOL 
CSGXScriptingManager::registerObject(CScriptingEngine *pEngine, const sgxString &name)
{
    return m_ScriptEngines.insert(ScriptMap::value_type(name, pEngine)).second ? TRUE : FALSE;
}

CScriptState *CSGXScriptingManager::CreateInstance()
{
	if (m_ScriptEngines.begin() == m_ScriptEngines.end()) {
		return NULL;
	}

	return (*m_ScriptEngines.begin()).second->initialise();
}

CScriptState *CSGXScriptingManager::CreateInstance(const sgxString &name)
{
    ScriptMap::iterator it = m_ScriptEngines.find(name);

    if (it == m_ScriptEngines.end()) {
        return NULL;
    }

	return (*it).second->initialise();
}
