selection_buffer.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: selection_buffer.cpp,v $
- * PRODUCTION Revision 1000.3 2004/06/01 20:44:38 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: selection_buffer.cpp,v 1000.3 2004/06/01 20:44:38 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:
- * Container classes for GBENCH selection information
- */
- #include <ncbi_pch.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/selection_buffer.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <serial/serialbase.hpp>
- #include <algorithm>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- //
- //
- // class CSelectionBuffer
- //
- //
- void CSelectionBuffer::Clear()
- {
- m_SelMap.clear();
- }
- void CSelectionBuffer::Copy(const CSelectionBuffer& other)
- {
- m_SelMap = other.m_SelMap;
- }
- void CSelectionBuffer::Clear(const IDocument* doc)
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter != m_SelMap.end()) {
- m_SelMap.erase(iter);
- }
- }
- void CSelectionBuffer::AddSelection(const IDocument* doc)
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter != m_SelMap.end()) {
- iter->second.push_back(CConstRef<CObject>(doc));
- return;
- }
- m_SelMap[doc_ref].push_back(CConstRef<CObject>(doc));
- }
- void CSelectionBuffer::AddSelection(const IDocument* doc,
- const CObject& obj)
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter == m_SelMap.end()) {
- m_SelMap[doc_ref] = TConstObjects();
- iter = m_SelMap.find(doc_ref);
- }
- CConstRef<CObject> ref(&obj);
- TConstObjects::const_iterator obj_iter =
- std::find(iter->second.begin(), iter->second.end(),
- ref);
- if (obj_iter == iter->second.end()) {
- iter->second.push_back(ref);
- }
- }
- void CSelectionBuffer::RemoveSelection(const IDocument* doc)
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter == m_SelMap.end()) {
- return;
- }
- CConstRef<CObject> obj_ref(doc);
- TConstObjects::iterator obj_iter =
- std::find(iter->second.begin(), iter->second.end(),
- obj_ref);
- if (obj_iter != iter->second.end()) {
- iter->second.erase(obj_iter);
- }
- if (iter->second.size() == 0) {
- m_SelMap.erase(iter);
- }
- }
- void CSelectionBuffer::RemoveSelection(const IDocument* doc,
- const CObject& obj)
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter == m_SelMap.end()) {
- return;
- }
- CConstRef<CObject> ref(&obj);
- TConstObjects::iterator obj_iter =
- std::find(iter->second.begin(), iter->second.end(),
- ref);
- if (obj_iter != iter->second.end()) {
- iter->second.erase(obj_iter);
- }
- if (iter->second.size() == 0) {
- m_SelMap.erase(iter);
- }
- }
- // ISelection interface requirements
- void CSelectionBuffer::GetSelections(TConstScopedObjects& objs) const
- {
- ITERATE (TSelMap, iter, m_SelMap) {
- CScope& scope = iter->first->GetScope();
- ITERATE (TConstObjects, obj_iter, iter->second) {
- SConstScopedObject sco(**obj_iter, scope);
- objs.push_back(sco);
- }
- }
- }
- void CSelectionBuffer::SetSelections(const TConstScopedObjects& objs)
- {
- ITERATE (TConstScopedObjects, iter, objs) {
- const IDocument* doc = CDocManager::GetDocumentFromScope(*iter->scope);
- if ( !doc ) {
- continue;
- }
- AddSelection(doc, *iter->object);
- }
- }
- const TConstObjects&
- CSelectionBuffer::GetSelections(const IDocument* doc) const
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter == m_SelMap.end()) {
- m_SelMap[doc_ref] = TConstObjects();
- iter = m_SelMap.find(doc_ref);
- }
- return iter->second;
- }
- TConstObjects& CSelectionBuffer::SetSelections(const IDocument* doc)
- {
- CConstRef<IDocument> doc_ref(doc);
- TSelMap::iterator iter = m_SelMap.find(doc_ref);
- if (iter == m_SelMap.end()) {
- m_SelMap[doc_ref] = TConstObjects();
- iter = m_SelMap.find(doc_ref);
- }
- return iter->second;
- }
- //
- // decompose the current selections into a series of pairs
- // of CObject and IDocument
- //
- TConstScopedObjects CSelectionBuffer::DecomposeToPairs(void) const
- {
- TConstScopedObjects sels;
-
- ITERATE(TSelMap, iter, m_SelMap) {
- if ( !iter->first ) {
- continue;
- }
- CScope& scope = iter->first->GetScope();
- ITERATE (TConstObjects, obj_iter, iter->second) {
- if ( !*obj_iter ) {
- continue;
- }
- sels.push_back(SConstScopedObject(**obj_iter, scope));
- }
- }
- return sels;
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: selection_buffer.cpp,v $
- * Revision 1000.3 2004/06/01 20:44:38 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18
- *
- * Revision 1.18 2004/05/21 22:27:40 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.17 2004/05/03 12:49:28 dicuccio
- * gui/utils --> gui/objutils where needed
- *
- * Revision 1.16 2004/04/21 12:40:33 dicuccio
- * Added ISelection interface. Added checks in DecomposeToPairs() to guard
- * against null ptr dereference.
- *
- * Revision 1.15 2004/04/16 14:29:18 dicuccio
- * Simplified interface - set all selections as CObject
- *
- * Revision 1.14 2004/04/07 12:48:21 dicuccio
- * Reworked to use structs / typedefs in objects.hpp
- *
- * Revision 1.13 2003/12/30 15:02:23 dicuccio
- * Use const IDocument* instead of IDocument* everywhere
- *
- * Revision 1.12 2003/12/22 19:21:36 dicuccio
- * Added Copy(). Removed GetSelections().
- *
- * Revision 1.11 2003/09/04 14:01:51 dicuccio
- * Introduce IDocument and IView as abstract base classes for CDocument and CView
- *
- * Revision 1.10 2003/08/18 14:43:27 dicuccio
- * Changed nales: CFeature -> CLayoutFeat; CAlignment -> CLayoutAlign; CGraph ->
- * CLayoutGraph; CProtProduct -> CLayoutProtProd.
- * Changed handling of CSeq_feat - return original feature always.
- *
- * Revision 1.9 2003/07/24 13:12:44 dicuccio
- * Handle protein product layout objects correctly
- *
- * Revision 1.8 2003/07/21 19:29:57 dicuccio
- * Removed all type-specific accessors - CSelectionBuffer is now generic. Added
- * new internal class for TSelections instead of pair<>.
- *
- * Revision 1.7 2003/06/25 17:02:54 dicuccio
- * Split CPluginHandle into a handle (pointer-to-implementation) and
- * implementation file. Lots of #include file clean-ups.
- *
- * Revision 1.6 2003/04/16 18:23:17 dicuccio
- * Added retrieval of arguments as generic CObjects, and as a set of pairwise
- * documents-and-objects
- *
- * Revision 1.5 2003/01/13 13:48:10 dicuccio
- * Minor compilation fixes. Corrected namespaces for MSVC
- *
- * Revision 1.4 2003/01/13 13:10:07 dicuccio
- * Namespace clean-up. Retired namespace gui -> converted all to namespace ncbi.
- * Moved all FLUID-generated code into namespace ncbi.
- *
- * Revision 1.3 2002/11/29 16:17:49 dicuccio
- * Added obtuse work-around for MSVC's brken handling of nested namespaces.
- *
- * Revision 1.2 2002/11/09 20:58:15 dicuccio
- * CConstRef<> ctor is now explicit. Also, minor formatting changes.
- *
- * Revision 1.1 2002/11/06 17:46:19 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */