void Formula::copy(TermList *frm, TermList *to) { int sz = frm->getList()->size(); for (int i = 0; i < sz; i++) { Term *t = frm->getList()->at(i); if (t->getType() == Term::CONS) { to->addTerm(t); } else if (t->getType() == Term::VAR) { if (t->isFree()) { to->addTerm(t); } else { Term *x = new Term(*t); to->addTerm(x); } } else { TermList *list = new TermList(); this->copy(t->getTermList(), list); Term *f = new Term(t->getName(), list); to->addTerm(f); } } }
bool Term::operator ==(Term &term) { if (this->type != term.type || strcmp(this->name, term.getName())) return false; if (this->type == FUNC) { return *(this->termList) == *(term.getTermList()); } else { return true; } }
/* * Copy Constructor */ Term::Term(Term &term) { this->free = term.free; this->type = term.type; this->name = new char[strlen(term.name) + 1]; strcpy(this->name, term.getName()); if (this->type == FUNC) { this->termList = new TermList(); for (int i = 0; i < term.getTermList()->getList()->size(); i++) { Term *t = new Term(*(term.getTermList()->getList()->at(i))); this->termList->addTerm(t); } } }