#include "Gos.pch"
#include "ClassInfo.h"

GosClassInfo *(*GosClassInfo::RegisterClass)( _TCHAR * ) = ClassInfo::RegisterClass;

ClassInfo *ClassInfo::m_pAnchorClass = NULL;

ClassInfo::ClassInfo( _TCHAR *name ) : GosClassInfo()
{
	m_pClassName = name;
	if( m_pAnchorClass )
	{
		m_pPrevClass = m_pAnchorClass->m_pPrevClass;
		m_pAnchorClass->m_pPrevClass = this;
		m_pNextClass = m_pAnchorClass;
	}
}


GosClassInfo *ClassInfo::RegisterClass( _TCHAR *className )
{
	ClassInfo *pInfo;

	if( !m_pAnchorClass )
	{
		// First time, need to create an object to anchor all classes
		m_pAnchorClass = new ClassInfo( _T("Anchor Class") );
		m_pAnchorClass->m_pNextClass = m_pAnchorClass;
		m_pAnchorClass->m_pPrevClass = m_pAnchorClass;
	}

	// now, search the list to see if we already have this class registered
	for( pInfo = m_pAnchorClass->m_pNextClass; pInfo != m_pAnchorClass; pInfo = pInfo->m_pNextClass )
	{
		if( _tcscmp( className, pInfo->m_pClassName ) == 0 )
			return (GosClassInfo *) pInfo;	// already have this class registered
	}

	return (GosClassInfo *) ( new ClassInfo( className ) );
}

