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

Go to the SVN repository for this file.

1 /* $Id: gi_cache.cpp 35227 2016-04-12 18:56:35Z katargir $
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>
34 #include <objmgr/bioseq_handle.hpp>
35 #include <objmgr/util/sequence.hpp>
36 
39 
40 
42 
43 
45  : m_Cache(50000)
46 {
47 }
48 
50 {
51 }
52 
53 
55 {
56  bool is_known = false;
57 
58  CSeq_id_Handle shdl = handle.GetSeq_id_Handle();
59  shdl = sequence::GetId(shdl, handle.GetScope(), sequence::eGetId_ForceGi);
60  CSeq_id::TGi gi = shdl.GetGi();
61  if (gi > ZERO_GI) {
63  TCache::const_iterator iter = std::find(m_Cache.begin(), m_Cache.end(), gi);
64  if (iter != m_Cache.end()) {
65  is_known = true;
66  } else {
67  m_Cache.push_back(gi);
68  }
69  }
70  return is_known;
71 }
72 
73 
75 {
76  if ( !m_CacheInstance ) {
77  DEFINE_STATIC_FAST_MUTEX(s_Mutex);
78  CFastMutexGuard LOCK(s_Mutex);
79  if ( !m_CacheInstance ) {
81  }
82  }
83  return *m_CacheInstance;
84 }
85 
86 
88 
89 
90 /*
91  * ===========================================================================
92  * $Log$
93  * ===========================================================================
94  */
CBioseq_Handle –.
class CGiCache provides a simple, thread-safe interface for storing the older or outdated versions of...
Definition: gi_cache.hpp:55
TCache m_Cache
Definition: gi_cache.hpp:71
CFastMutex m_Mutex
Definition: gi_cache.hpp:70
bool RecordKnown(const objects::CBioseq_Handle &handle)
Check if the record is in the cache.
Definition: gi_cache.cpp:54
static CGiCache & GetInstance()
retrieve a singleton.
Definition: gi_cache.cpp:74
~CGiCache()
Definition: gi_cache.cpp:49
static CRef< CGiCache > m_CacheInstance
Definition: gi_cache.hpp:73
CGiCache()
Definition: gi_cache.cpp:44
USING_SCOPE(objects)
#define ZERO_GI
Definition: ncbimisc.hpp:1088
TGi GetGi(void) const
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_ForceGi
return only a gi-based seq-id
Definition: sequence.hpp:99
const CSeq_id_Handle & GetSeq_id_Handle(void) const
Get handle of id used to obtain this bioseq handle.
CScope & GetScope(void) const
Get scope this handle belongs to.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define DEFINE_STATIC_FAST_MUTEX(id)
Define static fast mutex and initialize it.
Definition: ncbimtx.hpp:496
NCBI_NS_NCBI::TGi TGi
Definition: Seq_id_.hpp:180
Modified on Fri Sep 20 14:57:44 2024 by modify_doxy.py rev. 669887