std::ostream& Relation::Print(std::ostream& os) const { os << "Start of Relation: " << endl; int i = 0; Tuple* t = 0; GenericRelationIterator* it = MakeScan(); while ((t = it->GetNextTuple()) != 0) { os << i << ".Tuple: "; t->Print(os); t->DeleteIfAllowed(); t = 0; i++; os << endl; } delete it; it = 0; os << "End of Relation." << endl; return os; }
GenericRelation *Relation::In( ListExpr typeInfo, ListExpr value, int errorPos, ListExpr& errorInfo, bool& correct, bool tupleBuf /*=false*/) { ListExpr tuplelist, TupleTypeInfo, first; GenericRelation* rel; Tuple* tupleaddr; int tupleno, count; bool tupleCorrect; correct = true; count = 0; if (tupleBuf) rel = new TupleBuffer; else rel = new Relation( typeInfo ); tuplelist = value; TupleTypeInfo = nl->TwoElemList(nl->Second(typeInfo), nl->IntAtom(nl->ListLength(nl->Second(nl->Second(typeInfo))))); tupleno = 0; if (nl->IsAtom(value)) { correct = false; errorInfo = nl->Append(errorInfo, nl->ThreeElemList( nl->IntAtom(70), nl->SymbolAtom(Relation::BasicType()), tuplelist)); return rel; } else { // increase tupleno while (!nl->IsEmpty(tuplelist)) { first = nl->First(tuplelist); tuplelist = nl->Rest(tuplelist); tupleno++; tupleaddr = Tuple::In(TupleTypeInfo, first, tupleno, errorInfo, tupleCorrect); if (tupleCorrect) { rel->AppendTuple(tupleaddr); tupleaddr->DeleteIfAllowed(); count++; } else { correct = false; } } if (!correct) { errorInfo = nl->Append(errorInfo, nl->TwoElemList( nl->IntAtom(72), nl->SymbolAtom(Relation::BasicType()))); delete rel; return 0; } else return rel; } }