unsigned UserNSConfig::convContToHostID(const IDMap &map, const std::string &ID, unsigned contID) const { if (map.empty()) { return contID; } auto it = std::find_if(map.begin(), map.end(), [contID](const std::tuple<unsigned, unsigned, unsigned>& entry) { unsigned size = std::get<2>(entry); uid_t contMin = std::get<0>(entry); uid_t contMax = contMin + size - 1; if (contMin <= contID && contID <= contMax) { return true; } return false; } ); if (it == map.end()) { const std::string msg = "The " + ID + ": " + std::to_string(contID) + " is not mapped in the container"; LOGE(msg); throw ConfigureException(msg); } unsigned diff = contID - std::get<0>(*it); unsigned hostID = std::get<1>(*it) + diff; return hostID; }
/// Returns an annotation document by given path. AnnotationDocumentPtr AnnotationAgent::getDocument( const QString & doc_path ) { DocumentIter idx = docs_.find( doc_path ); if (idx != docs_.end()) { return idx.value(); } // create a new document AnnotationDocumentPtr doc( new AnnotationDocument() ); if ( !doc->open( doc_path ) ) { return AnnotationDocumentPtr(); } // put new document instance into list docs_[doc_path] = doc; // get the list of pages id and initialize all of the page instances shared_ptr<AnnotationIO> io = AnnotationIO::getIO( doc_path, false ); if (io.get()) { IDMap ids; io->loadPagesID( ids ); IDMapIter iter = ids.begin(); for (; iter != ids.end(); iter++) { AnnotationPagePtr page = doc->getPage( iter.value() ); page->setGlobalID( iter.key() ); // qDebug("Load Annotation Page:%d, Global ID:%d", iter.value(), iter.key()); } } return doc; }