/******************************************************************
** Copyright (C) 2001, University of Alabama in Huntsville. 
** All rights reserved.
**
** File   : CTypeHierarchy.cpp
**
** Author : David Phillips
**
** Description:
**    This file provides implementation for the CTypeHierarchy
**    class.
**
** History:
**    24-Nov-2001 : David Phillips
**        Created file.
**    02-Dec-2001 : Satish Hota
**        Added and implemented GetTypes method.
******************************************************************/

#include "CGEngine\CTypeHierarchy.h"
#include "CGEngine\CTypeDefinition.h"
#include "CLIPSInterface\Class.h"

#include <iostream>


// Class CTypeHierarchy 
CTypeHierarchy::CTypeHierarchy()
{
}

CTypeHierarchy::CTypeHierarchy(const CTypeHierarchy &right)
{
}


CTypeHierarchy::~CTypeHierarchy()
{
}


void CTypeHierarchy::Insert (ACConstruct* pConstruct)
{
	std::cout << "Inserting Def into TH" << std::endl;
	CTypeDefinition *pTypeDef = dynamic_cast<CTypeDefinition*>(pConstruct);
	
	if (pTypeDef)
	{
	  m_mapType.insert(TypeDefMap::value_type(pTypeDef->GetTypeName(), pTypeDef));
	  pTypeDef->SetParent(this);
	}
	else
	{
		std::cout << "*** Non-TypeDefinition inserted into TypeHierarchy" << std::endl;
	}
}

CTypeDefinition* CTypeHierarchy::FindByName(std::string sName) const 
{
	TypeDefMap::const_iterator iter;
	
	iter = m_mapType.find(sName);
	
	if (iter == m_mapType.end())
	{
		return NULL;
	}
	else
	{
		return (*iter).second;
	}
}

void CTypeHierarchy::Commit()
{
	std::cout << "Committing TypeHierarchy" << std::endl;
	
	CTypeDefinition *pEntity = FindByName("Entity");

	if (!pEntity)
	{
		std::cout << "*** Entity TypeDefinition was not found" << std::endl;
		exit (1);
	}

    pEntity->Commit();

	std::cout << std::endl << "Type Hierarchy:" << std::endl;
	pEntity->Browse();
	std::cout << std::endl;
}

CTypeHierarchy & CTypeHierarchy::operator=(const CTypeHierarchy &right)
{
	throw ACConstruct::Not_Implemented_Yet();
}


int CTypeHierarchy::operator==(const CTypeHierarchy &right) const
{
	throw ACConstruct::Not_Implemented_Yet();
}

int CTypeHierarchy::operator!=(const CTypeHierarchy &right) const
{
	throw ACConstruct::Not_Implemented_Yet();
}

const CTypeHierarchy::TypeDefMap* CTypeHierarchy::GetTypes()
{
	return &m_mapType;
}

