//_________________________________________________________________________________________________ void Normalize(AliMergeableCollection& hc) { TObjArray* a = hc.SortAllIdentifiers(); TIter nextId(a); TObjString* sid; while ( ( sid = static_cast<TObjString*>(nextId()) ) ) { std::cout << sid->String() << std::endl; if ( !sid->String().Contains("HITS") ) continue; TObjArray* parts = sid->String().Tokenize("/"); TString npadsId("/"); npadsId += static_cast<TObjString*>(parts->At(0))->String(); npadsId += "/NPADS"; delete parts; std::cout << npadsId << std::endl; TList* list = hc.CreateListOfObjectNames(sid->String().Data()); TIter nextObject(list); TObjString* sobject; while ( ( sobject = static_cast<TObjString*>(nextObject())) ) { std::cout << " " << sobject->String() << std::endl; } delete list; } delete a; }
struct polygon *makeTriangle(int x, int y, int z) /* Make triangle about center x,y,z */ { struct polygon *tri; struct point *pt; int i; AllocVar(tri); tri->id = nextId(); tri->pointCount = 3; AllocVar(pt); strcpy(pt->acc, "acc1"); pt->pt.x = pt->x = x; pt->pt.y = pt->y = y-100; pt->z = z; slAddTail(&tri->points, pt); AllocVar(pt); strcpy(pt->acc, "acc2"); pt->pt.x = pt->x = x-100; pt->pt.y = pt->y = y+100; pt->z = z; slAddTail(&tri->points, pt); AllocVar(pt); strcpy(pt->acc, "acc3"); pt->pt.x = pt->x = x+100; pt->pt.y = pt->y = y+100; pt->z = z; slAddTail(&tri->points, pt); AllocArray(tri->persp, 3); for (i=0, pt = tri->points; i < 3; ++i, pt = pt->next) { tri->persp[i].x = pt->x/2; tri->persp[i].y = pt->y/2; } return tri; }
Function(std::function<Signature> function, sf::Time timeUntilRemoval) : function(std::move(function)) , timeUntilRemoval(timeUntilRemoval) , id(nextId()) , tracker() { }
LightSource::LightSource( const GLfloat* pos, const GLfloat* amb, const GLfloat* diff, const GLfloat* spec, const GLfloat* spot, GLfloat s_exp, GLfloat s_cut, GLfloat a_con, GLfloat a_lin, GLfloat a_quad ) { createIdPool(); DUP4( position, 0.0, 0.0, 1.0, 0.0 ) DUP4( ambient, 0.0, 0.0, 0.0, 1.0 ) DUP4( diffuse, 0.0, 0.0, 0.0, 1.0 ) DUP4( specular, 0.0, 0.0, 0.0, 1.0 ) DUP3( spot_dir, 0.0, 0.0, -1.0 ) if( pos ) { DUP4( position, pos[0], pos[1], pos[2], pos[3] ) } if( amb ) { DUP4( ambient, amb[0], amb[1], amb[2], amb[4] ) } if( diff) { DUP4( diffuse, diff[0], diff[1], diff[2], diff[3] ) } if( spec) { DUP4( specular, spec[0], spec[1], spec[2], spec[3] ) } if( spot) { DUP3( spot_dir, spot[0], spot[1], spot[2] ) } spot_exp = s_exp; spot_cut = s_cut; att_constant = a_con; att_linear = a_lin; att_quadratic = a_quad; _enabled = true; _id = nextId(); }
int addWizard::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWizard::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: finishedWizard(); break; case 1: on_npcListCombobox_currentIndexChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 2: on_npcGraphicSizeSpin_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: on_comboBox_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 4: pageChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 5: { int _r = nextId(); if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; } break; default: ; } _id -= 6; } return _id; }
void CompleteWiz::skip() { Operate[currentId()]=false; if(nextId()!=-1) next(); else emit accept(); }
bool ChooseOrDumpPage::validatePage() { if(nextId() == HistoryManagerWindow::ChooseClient) { m_parent->restart(); return false; } return true; }
/** Create a string representation of the IdMap. * @param s is the string in which the result is returned. */ string& IdMap::toString(string& s) const { stringstream ss; ss << "{ "; for (int i = firstId(); i != 0; i = nextId(i)) { ss << "(" << ht->getKey(i) << "," << i << ") "; } ss << "}"; s = ss.str(); return s; }
//MakeMemblock void MemInterface::functionMakeMEMBlock(void){ int32_t size = cb->popValue().getInt(); uint8_t *mem = new uint8_t[size + 4]; *((int32_t *)mem) = size; memset(mem + 4, 0, size); int32_t id = nextId(); memblockMap[id] = mem; cb->pushValue(id); }
qint32 HConnectionManagerSinkService::prepareForConnection( const HProtocolInfo& remoteProtocolInfo, const HConnectionManagerId& peerConnectionManager, qint32 peerConnectionId, HConnectionManagerInfo::Direction direction, HPrepareForConnectionResult* result) { Q_ASSERT(result); if (!actions().value("PrepareForConnection")) { return UpnpOptionalActionNotImplemented; } if (direction != HConnectionManagerInfo::DirectionInput) { return HConnectionManagerInfo::IncompatibleDirections; } if (remoteProtocolInfo.protocol().compare("http-get", Qt::CaseInsensitive) && remoteProtocolInfo.protocol() != "*") { return HConnectionManagerInfo::IncompatibleProtocolInfo; } if (!isMimetypeValid( remoteProtocolInfo.contentFormat(), sinkProtocolInfo())) { return HConnectionManagerInfo::IncompatibleProtocolInfo; } qint32 connectionId = nextId(); qint32 avTransportId, rcsId; qint32 errCode = m_owner->prepareForConnection( remoteProtocolInfo.contentFormat(), connectionId, &avTransportId, &rcsId); if (errCode != UpnpSuccess) { return errCode; } HConnectionInfo connectionInfo( connectionId, avTransportId, rcsId, remoteProtocolInfo, peerConnectionManager, peerConnectionId, HConnectionManagerInfo::DirectionInput, HConnectionManagerInfo::StatusOk); result->setAvTransportId(avTransportId); result->setConnectionId(connectionId); result->setRcsId(rcsId); addConnection(connectionInfo); return UpnpSuccess; }
EntityManager::EntityManager() : _id(nextId()) { std::shared_ptr<sf::CircleShape> shape = std::make_shared<sf::CircleShape>(40); shape->setFillColor(sf::Color::Cyan); kult::entity entity; entity[transform] = shape; entity[drawable] = shape; entity[position] = sf::Vector2i(); entity[manager] = _id; }
void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QString &name, bool regex, bool cs, const QString &sender, const QString &chanName, bool self) { ui.ignoredTable->setRowCount(ui.ignoredTable->rowCount() + 1); if (id < 0) { id = nextId(); } auto *nameItem = new QTableWidgetItem(name); auto *regexItem = new QTableWidgetItem(""); if (regex) regexItem->setCheckState(Qt::Checked); else regexItem->setCheckState(Qt::Unchecked); regexItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *csItem = new QTableWidgetItem(""); if (cs) csItem->setCheckState(Qt::Checked); else csItem->setCheckState(Qt::Unchecked); csItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *enableItem = new QTableWidgetItem(""); if (enable) enableItem->setCheckState(Qt::Checked); else enableItem->setCheckState(Qt::Unchecked); enableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *chanNameItem = new QTableWidgetItem(chanName); auto *senderItem = new QTableWidgetItem(sender); setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem); int lastRow = ui.ignoredTable->rowCount() - 1; ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::RegExColumn, regexItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::CsColumn, csItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::EnableColumn, enableItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::SenderColumn, senderItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::ChanColumn, chanNameItem); if (!self) ui.ignoredTable->setCurrentItem(nameItem); ignoredList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, true, sender, chanName); }
void ReadUncompressed::handleRx(const message_ptr message) { if (!m_initialized) { m_initialized = check(); if (!m_initialized) m_error = true; } else { if (message->get_opcode() == websocketpp::frame::opcode::binary) { const std::string& bytes(message->get_payload()); const std::size_t rawNumBytes(bytes.size()); const std::size_t stride(m_layout->pointSize()); m_data.insert(m_data.end(), bytes.begin(), bytes.end()); const std::size_t wholePoints(m_data.size() / stride); PointId nextId(m_view->size()); const PointId doneId(nextId + wholePoints); const char* pos(m_data.data()); while (nextId < doneId) { for (const auto& dim : m_layout->dims()) { m_view->setField( dim, m_layout->dimType(dim), nextId, pos); pos += m_layout->dimSize(dim); } ++nextId; } m_numBytesReceived += rawNumBytes; m_data.assign( m_data.begin() + wholePoints * stride, m_data.end()); } else { m_error = true; } } }
bool NewElementWizard::validateCurrentPage() noexcept { if (currentPage() && (!currentPage()->validatePage())) { return false; } if (nextId() == NewElementWizardContext::ID_None) { // last page --> create the library element! try { mContext->createLibraryElement(); // can throw } catch (const Exception& e) { QMessageBox::critical(this, tr("Failed to create element"), e.getMsg()); return false; } } return true; }
void testPolyhOut() { struct polyhedron *ph; AllocVar(ph); ph->id = nextId(); ph->names[0] = cloneString("Jim"); ph->names[1] = cloneString("Kent"); ph->polygonCount = 2; slAddTail(&ph->polygons, makeTriangle(0, 0, 0)); slAddTail(&ph->polygons, makeTriangle(0, 0, 100)); findBox(ph); polyhedronCommaOut(ph, stdout); printf("\n"); polyhedronFree(&ph); }
const QString CompoundObjectDescriptor::storeExpression(OOModel::Expression* object) { int id; if (storedExpressions().values().contains(object)) id = storedExpressions().key(object); else { id = nextId(); storedExpressions().insert(id,object); } auto str = compoundSignature(); str.replace(" expr ", QString::number(id)); return str; }
int DatabaseManager::insertRenter(const QVariant& name, const QVariant& phone) { int renterId = -1; if (db.isOpen()) { QSqlQuery query; bool ret = query.prepare("INSERT INTO renter (id, name, phone, popular) " "VALUES (:id, :name, :phone, :popular)"); if (ret) { renterId = nextId(); query.bindValue(":id", renterId); query.bindValue(":name", name); query.bindValue(":phone", phone); query.bindValue(":popular", false); query.exec(); } } return renterId; }
void Wizard::next() { if (currentPageIsComplete() && validateCurrentPage()) { updateButtonState(); int nId = nextId(); if ((nId == -1) && (m_currentId < m_pages.size())) { setCurrentPage(m_currentId + 1); } if (nId > -1 && nId < m_pages.size()) { setCurrentPage(nId); } } }
void DatabaseManager::insertRent(const int year, const int month, const int day, const int rentBlock, const int rentItemId, const int renterId) { QDate date; date.setDate(year,month,day); if (db.isOpen()) { Rent* rent = new Rent(); rent->m_id = nextId(); rent->m_rentBlockIndex = rentBlock; rent->m_itemId = rentItemId; rent->m_renterId = renterId; rent->m_date = date.toJulianDay(); QSqlQuery query; query.exec(QString("insert into rent values(%1,%2,'%3',%4,%5)").arg(rent->m_id).arg(rent->m_rentBlockIndex).arg( rent->m_itemId).arg(rent->m_renterId).arg(rent->m_date)); delete rent; } }
void KGameChat::setFromPlayer(KPlayer* p) { if (!p) { qCCritical(GAMES_PRIVATE_KGAME) << ": NULL player"; removeSendingEntry(d->mToMyGroup); d->mFromPlayer = 0; return; } if (d->mFromPlayer) { changeSendingEntry(p->group(), d->mToMyGroup); } else { if (d->mToMyGroup != -1) { qCWarning(GAMES_PRIVATE_KGAME) << "send to my group exists already - removing"; removeSendingEntry(d->mToMyGroup); } d->mToMyGroup = nextId(); addSendingEntry(i18n("Send to My Group (\"%1\")", p->group()), d->mToMyGroup); } d->mFromPlayer = p; qCDebug(GAMES_PRIVATE_KGAME) << "player=" << p; }
point_count_t GreyhoundReader::setPoints( PointBuffer& pointBuffer, const char* data, const point_count_t pointsToRead) const { PointId nextId(pointBuffer.size()); std::size_t dataOffset(0); point_count_t numRead(0); while (numRead < pointsToRead) { for (auto dim : m_dimData) { pointBuffer.setField(dim.id, dim.type, nextId, data + dataOffset); dataOffset += Dimension::size(dim.type); } ++nextId; ++numRead; } return numRead; }
int main(int argC, char** argV) { boost::program_options::options_description desc("Allowed options"); bool debug = false; std::string input_file1, input_file2, output_file; std::string db_host, db_user, db_passw; std::string src1_db_name, src1_db_user, src1_db_passw; std::string src2_db_name, src2_db_user, src2_db_passw; std::string targetDb_name, targetDb_user, targetDb_passw; int db_port; desc.add_options() ("help,h", "produce help message") ("debug,d", "generate debug output") ("db-host,H", boost::program_options::value< std::string >(&db_host)->default_value("localhost"), "host of the database server") #ifdef ODB_MYSQL ("src1-db-name,M", boost::program_options::value< std::string >(&src1_db_name), "name of the first UniPAX source database") ("src2-db-name,N", boost::program_options::value< std::string >(&src2_db_name), "name of the second UniPAX source database") ("target-db-name,T", boost::program_options::value< std::string >(&targetDb_name), "name of the UniPAX target database") ("db-user,U", boost::program_options::value< std::string >(&db_user)->default_value("unipax"), "user name for the connection to the UniPAX database") ("db-passw,p", boost::program_options::value< std::string >(&db_passw)->default_value("unipax"), "password of the UniPAX database") ("db-port,P", boost::program_options::value< int >(&db_port)->default_value(3306), "port of the database server") #elif defined ODB_ORACLE ("src1-db-name,s1N", boost::program_options::value< std::string >(&src1_db_name), "SID of the first UniPAX source database") ("src1-db-user,s1U", boost::program_options::value< std::string >(&src1_db_user)->default_value("unipax"), "user name of the first UniPAX source database") ("src1-db-passw,s1P", boost::program_options::value< std::string >(&src1_db_passw)->default_value("unipax"), "password of the first UniPAX source database") ("src2-db-name,s2N", boost::program_options::value< std::string >(&src2_db_name), "SID of the second UniPAX source database") ("src2-db-user,s2U", boost::program_options::value< std::string >(&src2_db_user)->default_value("unipax"), "user name of the second UniPAX source database") ("src2-db-passw,s2P", boost::program_options::value< std::string >(&src2_db_passw)->default_value("unipax"), "password of the second UniPAX source database") ("target-db-name,tN", boost::program_options::value< std::string >(&targetDb_name), "name of the UniPAX target database") ("target-db-user,tU", boost::program_options::value< std::string >(&targetDb_user)->default_value("unipax"), "user name of the UniPAX target database") ("target-db-passw,tP", boost::program_options::value< std::string >(&targetDb_passw)->default_value("unipax"), "password of the UniPAX target database") ("db-port,P", boost::program_options::value< int >(&db_port)->default_value(1521), "port of the database server") #endif ("input-file1,i", boost::program_options::value< std::string >(&input_file1), "first input file") ("input-file2,j", boost::program_options::value< std::string >(&input_file2), "second input file") ("file-output,o", boost::program_options::value< std::string >(&output_file), "use file-output instead of target database") ; boost::program_options::positional_options_description pod; pod.add("output-file", -1); // for output boost::program_options::variables_map vm; boost::program_options::store(boost::program_options::command_line_parser(argC, argV).options(desc).positional(pod).run(), vm); boost::program_options::notify(vm); if (argC == 1 || vm.count("help")) { std::cout << desc << std::endl; return 0; } if (vm.count("debug")) { debug = true; } // if (targetDb_name.empty() == output_file.empty()) // { // std::cerr << "Please specify either at target database (-T name) or an outfile (-o name)." << std::endl; // return 0; // } // if ((input_file1.empty() != input_file2.empty()) || (src1_db_name.empty() != src2_db_name.empty()) // || (input_file1.empty() == src1_db_name.empty())) // { // std::cerr << "Please specify either input files (-i first -j second) or input databases (-M first -N second)." << std::endl; // return 0; // } // if ((src1_db_name.empty() || !targetDb_name.empty()) && db_passw.empty()) // { // std::cout << "Enter password for database access: "; // std::cin >> db_passw; // } UniPAX::MergerInputAdapter source1, source2; if (!src1_db_name.empty()) { if (debug) std::cout << "input mode: db" << std::endl; // setup src DB connections #ifdef ODB_MYSQL UniPAX::mysql::MySQLManager src1_db, src2_db; src1_db.setDBCredentials(db_user, db_passw, db_host, db_port, src1_db_name); source1 = UniPAX::MergerInputAdapter(src1_db); src2_db.setDBCredentials(db_user, db_passw, db_host, db_port, src2_db_name); source2 = UniPAX::MergerInputAdapter(src2_db); #elif defined ODB_ORACLE UniPAX::oracle::OracleManager src1_db, src2_db; src1_db.setDBCredentials(src1_db_user, src1_db_passw, db_host, db_port, src1_db_name); source1 = UniPAX::MergerInputAdapter(src1_db); src2_db.setDBCredentials(src2_db_user, src2_db_passw, db_host, db_port, src2_db_name); source2 = UniPAX::MergerInputAdapter(src2_db); #endif } else { if (debug) std::cout << "Input mode: file" << std::endl; // read infiles if (debug) std::cout << "Reading file " << input_file1 << std::endl; UniPAX::BIOPAXReader reader1(input_file1); reader1.setDebug(false); reader1.createObjectsOnly(true); if (!reader1.parse()) return 0; reader1.createObjectsOnly(false); if (!reader1.parse()) return 0; if (debug) std::cout << "done!" << std::endl; source1 = UniPAX::MergerInputAdapter(UnipaxPtr<UniPAX::PersistenceManager>::type(new UniPAX::PersistenceManager(reader1.getPersistenceManager()))); if (debug) std::cout << "Reading file " << input_file2 << std::endl; UniPAX::BIOPAXReader reader2(input_file2); reader2.setDebug(false); reader2.createObjectsOnly(true); if (!reader2.parse()) return 0; reader2.createObjectsOnly(false); if (!reader2.parse()) return 0; if (debug) std::cout << "done!\n" << std::endl; source2 = UniPAX::MergerInputAdapter(UnipaxPtr<UniPAX::PersistenceManager>::type(new UniPAX::PersistenceManager(reader2.getPersistenceManager()))); } source1.setIdGenFunction(&nextId); source2.setIdGenFunction(&nextId); UniPAX::KernelCollector result; std::vector<boost::shared_ptr<UniPAX::UPBase> > _first, _second; if (!(source1.getObjectsByType(_first, "Xref", true) && source2.getObjectsByType(_second, "Xref", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Xref objects:" << std::endl; if (!mergeXrefs(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Xref objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; //result.updateAll(); _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "BioSource", false) && source2.getObjectsByType(_second, "BioSource", false))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " BioSource objects: "<< std::endl; if (!mergeBioSources(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "BioSource objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Provenance", false) && source2.getObjectsByType(_second, "Provenance", false))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Provenance objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::Provenance>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Provenance objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Evidence", false) && source2.getObjectsByType(_second, "Evidence", false))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Evidence objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::Evidence>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Evidence objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "EntityReference", false) && source2.getObjectsByType(_second, "EntityReference", false))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " EntityReference objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::EntityReference>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "EntityReference objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); // Entity objects: if (!(source1.getObjectsByType(_first, "Gene", true) && source2.getObjectsByType(_second, "Gene", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Gene objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::Gene>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Gene objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Dna", true) && source2.getObjectsByType(_second, "Dna", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Dna objects: "<< std::endl; if (!mergeEntitiesByRef<UniPAX::Dna>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Dna objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "DnaRegion", true) && source2.getObjectsByType(_second, "DnaRegion", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " DnaRegion objects: "<< std::endl; if (!mergeEntitiesByRef<UniPAX::DnaRegion>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "DnaRegion objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Protein", true) && source2.getObjectsByType(_second, "Protein", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Protein objects: "<< std::endl; if (!mergeEntitiesByRef<UniPAX::Protein>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Protein objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Rna", true) && source2.getObjectsByType(_second, "Rna", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Rna objects: "<< std::endl; if (!mergeEntitiesByRef<UniPAX::Rna>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Rna objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "RnaRegion", true) && source2.getObjectsByType(_second, "RnaRegion", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " RnaRegion objects: "<< std::endl; if (!mergeEntitiesByRef<UniPAX::RnaRegion>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "RnaRegion objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "SmallMolecule", true) && source2.getObjectsByType(_second, "SmallMolecule", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " SmallMolecule objects: "<< std::endl; if (!mergeEntitiesByRef<UniPAX::SmallMolecule>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "SmallMolecule objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Complex", true) && source2.getObjectsByType(_second, "Complex", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Complex objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::Complex>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Complex objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); // Add remaining UtilityClass objects... if (!(source1.getObjectsByType(_first, "UtilityClass", true) && source2.getObjectsByType(_second, "UtilityClass", true))) { return 0; } if (debug) std::cout << "Adding " << _first.size() << " with " << _second.size() << " UtilityClass objects: "<< std::endl; for (std::vector<UniPAX::UPBasePtr>::iterator it = _first.begin(); it != _first.end(); ++it) { if (debug) std::cout << (*it)->getType() << " object found..." << std::endl; if (!result.isMerged(*it)) { if (debug) std::cout << "... and not yet merged." << std::endl; //if (!(*it)->update(result)) return 0; if ((*it)->getTypeID() == UniPAX::ClassType::idStoichiometry) { UniPAX::StoichiometryPtr stoi = boost::dynamic_pointer_cast<UniPAX::Stoichiometry>(*it); if (debug) std::cout << "before copy " << (stoi->getPhysicalEntity() != 0) << std::endl; if (!stoi->update(result)) return 0; if (debug) std::cout << "before copy after update " << (stoi->getPhysicalEntity() != 0) << std::endl; } UniPAX::UPBasePtr object = (*it)->dynamic_copy(); object->setUnipaxId(nextId()); if (!object->update(result)) return 0; if (object->getTypeID() == UniPAX::ClassType::idStoichiometry) { UniPAX::StoichiometryPtr stoi = boost::dynamic_pointer_cast<UniPAX::Stoichiometry>(object); if (debug) std::cout << "after copy " << (stoi->getPhysicalEntity() != 0) << std::endl; if (!stoi->update(result)) return 0; if (debug) std::cout << "before copy after update " << (stoi->getPhysicalEntity() != 0) << std::endl; } if (!result.collect(object)) return 0; result.addMerge(*it, object); } } for (std::vector<UniPAX::UPBasePtr>::iterator it = _second.begin(); it != _second.end(); ++it) { if (debug) std::cout << (*it)->getType() << " object found..." << std::endl; if (!result.isMerged(*it)) { if (debug) std::cout << "... and not yet merged." << std::endl; //if (!(*it)->update(result)) return 0; UniPAX::UPBasePtr object = (*it)->dynamic_copy(); object->setUnipaxId(nextId()); if (!object->update(result)) return 0; if (!result.collect(object)) return 0; result.addMerge(*it, object); } } if (debug) std::cout << "UtilityClass objects added.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Interaction", true) && source2.getObjectsByType(_second, "Interaction", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Interaction objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::Interaction>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Interaction objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (!(source1.getObjectsByType(_first, "Pathway", true) && source2.getObjectsByType(_second, "Pathway", true))) { return 0; } if (debug) std::cout << "Merging " << _first.size() << " with " << _second.size() << " Pathway objects: "<< std::endl; if (!mergeInstancesOf<UniPAX::Pathway>(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Pathway objects merged.\n" << std::endl; if (debug) std::cout << "Number of merged objects: " << result.getInstanceCount() << std::endl; _first.clear(); _second.clear(); if (debug) std::cout << result.isMerged(result.getInstance("175", "")) << std::endl; //result.updateAll(); // \Entity objects /*if (debug) std::cout << "Merging BioSource objects:" << std::endl; if (!mergeXrefs(result, _first, _second, debug)) { return 0; } if (debug) std::cout << "Xref objects merged." << std::endl;*/ //UniPAX::PersistenceManager target; /*UniPAX::mysql::MySQLManager targetDb; if (!targetDb_name.empty()) { targetDb.setDBCredentials(db_user, db_passw, db_host, db_port, targetDb_name);; }*/ // load all ids from dbs to merge /*std::vector<UnipaxId> ids1, ids2; if (!src1_db.getIdsByType(ids1, "UPBase", true)) { std::cerr << "Could not retrieve ids from database " << src1_db_name << ". Aborting merge." << std::endl; return 0; } if (!src2_db.getIdsByType(ids2, "UPBase", true)) { std::cerr << "Could not retrieve ids from database " << src2_db_name << ". Aborting merge." << std::endl; return 0; } UniPAX::KernelCollector src1_manager, src2_manager;*/ // merge UtilityClass subtypes /*{ std::vector<boost::shared_ptr<UniPAX::Xref> > all_xrefs1, all_xrefs2; if (!src1_manager.getObjectsByType(all_xrefs1, "Xref", true)) { std::cerr << "Could not retrieve Xref object pointers from database " << src1_db_name << ". Aborting merge." << std::endl; return 0; } if (!src2_manager.getObjectsByType(all_xrefs2, "Xref", true)) { std::cerr << "Could not retrieve Xref object pointers from database " << src2_db_name << ". Aborting merge." << std::endl; return 0; } } // merge BioSource objects { std::vector<boost::shared_ptr<UniPAX::BioSource> > all_biosources1, all_biosources2; if (!src1_manager.getObjectsByType(all_biosources1, "BioSource", true)) { std::cerr << "Could not retrieve BioSource object from database " << src1_db_name << ". Aborting merge." << std::endl; return 0; } if (!src1_manager.getObjectsByType(all_biosources2, "BioSource", true)) { std::cerr << "Could not retrieve BioSource object from database " << src2_db_name << ". Aborting merge." << std::endl; return 0; } for (std::vector<boost::shared_ptr<UniPAX::BioSource> >::const_iterator it = all_biosources1.begin(); it != all_biosources1.end(); it++) { if () } }*/ /*for (std::vector<UnipaxId>::const_iterator it = ids1.begin(); it != ids1.end(); it++) { }*/ UniPAX::BIOPAXWriter writer; // for output /*boost::shared_ptr<UniPAX::ProteinReference> first = boost::dynamic_pointer_cast<UniPAX::ProteinReference>(db.getObjectByID(705070265)); boost::shared_ptr<UniPAX::ProteinReference> second = boost::dynamic_pointer_cast<UniPAX::ProteinReference>(db.getObjectByID(705076958)); boost::shared_ptr<UniPAX::BioSource> first_org = boost::dynamic_pointer_cast<UniPAX::BioSource>(db.getObjectByID(16777233)); boost::shared_ptr<UniPAX::BioSource> second_org = boost::dynamic_pointer_cast<UniPAX::BioSource>(db.getObjectByID(16777218)); manager.collect(first); manager.collect(second); writer.setPersistenceManager(manager); writer.write(output_file); UniPAX::KernelCollector manager2; // make a copy of first object std::cout << first_org.get()->getUnipaxId() << std::endl; UniPAX::BioSource tmp_org(*first_org); boost::shared_ptr<UniPAX::BioSource> third_org = boost::shared_ptr<UniPAX::BioSource>(&tmp_org); // merge second object into new object if (third_org->merge(*second_org)) { manager2.collect(third_org); manager2.addMerge(second_org, third_org); } std::cout << "davor" << std::endl; first->update(manager2); std::cout << "mitte" << std::endl; second->update(manager2); std::cout << "danach" << std::endl; // make a copy of first object UniPAX::ProteinReference* tmp = new UniPAX::ProteinReference(*first); boost::shared_ptr<UniPAX::ProteinReference> third(tmp); // merge second object into new object if (third->merge(*second)) { manager2.collect(third); manager2.addMerge(second, third); } // UniPAX::MySQLManager db2; // db2.setDBCredentials(db_user, db_passw, db_host, db_port, "unipax2"); // db2.persist(manager2); // // assign new unipaxId by force // db2.assignIds(manager2, true);*/ writer.setDebug(false); if (true) std::cout << "Writing " << result.getInstanceCount() << " objects to file." << std::endl; writer.setPersistenceManager(result); writer.write(output_file); return 0; }
bool mergeBioSources(UniPAX::KernelCollector& merged, std::vector<boost::shared_ptr<UniPAX::UPBase> > all_biosources1, std::vector<boost::shared_ptr<UniPAX::UPBase> > all_biosources2, bool debug) { // fill a multimap with (UnificationXref.id -> BioSource*) pairs from the second data source std::multimap<std::string, boost::shared_ptr<UniPAX::BioSource> > uxrefid_biosource2_map; std::set<UniPAX::BioSourcePtr> src2_remainder; for (std::vector<boost::shared_ptr<UniPAX::UPBase> >::iterator it = all_biosources2.begin(); it != all_biosources2.end(); it++) { boost::shared_ptr<UniPAX::BioSource> biosource2 = boost::dynamic_pointer_cast<UniPAX::BioSource>(*it); for (std::vector<boost::shared_ptr<UniPAX::Xref> >::const_iterator xit = biosource2->getXrefs().begin(); xit != biosource2->getXrefs().end(); ++xit) { if ((*xit)->getType().compare("UnificationXref") == 0) { uxrefid_biosource2_map.insert(std::pair<std::string, boost::shared_ptr<UniPAX::BioSource> >((*xit)->getId(), biosource2)); src2_remainder.insert(biosource2); } } } // search for matches between Biosource objects for (std::vector<boost::shared_ptr<UniPAX::UPBase> >::iterator it = all_biosources1.begin(); it != all_biosources1.end(); it++) { boost::shared_ptr<UniPAX::BioSource> biosource3 = boost::dynamic_pointer_cast<UniPAX::BioSource>((*it)->dynamic_copy()); biosource3->setUnipaxId(nextId()); biosource3->update(merged); if (debug) std::cout << "Copying BioSource object with displayName: " << biosource3->getDisplayName() << ".\nSetting id to " << biosource3->getUnipaxId() << "." << std::endl; bool found = false; std::vector<boost::shared_ptr<UniPAX::Xref> >::const_iterator xit = biosource3->getXrefs().begin(); if (debug) std::cout << "Searching for matching UnificationXref:" << std::endl; while (!found && xit != biosource3->getXrefs().end()) { if ((*xit)->getType().compare("UnificationXref") == 0) { std::multimap<std::string, boost::shared_ptr<UniPAX::BioSource> >::iterator match = uxrefid_biosource2_map.find((*xit)->getId()); if (match != uxrefid_biosource2_map.end()) { if (debug) std::cout << "Found matching UnificationXref." << std::endl; found = true; boost::shared_ptr<UniPAX::BioSource> biosource2 = match->second; biosource2->update(merged); if (biosource3->merge(*biosource2)) { if (debug) std::cout << "Successfully merged." << std::endl; // remove merged objects //uxrefid_biosource2_map.erase(match); src2_remainder.erase(match->second); merged.collect(biosource3); merged.addMerge(biosource2, biosource3); merged.addMerge(*it, biosource3); } else { if (debug) std::cout << "Merge unsuccessful." << std::endl; } } } xit++; } if (debug && !found) std::cout << "No match found." << std::endl; if (!found) { merged.collect(biosource3); merged.addMerge(*it, biosource3); } } // add remaining objects from source2 for (std::set<UniPAX::BioSourcePtr>::const_iterator it = src2_remainder.begin(); it != src2_remainder.end(); ++it) { boost::shared_ptr<UniPAX::BioSource> biosource3 = boost::dynamic_pointer_cast<UniPAX::BioSource>((*it)->dynamic_copy()); if (debug) std::cout << "Copying remaining BioSource object. Setting id to " << biosource3->getUnipaxId() << "." << std::endl; biosource3->setUnipaxId(nextId()); biosource3->update(merged); merged.collect(biosource3); merged.addMerge(*it, biosource3); } return true; }
bool mergeXrefs(UniPAX::KernelCollector& merged, std::vector<boost::shared_ptr<UniPAX::UPBase> > all_xrefs1, std::vector<boost::shared_ptr<UniPAX::UPBase> > all_xrefs2, bool debug) { // merge Xref objects: // UnificationXref objects are important to be merged first // for serving the identity mapping in data integration std::multimap<std::string, boost::shared_ptr<UniPAX::Xref> > remainder; for (std::vector<boost::shared_ptr<UniPAX::UPBase> >::iterator it = all_xrefs2.begin(); it != all_xrefs2.end(); it++) { boost::shared_ptr<UniPAX::Xref> tmp = boost::dynamic_pointer_cast<UniPAX::Xref>(*it); if (tmp->getId().empty()) { std::cerr << "Empty Id field in " << tmp->getType() << " object." << std::endl; } else { remainder.insert(std::pair<std::string, boost::shared_ptr<UniPAX::Xref> >(tmp->getId(), tmp)); } } //std::list<boost::shared_ptr<UniPAX::UPBase> > remainder(all_xrefs2.begin(), all_xrefs2.end()); for (std::vector<boost::shared_ptr<UniPAX::UPBase> >::const_iterator it = all_xrefs1.begin(); it != all_xrefs1.end(); it++) { boost::shared_ptr<UniPAX::Xref> it_xref = boost::dynamic_pointer_cast<UniPAX::Xref>(*it); if (debug) std::cout << "Copying "<< it_xref->getType() << " object " << it_xref->getDb() << ":" << it_xref->getId() << " with unpaxId:" << it_xref->getUnipaxId() << std::endl; // make a copy boost::shared_ptr<UniPAX::UPBase> result = it_xref->dynamic_copy(); result->setUnipaxId(nextId()); if (debug) std::cout << "Setting unipaxId to " << result->getUnipaxId() << std::endl; // search for identical object in remainder std::multimap<std::string, boost::shared_ptr<UniPAX::Xref> >::iterator found = remainder.find(it_xref->getId()); if (found != remainder.end()) { boost::shared_ptr<UniPAX::Xref> del_xref = found->second; if (!it_xref->getDb().empty() && !del_xref->getDb().empty() && !it_xref->getId().empty() && !del_xref->getId().empty()) { if (debug) std::cout << "Trying to merge " << it_xref->getType() << " objects." << std::endl; if (debug) std::cout << it_xref->getDb() << ":" << it_xref->getId() << " and " << del_xref->getDb() << ":" << del_xref->getId() << std::endl; if (!result->merge(*del_xref)) { // some fields may have different values? if (debug) std::cout << "Adding two separate objects." << std::endl; } else { if (debug) std::cout << "Objects successfully merged." << std::endl; // remove identical object remainder.erase(found); } merged.collect(result); merged.addMerge(del_xref ,result); merged.addMerge(*it, result); } } else { merged.collect(result); merged.addMerge(*it ,result); } if (debug) std::cout << "Number of merged objects: " << merged.getInstanceCount() << std::endl; result->update(merged); } // add all remaining Xref objects from remainder for (std::multimap<std::string, boost::shared_ptr<UniPAX::Xref> >::const_iterator it = remainder.begin() ; it != remainder.end(); it++) { if (debug) std::cout << "Copying "<< it->second->getType() << " object " << it->second->getDb() << ":" << it->second->getId() << " with unpaxId:" << it->second->getUnipaxId() << std::endl; // make a copy boost::shared_ptr<UniPAX::UPBase> result = it->second->dynamic_copy(); result->setUnipaxId(nextId()); result->update(merged); if (debug) std::cout << "Setting unipaxId to " << result->getUnipaxId() << std::endl; merged.collect(result); merged.addMerge(it->second, result); } return true; }
bool mergeInstancesOf(UniPAX::KernelCollector& merged, const std::vector<boost::shared_ptr<UniPAX::UPBase> > source_vec1, const std::vector<boost::shared_ptr<UniPAX::UPBase> > source_vec2, bool debug) { // fill a multimap with (UnificationXref.id -> T*) pairs from the second data source std::multimap<std::string, boost::shared_ptr<T> > uxrefid_source2_map; std::set<boost::shared_ptr<T> > src2_remainder; for (std::vector<boost::shared_ptr<UniPAX::UPBase> >::const_iterator it = source_vec2.begin(); it != source_vec2.end(); ++it) { boost::shared_ptr<T> instance2 = boost::dynamic_pointer_cast<T>(*it); //for (std::vector<boost::shared_ptr<UniPAX::Xref> >::const_iterator xit = instance2->getXrefs().begin(); xit != instance2->getXrefs().end(); ++xit) for (std::vector<boost::shared_ptr<UniPAX::Xref> >::const_iterator xit = instance2->getXrefs().begin(); xit != instance2->getXrefs().end(); ++xit) { if ((*xit)->getType().compare("UnificationXref") == 0) { uxrefid_source2_map.insert(std::pair<std::string, boost::shared_ptr<T> >((*xit)->getId(), instance2)); src2_remainder.insert(instance2); } } } // search for matches between T objects std::map<UnipaxId, UniPAX::UPBasePtr> uxrefs_handled; for (std::vector<boost::shared_ptr<UniPAX::UPBase> >::const_iterator it = source_vec1.begin(); it != source_vec1.end(); it++) { boost::shared_ptr<T> instance3 = boost::dynamic_pointer_cast<T>((*it)->dynamic_copy()); instance3->setUnipaxId(nextId()); instance3->update(merged); if (debug) std::cout << "Copying instance of type " << instance3->getType() << ".\nSetting id to " << instance3->getUnipaxId() << "." << std::endl; bool found = false; if (debug) std::cout << "Searching for matching UnificationXref:" << std::endl; std::vector<boost::shared_ptr<UniPAX::Xref> >::const_iterator xit = instance3->getXrefs().begin(); while (!found && xit != instance3->getXrefs().end()) { if ((*xit)->getType().compare("UnificationXref") == 0) { std::map<UnipaxId, UniPAX::UPBasePtr>::iterator xref_found = uxrefs_handled.find((*xit)->getUnipaxId()); if (xref_found != uxrefs_handled.end()) // identical object has already been handled -> doublet in source_vec1 { if (debug) std::cout << "Identical object has already been handled. Doublet in source_vec1." << std::endl; merged.addMerge(*it, xref_found->second); // dummy addMerge to set it as merged found = true; break; } else { uxrefs_handled.insert(std::pair<UnipaxId, UniPAX::UPBasePtr>((*xit)->getUnipaxId(), instance3)); } typedef typename std::multimap<std::string, boost::shared_ptr<T> >::iterator mapIter; std::pair<mapIter, mapIter> range = uxrefid_source2_map.equal_range((*xit)->getId()); if (range.first != range.second) { mapIter match = range.first; if (debug) std::cout << "Found matching UnificationXref." << std::endl; found = true; boost::shared_ptr<T> instance2 = match->second; instance2->update(merged); if (instance3->merge(*instance2)) { if (debug) std::cout << "Successfully merged." << std::endl; src2_remainder.erase(match->second); merged.collect(instance3); merged.addMerge(instance2, instance3); merged.addMerge(*it, instance3); } else { if (debug) std::cout << "Merge unsuccessful." << std::endl; return false; } // for doublets in source2 match++; while (match != range.second) { if (debug) std::cout << "Identical object has already been handled. Doublet in source_vec2." << std::endl; instance2 = match->second; merged.addMerge(instance2, instance3); match++; } } } xit++; } if (debug && !found) std::cout << "No match found." << std::endl; if (!found) { merged.collect(instance3); merged.addMerge(*it, instance3); } } // add remaining objects from source2 for (typename std::set<boost::shared_ptr<T> >::iterator it = src2_remainder.begin(); it != src2_remainder.end(); ++it) { if (debug) std::cout << "Copying remaining " << (*it)->getType() << " object." << std::endl; boost::shared_ptr<T> instance3 = boost::dynamic_pointer_cast<T>((*it)->dynamic_copy()); instance3->setUnipaxId(nextId()); instance3->update(merged); if (debug) std::cout << "Setting id to " << instance3->getUnipaxId() << "." << std::endl; merged.collect(instance3); merged.addMerge((*it), instance3); } return true; }
bool mergeEntitiesByRef(UniPAX::KernelCollector& merged, const std::vector<boost::shared_ptr<UniPAX::UPBase> > source_vec1, const std::vector<boost::shared_ptr<UniPAX::UPBase> > source_vec2, bool debug) { // follow the merged EntityRefs to see, if two objects may be equal. // fill a multimap with (merged EntityRef.UnipaxId -> referenced Entity from the second data source) std::multimap<UnipaxId, boost::shared_ptr<T> > eref_uid_source2_map; //std::multimap<UniPAX::EntityReferencePtr, boost::shared_ptr<T> > eref_uid_source2_map; std::set<boost::shared_ptr<T> > src2_remainder; for (std::vector<UniPAX::UPBasePtr>::const_iterator it = source_vec2.begin(); it != source_vec2.end(); ++it) { boost::shared_ptr<T> entity2 = boost::dynamic_pointer_cast<T>(*it); //entity2->update(merged); for (std::vector<UniPAX::EntityReferencePtr>::const_iterator er_it = entity2->getEntityReferences().begin(); er_it != entity2->getEntityReferences().end(); ++er_it) { if (merged.isMerged(*er_it)) { //(*er_it)->update(merged); // maybe like this? //eref_uid_source2_map.insert(std::pair<UnipaxId, typename UnipaxPtr<T>::type>((*er_it)->getUnipaxId(), entity2)); eref_uid_source2_map.insert(std::pair<UnipaxId, typename UnipaxPtr<T>::type>(merged.getMergedObject(*er_it)->getUnipaxId(), entity2)); //eref_uid_source2_map.insert(std::pair<UniPAX::EntityReferencePtr, typename UnipaxPtr<T>::type>(merged.getMergedObject(*er_it), entity2)); src2_remainder.insert(entity2); } } } //search for matches between Entity objects std::map<UnipaxId, UniPAX::UPBasePtr> refs_handled; for (std::vector<UniPAX::UPBasePtr>::const_iterator it = source_vec1.begin(); it != source_vec1.end(); ++it) { boost::shared_ptr<T> entity3 = boost::dynamic_pointer_cast<T>((*it)->dynamic_copy()); entity3->setUnipaxId(nextId()); entity3->update(merged); if (debug) std::cout << "Copying instance of type " << entity3->getType() << ".\nSetting id to " << entity3->getUnipaxId() << "." << std::endl; bool found = false; if (debug) std::cout << "Searching for matching EntityReference:" << std::endl; std::vector<UniPAX::EntityReferencePtr>::const_iterator er_it = entity3->getEntityReferences().begin(); while (!found && er_it != entity3->getEntityReferences().end()) { std::map<UnipaxId, UniPAX::UPBasePtr>::iterator ref_found = refs_handled.find((*er_it)->getUnipaxId()); if (ref_found != refs_handled.end()) // identical object has already been handled -> doublet in source_vec1 { if (debug) std::cout << "Identical object has already been handled. Doublet in source_vec1." << std::endl; merged.addMerge(*it, ref_found->second); // dummy addMerge to set it as merged found = true; break; } else { refs_handled.insert(std::pair<UnipaxId, UniPAX::UPBasePtr>((*er_it)->getUnipaxId(), entity3)); } typedef typename std::multimap<UnipaxId, boost::shared_ptr<T> >::iterator mapIter; std::pair<mapIter, mapIter> range = eref_uid_source2_map.equal_range((*er_it)->getUnipaxId()); if (range.first != range.second) { mapIter match = range.first; if (debug) std::cout << "Found matching EntityReference." << std::endl; found = true; boost::shared_ptr<T> entity2 = match->second; entity2->update(merged); if (entity3->merge(*entity2)) { if (debug) std::cout << "Successfully merged." << std::endl; src2_remainder.erase(match->second); merged.collect(entity3); merged.addMerge(entity2, entity3); merged.addMerge(*it, entity3); } else { if (debug) std::cout << "Merge unsuccessful." << std::endl; return false; } // for doublets in source2 match++; while (match != range.second) { if (debug) std::cout << "Identical object has already been handled. Doublet in source_vec2." << std::endl; entity2 = match->second; merged.addMerge(entity2, entity3); match++; } } // if (merged.isMerged(*er_it)) // { // UnipaxId uid = merged.getMergedObject(*er_it)->getUnipaxId(); // //UniPAX::EntityReferencePtr uid = merged.getMergedObject(*er_it); // //typename std::multimap<UniPAX::EntityReferencePtr, boost::shared_ptr<T> >::iterator match = eref_uid_source2_map.find(uid); // typename std::multimap<UnipaxId, boost::shared_ptr<T> >::iterator match = eref_uid_source2_map.find(uid); // if (match != eref_uid_source2_map.end()) // { // if (debug) std::cout << "Found matching EntityReference." << std::endl; // found = true; // boost::shared_ptr<T> entity2 = match->second; // entity2->update(merged); // if (entity3->merge(*entity2)) // { // if (debug) std::cout << "Successfully merged." << std::endl; // // remove merged objects from map // //eref_uid_source2_map.erase(match); // src2_remainder.erase(match->second); // entity3->update(merged); // merged.collect(entity3); // merged.addMerge(entity2, entity3); // merged.addMerge(*it, entity3); // } // else // { // if (debug) std::cout << "Merge unsuccessful." << std::endl; // return false; // } // } // } er_it++; } if (debug && !found) std::cout << "No match found." << std::endl; if (!found) { // add remaining objects from source1 //entity3->update(merged); merged.collect(entity3); merged.addMerge(*it, entity3); } } // add remaining objects from source2 for (typename std::set<boost::shared_ptr<T> >::iterator it = src2_remainder.begin(); it != src2_remainder.end(); ++it) { if (debug) std::cout << "Copying remaining " << (*it)->getType() << " object." << std::endl; boost::shared_ptr<T> entity3 = boost::dynamic_pointer_cast<T>((*it)->dynamic_copy()); entity3->setUnipaxId(nextId()); entity3->update(merged); if (debug) std::cout << "Setting id to " << entity3->getUnipaxId() << "." << std::endl; merged.collect(entity3); merged.addMerge(*it, entity3); } return true; }
void XmppHistoryResponseActor::execute() { qDebug("EXECUTE SignerResponse"); BEGIN_EXECUTE; // Analyze the request { XmppTag* pubsub = m_stanza.child("pubsub"); XmppTag* items = pubsub ? pubsub->child( "items" ) : 0; XmppTag* history = items ? items->child("delta-history") : 0; if ( !history ) { XMPPERROR("Malformed delta-hiistory request"); } // TODO: Inspect the hashes that are being sent bool ok = true; m_start = history->attribute("start-version").toLong(&ok); if ( !ok || m_start < 0) { XMPPERROR("start-version missing"); } m_end = history->attribute("end-version").toLong(&ok); if ( !ok || m_end < 0 ) { XMPPERROR("end-version missing"); } QString waveletName = history->attribute("wavelet-name"); m_url = WaveUrl( waveletName ); if ( m_url.isNull() ) { XMPPERROR("Malformed wavelet-name"); } } // Wait until the connection is ready if ( !connection()->isReady() ) yield( RecvSignal( connection(), SIGNAL(ready())) ); // Send a query to the database asking for the deltas { m_msgId = nextId(); PBMessage<messages::QueryWaveletUpdates>* query = new PBMessage<messages::QueryWaveletUpdates>( ActorId("store", m_url.toString() ), m_msgId ); query->setCreateOnDemand( true ); query->set_wavelet_name(m_url.toString().toStdString() ); query->set_start_version( m_start ); query->set_end_version( m_end ); bool ok = post( query ); if ( !ok ) { XMPPERROR("Internal server error. Could not talk to database."); } } // Wait for a response from the database yield( RecvPB<messages::QueryWaveletUpdatesResponse>(m_msgId) | Timeout(10000) ); if ( REASON(RecvPB<messages::QueryWaveletUpdatesResponse>) ) { if ( !REASON->ok() ) { XMPPERROR("Data base reported an error:" + QString::fromStdString( REASON->error() )); } // Send the requested deltas { QString send; QXmlStreamWriter writer( &send ); writer.writeStartElement("iq"); writer.writeAttribute("type", "result" ); writer.writeAttribute("id", m_stanza.stanzaId() ); writer.writeAttribute("to", connection()->domain() ); writer.writeAttribute("from", Settings::settings()->xmppComponentName() ); writer.writeStartElement("pubsub"); writer.writeAttribute("xmlns", "http://jabber.org/protocol/pubsub" ); writer.writeStartElement("items"); for( i = 0; i < REASON->applied_delta_size(); ++i ) { QByteArray ba = QByteArray::fromRawData( REASON->applied_delta(i).data(), REASON->applied_delta(i).length() ); QString str64 = QString::fromAscii( ba.toBase64() ); writer.writeStartElement("item"); writer.writeStartElement("applied-delta"); writer.writeCDATA( str64 ); writer.writeEndElement(); writer.writeEndElement(); } writer.writeStartElement("item"); writer.writeStartElement("commit-notice"); writer.writeAttribute("xmlns", "http://waveprotocol.org/protocol/0.2/waveserver" ); writer.writeAttribute("version", QString::number(REASON->end_version()) ); writer.writeEndElement(); writer.writeEndElement(); writer.writeStartElement("item"); writer.writeStartElement("history-truncated"); writer.writeAttribute("xmlns", "http://waveprotocol.org/protocol/0.2/waveserver" ); writer.writeAttribute("version", QString::number(REASON->end_version()) ); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); writer.writeEndElement(); connection()->send( send ); } } else { XMPPERROR("Timeout waiting for database"); } END_EXECUTE; }
void CoreHighlightSettingsPage::importRules() { NotificationSettings notificationSettings; const auto localHighlightList = notificationSettings.highlightList(); // Re-use translations of "Legacy/Local Highlights" as this is a word-for-word reference, // forcing all spaces to non-breaking QString localHighlightsName; if (Quassel::runMode() == Quassel::Monolithic) { localHighlightsName = tr("Legacy Highlights").replace(" ", " "); } else { localHighlightsName = tr("Local Highlights").replace(" ", " "); } if (localHighlightList.count() == 0) { // No highlight rules exist to import, do nothing QMessageBox::information(this, tr("No highlights to import"), tr("No highlight rules in <i>%1</i>." ).arg(localHighlightsName)); return; } int ret = QMessageBox::question(this, tr("Import highlights?"), tr("Import all highlight rules from <i>%1</i>?" ).arg(localHighlightsName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No); if (ret != QMessageBox::Yes) { // Only two options, Yes or No, return if not Yes return; } auto clonedManager = HighlightRuleManager(); clonedManager.fromVariantMap(Client::highlightRuleManager()->toVariantMap()); for (const auto &variant : notificationSettings.highlightList()) { auto highlightRule = variant.toMap(); clonedManager.addHighlightRule( clonedManager.nextId(), highlightRule["Name"].toString(), highlightRule["RegEx"].toBool(), highlightRule["CS"].toBool(), highlightRule["Enable"].toBool(), false, "", highlightRule["Channel"].toString() ); } Client::highlightRuleManager()->requestUpdate(clonedManager.toVariantMap()); setChangedState(false); load(); // Give a heads-up that all succeeded QMessageBox::information(this, tr("Imported highlights"), tr("%1 highlight rules successfully imported." ).arg(QString::number(localHighlightList.count()))); }
void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QString &name, bool regex, bool cs, const QString &sender, const QString &chanName, bool self) { ui.ignoredTable->setRowCount(ui.ignoredTable->rowCount() + 1); if (id < 0) { id = nextId(); } auto *nameItem = new QTableWidgetItem(name); auto *regexItem = new QTableWidgetItem(""); if (regex) regexItem->setCheckState(Qt::Checked); else regexItem->setCheckState(Qt::Unchecked); regexItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *csItem = new QTableWidgetItem(""); if (cs) csItem->setCheckState(Qt::Checked); else csItem->setCheckState(Qt::Unchecked); csItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *enableItem = new QTableWidgetItem(""); if (enable) enableItem->setCheckState(Qt::Checked); else enableItem->setCheckState(Qt::Unchecked); enableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *chanNameItem = new QTableWidgetItem(chanName); auto *senderItem = new QTableWidgetItem(sender); enableItem->setToolTip(tr("Enable/disable this rule")); nameItem->setToolTip(tr("Phrase to match")); regexItem->setToolTip( tr("<b>RegEx</b>: This option determines if the highlight rule should be " "interpreted as a <b>regular expression</b> or just as a keyword.")); csItem->setToolTip( tr("<b>CS</b>: This option determines if the highlight rule should be interpreted " "<b>case sensitive</b>.")); senderItem->setToolTip( tr("<b>Sender</b>: This option specifies which sender nicknames match. Leave " "blank to match any nickname.")); chanNameItem->setToolTip( tr("<p><b>Channel</b>: Semicolon separated list of channel names.</p>" "<p><i>Example:</i><br />" "<i>#quassel*; #foobar; !#quasseldroid</i><br />" "would match on #foobar and any channel starting with <i>#quassel</i> except " "for <i>#quasseldroid</i><br />" "<p>If only inverted names are specified, it will match anything except for " "what's specified (implicit wildcard).</p>" "<p><i>Example:</i><br />" "<i>!#quassel*; !#foobar</i><br />" "would match anything except for #foobar or any channel starting with " "<i>#quassel</i></p>")); int lastRow = ui.ignoredTable->rowCount() - 1; ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::RegExColumn, regexItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::CsColumn, csItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::EnableColumn, enableItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::SenderColumn, senderItem); ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::ChanColumn, chanNameItem); if (!self) ui.ignoredTable->setCurrentItem(nameItem); ignoredList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, true, sender, chanName); }
void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QString &name, bool regex, bool cs, const QString &sender, const QString &chanName, bool self) { ui.highlightTable->setRowCount(ui.highlightTable->rowCount() + 1); if (id < 0) { id = nextId(); } auto *nameItem = new QTableWidgetItem(name); auto *regexItem = new QTableWidgetItem(""); if (regex) regexItem->setCheckState(Qt::Checked); else regexItem->setCheckState(Qt::Unchecked); regexItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *csItem = new QTableWidgetItem(""); if (cs) csItem->setCheckState(Qt::Checked); else csItem->setCheckState(Qt::Unchecked); csItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *enableItem = new QTableWidgetItem(""); if (enable) enableItem->setCheckState(Qt::Checked); else enableItem->setCheckState(Qt::Unchecked); enableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); auto *senderItem = new QTableWidgetItem(sender); auto *chanNameItem = new QTableWidgetItem(chanName); enableItem->setToolTip(tr("Enable/disable this rule")); nameItem->setToolTip(tr("Phrase to match")); regexItem->setToolTip( tr("<b>RegEx</b>: This option determines if the highlight rule, <i>Sender</i>, and " "<i>Channel</i> should be interpreted as <b>regular expressions</b> or just as " "keywords.")); csItem->setToolTip( tr("<b>CS</b>: This option determines if the highlight rule, <i>Sender</i>, and " "<i>Channel</i> should be interpreted <b>case sensitive</b>.")); senderItem->setToolTip( tr("<p><b>Sender</b>: Semicolon separated list of <i>nick!ident@host</i> names, " "leave blank to match any nickname.</p>" "<p><i>Example:</i><br />" "<i>Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*</i><br />" "would match on <i>Alice</i>, <i>Bob</i> with hostmask <i>example.com</i>, and " "any nickname starting with <i>Carol</i> except for <i>Caroline</i><br />" "<p>If only inverted names are specified, it will match anything except for " "what's specified (implicit wildcard).</p>" "<p><i>Example:</i><br />" "<i>!Announce*!*; !Wheatley!aperture@*</i><br />" "would match anything except for <i>Wheatley</i> with ident <i>aperture</i> or " "any nickname starting with <i>Announce</i></p>")); chanNameItem->setToolTip( tr("<p><b>Channel</b>: Semicolon separated list of channel names, leave blank to " "match any name.</p>" "<p><i>Example:</i><br />" "<i>#quassel*; #foobar; !#quasseldroid</i><br />" "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> " "except for <i>#quasseldroid</i><br />" "<p>If only inverted names are specified, it will match anything except for " "what's specified (implicit wildcard).</p>" "<p><i>Example:</i><br />" "<i>!#quassel*; !#foobar</i><br />" "would match anything except for <i>#foobar</i> or any channel starting with " "<i>#quassel</i></p>")); int lastRow = ui.highlightTable->rowCount() - 1; ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::RegExColumn, regexItem); ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::CsColumn, csItem); ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::EnableColumn, enableItem); ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::SenderColumn, senderItem); ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::ChanColumn, chanNameItem); if (!self) ui.highlightTable->setCurrentItem(nameItem); highlightList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, false, sender, chanName); }