📄 cache.cpp
字号:
return -1;}boolCOrgRefCache::InitNameClasses(){ if( m_ncStorage.size() == 0 ) { CTaxon1_req req; CTaxon1_resp resp; req.SetGetcde(); if( m_host.SendRequest( req, resp ) ) { if( resp.IsGetcde() ) { // Correct response, return object const list< CRef< CTaxon1_info > >& l = ( resp.GetGetcde() ); // Fill in storage for( list< CRef< CTaxon1_info > >::const_iterator i = l.begin(); i != l.end(); ++i ) m_ncStorage .insert( TNameClassMap::value_type((*i)->GetIval1(), (*i)->GetSval()) ); } else { // Internal: wrong respond type m_host.SetLastError( "Response type is not Getcde" ); return false; } } m_ncPrefCommon = FindNameClassByName( "genbank common name" ); if( m_ncPrefCommon < 0 ) { m_host.SetLastError( "Genbank common name class was not found" ); return false; } m_ncCommon = FindNameClassByName( "common name" ); if( m_ncCommon < 0 ) { m_host.SetLastError( "Common name class was not found" ); return false; } m_ncSynonym = FindNameClassByName( "synonym" ); if( m_ncSynonym < 0 ) { m_host.SetLastError( "Synonym name class was not found" ); return false; } m_ncGBAcronym= FindNameClassByName("genbank acronym"); if( m_ncGBAcronym < 0 ) { m_host.SetLastError( "Genbank acrony name class was not found" ); return false; } m_ncGBSynonym= FindNameClassByName("genbank synonym"); if( m_ncGBSynonym < 0 ) { m_host.SetLastError( "Genbank synonym name class was not found" ); return false; } m_ncGBAnamorph= FindNameClassByName("genbank anamorph"); if( m_ncGBAnamorph < 0 ) { m_host.SetLastError( "Genbank anamorph name class was not found" ); return false; } } return true;}shortCOrgRefCache::FindDivisionByCode( const char* pchCode ) const{ for( TDivisionMapCI ci = m_divStorage.begin(); ci != m_divStorage.end(); ++ci ) { const char* cp = ( ci->second.m_sCode.c_str() ); if( strcmp( cp, pchCode ) == 0 ) return ci->first; } return -1;}const char*COrgRefCache::GetDivisionCode( short div_id ) const{ TDivisionMapCI ci( m_divStorage.find( div_id ) ); if( ci != m_divStorage.end() ) { return ci->second.m_sCode.c_str(); } return NULL;}const char*COrgRefCache::GetDivisionName( short div_id ) const{ TDivisionMapCI ci( m_divStorage.find( div_id ) ); if( ci != m_divStorage.end() ) { return ci->second.m_sName.c_str(); } return NULL;}boolCOrgRefCache::InitDivisions(){ if( m_divStorage.size() == 0 ) { CTaxon1_req req; CTaxon1_resp resp; req.SetGetdivs(); if( m_host.SendRequest( req, resp ) ) { if( resp.IsGetdivs() ) { // Correct response, return object const list< CRef< CTaxon1_info > >& l = ( resp.GetGetdivs() ); // Fill in storage for( list< CRef< CTaxon1_info > >::const_iterator i = l.begin(); i != l.end(); ++i ) { SDivision& div = ( m_divStorage[(*i)->GetIval1()] ); div.m_sName.assign( (*i)->GetSval() ); int code = (*i)->GetIval2(); for(int k= 0; k < 3; k++) { div.m_sCode.append( 1U, (code >> (8*(3-k))) & 0xFF ); } div.m_sCode.append( 1U, code & 0xFF ); } } else { // Internal: wrong response type m_host.SetLastError( "Response type is not Getdivs" ); return false; } } if( (m_divViruses = FindDivisionByCode( "VRL" )) < 0 ) { m_host.SetLastError( "Viruses division was not found" ); return false; } if( (m_divPhages = FindDivisionByCode( "PHG" )) < 0 ) { m_host.SetLastError( "Phages division was not found" ); return false; } } return true;}voidCOrgRefCache::SetIndexEntry( int id, CTaxon1Node* pNode ){ m_ppEntries[id] = pNode;}//=======================================================//// Iterators implementation//boolCTaxTreeConstIterator::IsLastChild() const{ const CTreeContNodeBase* pOldNode = m_it->GetNode(); bool bResult = true; while( m_it->GoParent() ) { if( IsVisible( m_it->GetNode() ) ) { const CTreeContNodeBase* pParent = m_it->GetNode(); m_it->GoNode( pOldNode ); while( m_it->GetNode() != pParent ) { if( m_it->GoSibling() ) { bResult = !NextVisible( pParent ); break; } if( !m_it->GoParent() ) { break; } } break; } } m_it->GoNode( pOldNode ); return bResult;}boolCTaxTreeConstIterator::IsFirstChild() const{ const CTreeContNodeBase* pOldNode = m_it->GetNode(); bool bResult = false; while( m_it->GoParent() ) { if( IsVisible( m_it->GetNode() ) ) { const CTreeContNodeBase* pParent = m_it->GetNode(); if( m_it->GoChild() ) { bResult = NextVisible(pParent) && m_it->GetNode() == pOldNode; } break; } } m_it->GoNode( pOldNode ); return bResult;}boolCTaxTreeConstIterator::IsTerminal() const{ const CTreeContNodeBase* pOldNode = m_it->GetNode(); if( m_it->GoChild() ) { bool bResult = NextVisible( pOldNode ); m_it->GoNode( pOldNode ); return !bResult; } return true;}boolCTaxTreeConstIterator::NextVisible( const CTreeContNodeBase* pParent ) const{ if( m_it->GetNode() == pParent ) { return false; } next: if( IsVisible( m_it->GetNode() ) ) { return true; } if( m_it->GoChild() ) { goto next; } else if( m_it->GoSibling() ) { goto next; } else { while( m_it->GoParent() && m_it->GetNode() != pParent ) { if( m_it->GoSibling() ) { goto next; } } } return false;}boolCTaxTreeConstIterator::GoParent(){ const CTreeContNodeBase* pOldNode = m_it->GetNode(); bool bResult = false; while( m_it->GoParent() ) { if( IsVisible( m_it->GetNode() ) ) { bResult = true; break; } } if( !bResult ) { m_it->GoNode( pOldNode ); } return bResult;}boolCTaxTreeConstIterator::GoChild(){ const CTreeContNodeBase* pOldNode = m_it->GetNode(); bool bResult = false; if( m_it->GoChild() ) { bResult = NextVisible( pOldNode ); } if( !bResult ) { m_it->GoNode( pOldNode ); } return bResult;}boolCTaxTreeConstIterator::GoSibling(){ const CTreeContNodeBase* pOldNode = m_it->GetNode(); bool bResult = false; if( GoParent() ) { const CTreeContNodeBase* pParent = m_it->GetNode(); m_it->GoNode( pOldNode ); while( m_it->GetNode() != pParent ) { if( m_it->GoSibling() ) { bResult = NextVisible( pParent ); break; } if( !m_it->GoParent() ) { break; } } if( !bResult ) { m_it->GoNode( pOldNode ); } } return bResult;}boolCTaxTreeConstIterator::GoNode( const ITaxon1Node* pNode ){ const CTreeContNodeBase* pTaxNode = CastIC( pNode ); if( pNode && IsVisible( pTaxNode ) ) { return m_it->GoNode( pTaxNode ); } return false;}boolCTaxTreeConstIterator::GoAncestor(const ITaxon1Node* pINode){ const CTreeContNodeBase* pNode = CastIC( pINode ); if( pNode && IsVisible( pNode ) ) { const CTreeContNodeBase* pOldNode = m_it->GetNode(); vector< const CTreeContNodeBase* > v; do { v.push_back( m_it->GetNode() ); } while( GoParent() ); m_it->GoNode( pNode ); vector< const CTreeContNodeBase* >::const_iterator vi; do { vi = find( v.begin(), v.end(), m_it->GetNode() ); if( vi != v.end() ) { return true; } } while( GoParent() ); // Restore old position m_it->GoNode( pOldNode ); } return false;}boolCTaxTreeConstIterator::BelongSubtree(const ITaxon1Node* pIRoot) const{ const CTreeContNodeBase* pRoot = CastIC( pIRoot ); if( pRoot && IsVisible( pRoot ) ) { const CTreeContNodeBase* pOldNode = m_it->GetNode(); do { if( IsVisible( m_it->GetNode() ) ) { if( m_it->GetNode() == pRoot ) { m_it->GoNode( pOldNode ); return true; } } } while( m_it->GoParent() ); m_it->GoNode( pOldNode ); } return false;}// check if given node belongs to subtree pointed by cursorboolCTaxTreeConstIterator::AboveNode(const ITaxon1Node* pINode) const{ const CTreeContNodeBase* pNode = CastIC( pINode ); if( pNode == m_it->GetNode() ) { // Node is not above itself return false; } if( pNode && IsVisible( pNode ) ) { const CTreeContNodeBase* pOldNode = m_it->GetNode(); m_it->GoNode( pNode ); do { if( IsVisible( m_it->GetNode() ) ) { if( m_it->GetNode() == pOldNode ) { m_it->GoNode( pOldNode ); return true; } } } while( m_it->GoParent() ); m_it->GoNode( pOldNode ); } return false;}boolCTreeLeavesBranchesIterator::IsVisible( const CTreeContNodeBase* pNode ) const{ return pNode && ( pNode->IsRoot() || pNode->IsTerminal() || !pNode->Child()->IsLastChild() );}boolCTreeBestIterator::IsVisible( const CTreeContNodeBase* pNode ) const{ return pNode && ( pNode->IsRoot() || pNode->IsTerminal() || !pNode->Child()->IsLastChild() || !(pNode->IsLastChild() && pNode->IsFirstChild()) );}boolCTreeBlastIterator::IsVisible( const CTreeContNodeBase* pNode ) const{ return pNode && ( pNode->IsRoot() || !CastCI(pNode)->GetBlastName().empty() );}END_objects_SCOPEEND_NCBI_SCOPE/* * $Log: cache.cpp,v $ * Revision 1000.3 2004/06/01 19:35:08 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R6.21 * * Revision 6.21 2004/05/19 17:27:10 gorelenk * Added include of PCH - ncbi_pch.hpp * * Revision 6.20 2004/02/04 16:14:44 domrach * New iterator types (modes of operation) are introduced. They include: * full tree, branches'n'leaves, best, and blast. Position inquiry f-ns * IsTerminal(), IsFirstChild(), and IsLastChild() has been moved from * ITreeNode to ITreeIterator. Node loading f-ns() now return the ITreeNode * for tax id. * * Revision 6.19 2003/11/20 15:42:19 ucko * Update for new (saner) treatment of ASN.1 NULLs. * * Revision 6.18 2003/06/23 20:42:08 domrach * New treatment of subspecies names introduced * * Revision 6.17 2003/06/05 20:44:01 domrach * Adjusted to the new CanGetXxx verification methods * * Revision 6.16 2003/05/06 19:53:53 domrach * New functions and interfaces for traversing the cached partial taxonomy tree introduced. Convenience functions GetDivisionName() and GetRankName() were added * * Revision 6.15 2003/03/06 16:13:14 domrach * Typo fix * * Revision 6.14 2003/03/06 16:11:29 domrach * More static initialization work * * Revision 6.13 2003/03/06 16:01:20 domrach * Static initialization corrected for msvc * * Revision 6.12 2003/03/05 21:33:52 domrach * Enhanced orgref processing. Orgref cache capacity control added. * * Revision 6.11 2003/01/21 19:36:22 domrach * Secondary tax id support added. New copy constructor for partial tree support added. * * Revision 6.10 2002/11/08 14:39:52 domrach * Member function GetSuperkingdom() added * * Revision 6.9 2002/11/04 21:29:18 grichenk * Fixed usage of const CRef<> and CRef<> constructor * * Revision 6.8 2002/08/06 15:09:45 domrach * Introducing new genbank name classes * * Revision 6.7 2002/07/25 15:01:56 grichenk * Replaced non-const GetXXX() with SetXXX() * * Revision 6.6 2002/02/14 22:44:50 vakatov * Use STimeout instead of time_t. * Get rid of warnings and extraneous #include's, shuffled code a little. * * Revision 6.5 2002/01/31 00:31:26 vakatov * Follow the renaming of "CTreeCont.hpp" to "ctreecont.hpp". * Get rid of "std::" which is unnecessary and sometimes un-compilable. * Also done some source identation/beautification. * * Revision 6.4 2002/01/30 16:13:37 domrach * Changes made to pass through MSVC compiler. Some src files renamed * * Revision 6.3 2002/01/29 17:17:45 domrach * Confusion with list/set resolved * * Revision 6.2 2002/01/28 21:37:02 domrach * list changed to multiset in BuildOrgRef() * * Revision 6.1 2002/01/28 19:56:10 domrach * Initial checkin of the library implementation files * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -