/** 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/core/settings/configuration.cpp

*/

#include "sgx/core/core.hpp"

CConfiguration	*CConfiguration::m_pSingleton;

CConfiguration *CConfiguration::get()
{
	if (!m_pSingleton) {
		m_pSingleton = new CConfiguration();
	}
	return m_pSingleton;
}

CConfiguration::CConfiguration() 
{
	m_bcomplete = FALSE;
}

/**
add a mapping between @opt and @value in the configuration. Any changes
to 'complete' configurations (i.e. those issued after @complete is called)
are ignored, and existing options are replaced.
*/ 
void 
CConfiguration::setOption(const sgxString &opt, tINT32 value)
{
    if (m_bcomplete) {
        sgxTrace("Option '%s' ignored!", opt.c_str());
        return;
    }

    m_Options[opt] = value;
}

/**
Returns the current value of the specified option, @opt. If the option
doesn't exist, then the default @opt_default is returned.
*/
tINT32	CConfiguration::getOption(const sgxString &opt, tINT32 opt_default/*=0*/)
{
	sgxOptionMap::iterator it = m_Options.find(opt);

	if (it == m_Options.end()) {
		return opt_default;
	}

	return (*it).second;
}

/**
Marks this configuration as 'complete'. This means that no other options can be
added. This helps stops mispellings (e.g. GODMODE and GOODMODE) from both 
being used.
*/
void 
CConfiguration::complete(void)
{
	m_bcomplete = TRUE;
}
