doc_manager.cpp

来自「ncbi源码」· C++ 代码 · 共 550 行 · 第 1/2 页

CPP
550
字号
/* * =========================================================================== * PRODUCTION $Log: doc_manager.cpp,v $ * PRODUCTION Revision 1000.5  2004/06/01 20:43:48  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.50 * PRODUCTION * =========================================================================== *//*  $Id: doc_manager.cpp,v 1000.5 2004/06/01 20:43:48 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Mike DiCuccio * * File Description: *    Central document arbiter for GBENCH */#include <ncbi_pch.hpp>#include <corelib/ncbimtx.hpp>#include <gui/core/data_store.hpp>#include <gui/core/doc_exception.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/docmgr_view.hpp>#include <gui/core/idocument.hpp>#include <gui/core/plugin_registry.hpp>#include <gui/core/plugin_utils.hpp>#include <gui/core/message_queue.hpp>#include <gui/core/iview.hpp>#include <gui/config/settings.hpp>#include <gui/core/selection_buffer.hpp>#include <gui/utils/message_box.hpp>#include <gui/utils/clipboard.hpp>#include <gui/plugin/PluginMessage.hpp>#include <gui/plugin/PluginMRUList.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqalign/Seq_align.hpp>#include <objects/seq/Seq_annot.hpp>#include <objmgr/object_manager.hpp>#include <serial/typeinfo.hpp>#include <algorithm>#include "seqid_doc.hpp"#include "serialobj_doc.hpp"BEGIN_NCBI_SCOPE//// statics//DEFINE_STATIC_MUTEX(s_DocMgrMutex);CRef<CObjectManager>     CDocManager::sm_ObjMgr;CDocManager::TDocList    CDocManager::sm_Documents;CDocManager::TViewList   CDocManager::sm_Views;CRef<CSelectionBuffer>   CDocManager::sm_SelBuffer;CRef<CSettings>          CDocManager::sm_Settings;CDocManager::TScopeIndex CDocManager::sm_ScopeIdx;CRef<CPluginMRUList>     CDocManager::sm_PluginMessageCache;//// destructor// this is defined so that we can specify the order of destruction of our// member objects.  scopes must be deleted before the object manager itself!//void CDocManager::ShutDown(){    CMutexGuard LOCK(s_DocMgrMutex);    // shut down our settings    GetSettings().ShutDown();    // clear the data store    CDataStore::Clear();    // clear the clipboard    CClipboard::Clear();    // clear the plugin registry    CPluginRegistry::Clear();    // clear our views    sm_Views.clear();    // clear the plugin message queue    CPluginMessageQueue::Clear();    // clear our documents - there are hidden scopes here    // because of a circular CRef<>, we need to clear the views first    NON_CONST_ITERATE (TDocList, iter, sm_Documents) {        (*iter)->Clear();    }    sm_Documents.clear();    sm_ScopeIdx.clear();    // now, free to object manager    // (hopefully we've rooted out all lingering scopes by this point)    sm_ObjMgr.Reset(NULL);}CDocManager::TDocList& CDocManager::GetDocuments(){    CMutexGuard LOCK(s_DocMgrMutex);    return sm_Documents;}//// attach a view to the document manager//void CDocManager::AttachView(CDocMgrView* view){    CMutexGuard LOCK(s_DocMgrMutex);    CRef<CDocMgrView> ref(view);    sm_Views.push_back(ref);}//// force update() to be called on all views//void CDocManager::UpdateAllViews(TUpdateFlags flags){    CMutexGuard LOCK(s_DocMgrMutex);    NON_CONST_ITERATE (TViewList, iter, sm_Views) {        if (flags & (*iter)->GetEventMask()) {            (*iter)->Update(flags & (*iter)->GetEventMask());        }    }}//// event will be broadcasted to all documents and then views//void CDocManager::NotifyAllViews(const CEvent * event){    CMutexGuard LOCK(s_DocMgrMutex);    NON_CONST_ITERATE (TDocList, iter, sm_Documents) {        IEventReceiver * vr = (*iter)->QueryInterfaceReceiver();        if (vr) vr->OnEvent(event);    }}//// x_CreateObjectManager()// function to wrap object manager and scope creation//void CDocManager::x_CreateObjectManager(void){    // Check to see if we have an object manager(if not, we need to create one)    if (sm_ObjMgr) {        return;    }    // Create object manager    sm_ObjMgr = new CObjectManager();    if ( !sm_ObjMgr  ) {        NCBI_THROW(CDocException, eObjectManagerError,                   "CDocManager::CDocManager(): can't create object manager");    }}//// access the object manager//CObjectManager& CDocManager::GetObjectManager(){    if ( !sm_ObjMgr ) {        CMutexGuard LOCK(s_DocMgrMutex);        x_CreateObjectManager();    }    return *sm_ObjMgr;}//// access the selection buffer//CSelectionBuffer& CDocManager::GetSelBuffer(){    if (sm_SelBuffer) {        return *sm_SelBuffer;    }    CMutexGuard LOCK(s_DocMgrMutex);    // check again after locking to make sure we didn't block on a thread that    // was creating our selection buffer    if (sm_SelBuffer) {        return *sm_SelBuffer;    }    sm_SelBuffer = new CSelectionBuffer();    return *sm_SelBuffer;}//// GetSettings()// access the global settings repository//CSettings& CDocManager::GetSettings(void){    if ( !sm_Settings ) {        CMutexGuard LOCK(s_DocMgrMutex);        if ( !sm_Settings ) {            sm_Settings.Reset(new CSettings());        }    }    return *sm_Settings;}IDocument* CDocManager::GetDocumentFromScope(CScope& scope){    CMutexGuard LOCK(s_DocMgrMutex);    TScopeIndex::iterator iter = sm_ScopeIdx.find(CRef<CScope>(&scope));    if (iter == sm_ScopeIdx.end()) {        return NULL;    }    return iter->second;}const IDocument* CDocManager::GetDocumentFromScope(const CScope& scope){    CRef<CScope> nc_ref(&const_cast<CScope&>(scope));    CMutexGuard LOCK(s_DocMgrMutex);    TScopeIndex::const_iterator iter = sm_ScopeIdx.find(nc_ref);    if (iter == sm_ScopeIdx.end()) {        return NULL;    }    return iter->second;}//// GetDocument()// this actually creates and manages documents for the user//IDocument* CDocManager::CreateDocument(CScope& scope, const CSeq_id& id){    CMutexGuard LOCK(s_DocMgrMutex);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?