/******************************************************************
** Copyright (C) 2001, University of Alabama in Huntsville. 
** All rights reserved.
**
** File   : CRelationHierarchy.cpp
**
** Author : David Phillips
**
** Description:
**    This file provides implementation for the CRelationHierarchy
**    class.
**
** History:
**    24-Nov-2001 : David Phillips
**        Created file.
******************************************************************/

//## begin module%1.4%.codegen_version preserve=yes
//   Read the documentation to learn more about C++ code generator
//   versioning.
//## end module%1.4%.codegen_version

//## begin module%3BE21A8902B4.cm preserve=no
//	  %X% %Q% %Z% %W%
//## end module%3BE21A8902B4.cm

//## begin module%3BE21A8902B4.cp preserve=no
//## end module%3BE21A8902B4.cp

//## Module: CRelationHierarchy%3BE21A8902B4; Pseudo Package body
//## Source file: C:\Documents and Settings\dphillips.PORTABLE\Desktop\CS650\ConGraT\CGEngine\CRelationHierarchy.cpp

//## begin module%3BE21A8902B4.additionalIncludes preserve=no
//## end module%3BE21A8902B4.additionalIncludes

//## begin module%3BE21A8902B4.includes preserve=yes
//## end module%3BE21A8902B4.includes

// CRelationHierarchy
#include "CGEngine\CRelationHierarchy.h"
#include "CGEngine\CRelationDefinition.h"
#include <iostream>

// Class CRelationHierarchy 

CRelationHierarchy::CRelationHierarchy()
  //## begin CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_const.hasinit preserve=no
  //## end CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_const.hasinit
  //## begin CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_const.initialization preserve=yes
  //## end CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_const.initialization
{
  //## begin CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_const.body preserve=yes
  //## end CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_const.body
}

CRelationHierarchy::CRelationHierarchy(const CRelationHierarchy &right)
  //## begin CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_copy.hasinit preserve=no
  //## end CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_copy.hasinit
  //## begin CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_copy.initialization preserve=yes
  //## end CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_copy.initialization
{
  //## begin CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_copy.body preserve=yes
  //## end CRelationHierarchy::CRelationHierarchy%3BE21A8902B4_copy.body
}


CRelationHierarchy::~CRelationHierarchy()
{
  //## begin CRelationHierarchy::~CRelationHierarchy%3BE21A8902B4_dest.body preserve=yes
  //## end CRelationHierarchy::~CRelationHierarchy%3BE21A8902B4_dest.body
}

void CRelationHierarchy::Insert (ACConstruct* pConstruct)
{
	std::cout << "Inserting Def into RH" << std::endl;
	CRelationDefinition *pRelationDef = dynamic_cast<CRelationDefinition*>(pConstruct);
	
	if (pRelationDef)
	{
	  m_mapRelation.insert(RelationDefMap::value_type(pRelationDef->GetTypeName(), pRelationDef));
	  pRelationDef->SetParent(this);
	}
	else
	{
		std::cout << "*** Non-RelationDefinition inserted into RelationHierarchy" << std::endl;
	}
}

CRelationDefinition* CRelationHierarchy::FindByName(std::string sName) const
{
	RelationDefMap::const_iterator iter;
	
	iter = m_mapRelation.find(sName);
	
	if (iter == m_mapRelation.end())
	{
		return NULL;
	}
	else
	{
		return (*iter).second;
	}
}

void CRelationHierarchy::Commit()
{
	std::cout << "Committing RelationHierarchy" << std::endl;
	
	CRelationDefinition *pRelation = FindByName("Relation");

	if (!pRelation)
	{
		std::cout << "*** Relation Definition was not found" << std::endl;
		exit (1);
	}

    pRelation->Commit();

	std::cout << std::endl << "Relation Hierarchy:" << std::endl;
	pRelation->Browse();
	std::cout << std::endl;
}

CRelationHierarchy & CRelationHierarchy::operator=(const CRelationHierarchy &right)
{
  //## begin CRelationHierarchy::operator=%3BE21A8902B4_assign.body preserve=yes
	throw ACConstruct::Not_Implemented_Yet();
  //## end CRelationHierarchy::operator=%3BE21A8902B4_assign.body
}


int CRelationHierarchy::operator==(const CRelationHierarchy &right) const
{
  //## begin CRelationHierarchy::operator==%3BE21A8902B4_eq.body preserve=yes
	throw ACConstruct::Not_Implemented_Yet();
  //## end CRelationHierarchy::operator==%3BE21A8902B4_eq.body
}

int CRelationHierarchy::operator!=(const CRelationHierarchy &right) const
{
  //## begin CRelationHierarchy::operator!=%3BE21A8902B4_neq.body preserve=yes
	throw ACConstruct::Not_Implemented_Yet();
  //## end CRelationHierarchy::operator!=%3BE21A8902B4_neq.body
}


// Additional Declarations
  //## begin CRelationHierarchy%3BE21A8902B4.declarations preserve=yes
  //## end CRelationHierarchy%3BE21A8902B4.declarations

//## begin module%3BE21A8902B4.epilog preserve=yes
//## end module%3BE21A8902B4.epilog
