void DataObject::replaceInput(PrimitivePtr p, PrimitivePtr new_p) { if (VectorPtr v = kst_cast<Vector>(p) ) { if (VectorPtr new_v = kst_cast<Vector>(new_p)) { for (VectorMap::Iterator j = _inputVectors.begin(); j != _inputVectors.end(); ++j) { if (j.value() == v) { _inputVectors[j.key()] = new_v; } } } } else if (MatrixPtr m = kst_cast<Matrix>(p) ) { if (MatrixPtr new_m = kst_cast<Matrix>(new_p)) { for (MatrixMap::Iterator j = _inputMatrices.begin(); j != _inputMatrices.end(); ++j) { if (j.value() == m) { _inputMatrices[j.key()] = new_m; } } } } else if (StringPtr s = kst_cast<String>(p) ) { if (StringPtr new_s = kst_cast<String>(new_p)) { for (StringMap::Iterator j = _inputStrings.begin(); j != _inputStrings.end(); ++j) { if (j.value() == s) { _inputStrings[j.key()] = new_s; } } } } else if (ScalarPtr s = kst_cast<Scalar>(p) ) { if (ScalarPtr new_s = kst_cast<Scalar>(new_p)) { for (ScalarMap::Iterator j = _inputScalars.begin(); j != _inputScalars.end(); ++j) { if (j.value() == s) { _inputScalars[j.key()] = new_s; } } } } }
bool DataObject::deleteDependents() { // FIXME: redo #if 0 dataObjectList.lock().readLock(); DataObjectList dol = dataObjectList; dataObjectList.lock().unlock(); for (DataObjectList::Iterator i = dol.begin(); i != dol.end(); ++i) { bool user = (*i)->uses(this); if (!user) { for (VectorMap::Iterator j = _outputVectors.begin(); !user && j != _outputVectors.end(); ++j) { user = (*i)->uses(j.value().data()); } for (ScalarMap::Iterator j = _outputScalars.begin(); !user && j != _outputScalars.end(); ++j) { user = (*i)->uses(j.value().data()); } for (StringMap::Iterator j = _outputStrings.begin(); !user && j != _outputStrings.end(); ++j) { user = (*i)->uses(j.value().data()); } } if (user) { DataObjectPtr dop = *i; dataObjectList.lock().writeLock(); dataObjectList.removeAll(dop); dataObjectList.lock().unlock(); dop->deleteDependents(); } } #endif return true; }
bool DataObject::uses(ObjectPtr p) const { VectorPtr v = kst_cast<Vector>(p); if (v) { for (VectorMap::ConstIterator j = _inputVectors.begin(); j != _inputVectors.end(); ++j) { if (j.value() == v) { return true; } } QHashIterator<QString, Scalar*> scalarDictIter(v->scalars()); for (ScalarMap::ConstIterator j = _inputScalars.begin(); j != _inputScalars.end(); ++j) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == j.value()) { return true; } } } } else if (MatrixPtr matrix = kst_cast<Matrix>(p)) { for (MatrixMap::ConstIterator j = _inputMatrices.begin(); j != _inputMatrices.end(); ++j) { if (j.value() == matrix) { return true; } } QHashIterator<QString, Scalar*> scalarDictIter(matrix->scalars()); for (ScalarMap::ConstIterator j = _inputScalars.begin(); j != _inputScalars.end(); ++j) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == j.value()) { return true; } } } } else if (DataObjectPtr obj = kst_cast<DataObject>(p) ) { // check all connections from this object to p for (VectorMap::Iterator j = obj->outputVectors().begin(); j != obj->outputVectors().end(); ++j) { for (VectorMap::ConstIterator k = _inputVectors.begin(); k != _inputVectors.end(); ++k) { if (j.value() == k.value()) { return true; } } // also check dependencies on vector stats QHashIterator<QString, Scalar*> scalarDictIter(j.value()->scalars()); for (ScalarMap::ConstIterator k = _inputScalars.begin(); k != _inputScalars.end(); ++k) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == k.value()) { return true; } } } } for (MatrixMap::Iterator j = obj->outputMatrices().begin(); j != obj->outputMatrices().end(); ++j) { for (MatrixMap::ConstIterator k = _inputMatrices.begin(); k != _inputMatrices.end(); ++k) { if (j.value() == k.value()) { return true; } } // also check dependencies on vector stats QHashIterator<QString, Scalar*> scalarDictIter(j.value()->scalars()); for (ScalarMap::ConstIterator k = _inputScalars.begin(); k != _inputScalars.end(); ++k) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == k.value()) { return true; } } } } for (ScalarMap::Iterator j = obj->outputScalars().begin(); j != obj->outputScalars().end(); ++j) { for (ScalarMap::ConstIterator k = _inputScalars.begin(); k != _inputScalars.end(); ++k) { if (j.value() == k.value()) { return true; } } } for (StringMap::Iterator j = obj->outputStrings().begin(); j != obj->outputStrings().end(); ++j) { for (StringMap::ConstIterator k = _inputStrings.begin(); k != _inputStrings.end(); ++k) { if (j.value() == k.value()) { return true; } } } } return false; }
void DataObject::replaceDependency(DataObjectPtr oldObject, DataObjectPtr newObject) { // find all connections from this object to old object // vectors for (VectorMap::Iterator j = oldObject->outputVectors().begin(); j != oldObject->outputVectors().end(); ++j) { for (VectorMap::Iterator k = _inputVectors.begin(); k != _inputVectors.end(); ++k) { if (j.value().data() == k.value().data()) { // replace input with the output from newObject _inputVectors[k.key()] = (newObject->outputVectors())[j.key()]; } } // also replace dependencies on vector stats QHashIterator<QString, Scalar*> scalarDictIter(j.value()->scalars()); for (ScalarMap::Iterator k = _inputScalars.begin(); k != _inputScalars.end(); ++k) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == k.value()) { _inputScalars[k.key()] = (((newObject->outputVectors())[j.key()])->scalars())[scalarDictIter.key()]; } } } } // matrices for (MatrixMap::Iterator j = oldObject->outputMatrices().begin(); j != oldObject->outputMatrices().end(); ++j) { for (MatrixMap::Iterator k = _inputMatrices.begin(); k != _inputMatrices.end(); ++k) { if (j.value().data() == k.value().data()) { // replace input with the output from newObject _inputMatrices[k.key()] = (newObject->outputMatrices())[j.key()]; } } // also replace dependencies on matrix stats QHashIterator<QString, Scalar*> scalarDictIter(j.value()->scalars()); for (ScalarMap::Iterator k = _inputScalars.begin(); k != _inputScalars.end(); ++k) { while (scalarDictIter.hasNext()) { scalarDictIter.next(); if (scalarDictIter.value() == k.value()) { _inputScalars[k.key()] = (((newObject->outputMatrices())[j.key()])->scalars())[scalarDictIter.key()]; } } } } // scalars for (ScalarMap::Iterator j = oldObject->outputScalars().begin(); j != oldObject->outputScalars().end(); ++j) { for (ScalarMap::Iterator k = _inputScalars.begin(); k != _inputScalars.end(); ++k) { if (j.value().data() == k.value().data()) { // replace input with the output from newObject _inputScalars[k.key()] = (newObject->outputScalars())[j.key()]; } } } // strings for (StringMap::Iterator j = oldObject->outputStrings().begin(); j != oldObject->outputStrings().end(); ++j) { for (StringMap::Iterator k = _inputStrings.begin(); k != _inputStrings.end(); ++k) { if (j.value().data() == k.value().data()) { // replace input with the output from newObject _inputStrings[k.key()] = (newObject->outputStrings())[j.key()]; } } } }