/* 4 Implementation of the class ~Tuple~ */ Tuple *Tuple::Clone() const { Counter::getRef("RA:ClonedTuples")++; Tuple *result = new Tuple( this->GetTupleType() ); for( int i = 0; i < this->GetNoAttributes(); i++ ) { Attribute* tmp = GetAttribute(i); Attribute *attr = tmp?tmp->Clone():0; result->PutAttribute( i, attr ); } return result; }
Tuple *Tuple::In( ListExpr typeInfo, ListExpr value, int errorPos, ListExpr& errorInfo, bool& correct ) { int attrno, algebraId, typeId, noOfAttrs; Word attr; bool valueCorrect; ListExpr first, firstvalue, valuelist, attrlist; attrno = 0; noOfAttrs = 0; Tuple *t = new Tuple( nl->First( typeInfo ) ); attrlist = nl->Second(nl->First(typeInfo)); valuelist = value; correct = true; if (nl->IsAtom(valuelist)) { correct = false; cout << "Error in reading tuple: an atom instead of a list " << "of values." << endl; cout << "Tuple no." << errorPos << endl; cout << "The tuple is: " << endl; nl->WriteListExpr(value); errorInfo = nl->Append(errorInfo, nl->FourElemList( nl->IntAtom(71), nl->SymbolAtom(Tuple::BasicType()), nl->IntAtom(1), nl->IntAtom(errorPos))); delete t; return 0; } else { while (!nl->IsEmpty(attrlist)) { first = nl->First(attrlist); attrlist = nl->Rest(attrlist); algebraId = t->GetTupleType()->GetAttributeType( attrno ).algId; typeId = t->GetTupleType()->GetAttributeType( attrno ).typeId; attrno++; if (nl->IsEmpty(valuelist)) { correct = false; cout << "Error in reading tuple: list of values is empty." << endl; cout << "Tuple no." << errorPos << endl; cout << "The tuple is: " << endl; nl->WriteListExpr(value); errorInfo = nl->Append(errorInfo, nl->FourElemList( nl->IntAtom(71), nl->SymbolAtom(Tuple::BasicType()), nl->IntAtom(2), nl->IntAtom(errorPos))); delete t; return 0; } else { firstvalue = nl->First(valuelist); valuelist = nl->Rest(valuelist); attr = (am->InObj(algebraId, typeId)) (nl->First(nl->Rest(first)), firstvalue, attrno, errorInfo, valueCorrect); if (valueCorrect) { correct = true; t->PutAttribute(attrno - 1, (Attribute *)attr.addr); noOfAttrs++; } else { correct = false; cout << "Error in reading tuple: " << "wrong attribute value representation." << endl; cout << "Tuple no." << errorPos << endl; cout << "The tuple is: " << endl; nl->WriteListExpr(value); cout << endl << "The attribute is: " << endl; nl->WriteListExpr(firstvalue); cout << endl; errorInfo = nl->Append(errorInfo, nl->FiveElemList( nl->IntAtom(71), nl->SymbolAtom(Tuple::BasicType()), nl->IntAtom(3), nl->IntAtom(errorPos), nl->IntAtom(attrno))); delete t; return 0; } } } if (!nl->IsEmpty(valuelist)) { correct = false; cout << "Error in reading tuple: " << "too many attribute values." << endl; cout << "Tuple no." << errorPos << endl; cout << "The tuple is: " << endl; nl->WriteListExpr(value); errorInfo = nl->Append(errorInfo, nl->FourElemList( nl->IntAtom(71), nl->SymbolAtom(Tuple::BasicType()), nl->IntAtom(4), nl->IntAtom(errorPos))); delete t; return 0; } } return t; }