//---------------------------------------------------------------------------

#include "stdafx.h"

using namespace std;

#pragma hdrstop

#include "myExcept.h"
#include "bitvector.h"
#include "PLA_type.h"
#include "SoTerm.h"
#include "SoPLA.h"
//---------------------------------------------------------------------------


SoPLA::SoPLA(void)
{
}

SoPLA::SoPLA( const unsigned int iv )
{
	inputs = iv;
}

SoPLA::SoPLA( const SoPLA *_pla )
{
	inputs = _pla->inputs;
}

SoPLA::~SoPLA(void)
{
}

list<SoTerm>::iterator SoPLA::AppendTerm( const SoTerm &t )
{
	list<SoTerm>::iterator ti;

	if ( inputs != t.GetIMSize() ) throw RuntimeException( "SoPLA::AppendTerm: incompatible terms" );
	data.push_back(t);
	ti = data.end();
	ti--;
	return ti;
}

list<SoTerm>::iterator SoPLA::AppendTerm( const string s )
{
	SoTerm t;

	t.SetIM(s);
	return AppendTerm(t);
}

void SoPLA::AppendPLA(const SoPLA &_pla)
// appends a given PLA to this
{
	SoTermList::const_iterator ti;

	for ( ti = _pla.data.begin(); ti != _pla.data.end(); ti++ )
		AppendTerm(*ti);
}

string SoPLA::GetIName(const unsigned int i) const
{
	if ( inames.empty() ) return "";
	else return inames[i];
}

void SoPLA::SetIName(const unsigned int i, const string name)
{
	if ( inames.empty() ) inames.resize( inputs, "" );
	if ( i >= inputs ) throw RuntimeException( "SoPLA::SetIName: Incorrect index" );
	inames[i] = name;
}
