NCBI C++ ToolKit
seqgraphic_ds_manager.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: seqgraphic_ds_manager.cpp 45881 2021-01-05 03:10:02Z rudnev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Liangshou Wu
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
37 
39 
41 {
42  // get Data Source Types from Extension Registry
45 }
46 
47 
49  const string& type,
50  SConstScopedObject& object)
51 {
53 
54  // first try to find it in the cached registry
55  {
58  if (ds_iter != m_DataSources.end()) {
59  ds = ds_iter->second.Lock();
60  if (ds.IsNull()) {
61  // remove it from registry
62  m_DataSources.erase(ds_iter);
63  }
64  }
65  }
66 
67  if ( !ds ) {// we need to create one using the corresponding factory.
68  for( size_t i = 0; i < m_DataSourceTypes.size(); i++ ) {
70  if (type == typeid(ds_type).name()) {
71  ds.Reset(ds_type.CreateDS(object));
72 
73  // if the data source can be shared, cache it.
74  if (ds_type.IsSharable()) {
77  }
78  break;
79  }
80  }
81  }
82 
83  if ( !ds ) {
84  NCBI_THROW(CException, eInvalid, "The data source type can't be recognized!");
85  }
86 
87  INonAsnDataSource* nonasn_ds = dynamic_cast<INonAsnDataSource*>(ds.GetPointerOrNull());
88  if (nullptr != nonasn_ds) {
89  nonasn_ds->SetNonAsnDataRegistry(this);
90  }
91 
92  return ds;
93 }
94 
95 
97 {
98 }
99 
100 
102 {
103  {
104  CFastMutexGuard LOCK(m_Mutex);
106  }
107  {
108  std::lock_guard<std::mutex> guard(m_NonAsnDataBlobsMutex);
110  }
111 }
112 
113 
115 {
116  std::lock_guard<std::mutex> guard(m_NonAsnDataBlobsMutex);
117  m_NonAsnDataBlobs[data.GetAnnots()[0]] = &data.GetBlob();
118 }
119 
121 {
122  std::lock_guard<std::mutex> guard(m_NonAsnDataBlobsMutex);
124  TBlobsMap::iterator it_data = m_NonAsnDataBlobs.find(data.GetAnnots()[0]);
125  if (it_data != m_NonAsnDataBlobs.end()) {
126  m_NonAsnDataBlobs.erase(it_data);
127  }
128 }
129 
130 bool CSGDataSourceContext::HasNonAsnData(const string &annot_name) const
131 {
132  std::lock_guard<std::mutex> guard(m_NonAsnDataBlobsMutex);
133  return m_NonAsnDataBlobs.count(annot_name) != 0;
134 }
135 
137 {
138  std::lock_guard<std::mutex> guard(m_NonAsnDataBlobsMutex);
139  return *(m_NonAsnDataBlobs.at(annot_name));
140 }
141 
142 
virtual CIRef< ISGDataSource > GetDS(const string &type, SConstScopedObject &object)
Get a seqgraphic data source instance of the specified type.
virtual void AddNonAsnData(const INonAsnTrackData &data)
virtual void ClearCache()
clear the cache if any.
virtual bool HasNonAsnData(const string &annot_name) const
TDSRegistry m_DataSources
The cached data source instances.
virtual const TDataBlob & GetNonAsnDataBlob(const string &annot_name) const
CFastMutex m_Mutex
make sure data source context is thread-safe
virtual void RemoveNonAsnData(const INonAsnTrackData &data)
TDataSourceTypeVec m_DataSourceTypes
All the registered data source types.
static void EraseCachePerAnnotation(const string &annot_name)
ISGDataSourceFactory.
virtual ISGDataSource * CreateDS(SConstScopedObject &object) const =0
create an instance of the layout track type using default settings.
virtual bool IsSharable() const =0
check if the data source can be shared.
void erase(iterator pos)
Definition: map.hpp:167
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
static int type
Definition: getdata.c:31
char data[12]
Definition: iconv.c:80
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
virtual void SetNonAsnDataRegistry(const INonAsnDataRegistry *registry)=0
INonAsnTrackData::TDataBlob TDataBlob
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
bool IsNull(void) const THROWS_NONE
Check if pointer is null – same effect as Empty().
Definition: ncbiobj.hpp:735
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
int i
#define EXT_POINT__SEQGRAPHIC_DATA_SOURCE_TYPE
ISGDataSourceManager uses the following extension point to obtain registered seqgraphic data source f...
Definition: type.c:6
Modified on Thu May 02 14:29:14 2024 by modify_doxy.py rev. 669887