1 /*  $Id: tse_handle.cpp 603374 2020-03-10 19:52:03Z vasilche $
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 * Author: Aleksey Grichenko, Eugene Vasilchenko
27 *
28 * File Description:
29 *    Handle to top level Seq-entry
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <objmgr/tse_handle.hpp>
35 #include <objmgr/seq_entry_handle.hpp>
36 #include <objmgr/bioseq_handle.hpp>
37 #include <objmgr/impl/scope_info.hpp>
38 #include <objmgr/impl/scope_impl.hpp>
39 #include <objmgr/seq_feat_handle.hpp>
40 #include <objmgr/impl/seq_annot_info.hpp>
41 #include <objects/submit/Seq_submit.hpp>
42 
43 BEGIN_NCBI_SCOPE
BEGIN_SCOPE(objects)44 BEGIN_SCOPE(objects)
45 
46 #if 0
47 # define _TRACE_TSE_LOCK(type)                                          \
48     if ( !m_TSE.GetPointer() )                                          \
49         ;                                                               \
50     else                                                                \
51         _TRACE("CTSE_Handle("<<this<<") "<<m_TSE.GetPointer()<<" " type)
52 #else
53 # define _TRACE_TSE_LOCK(type) ((void)0)
54 #endif
55 
56 #define _CHECK() _ASSERT(!*this || &m_TSE->GetScopeImpl() == m_Scope.GetImpl())
57 
58 CTSE_Handle::CTSE_Handle(TScopeInfo& object)
59     : m_Scope(object.GetScopeImpl().GetScope()),
60       m_TSE(&object)
61 {
62     _TRACE_TSE_LOCK("lock");
63     _CHECK();
64 }
65 
66 
CTSE_Handle(const CTSE_ScopeUserLock & lock)67 CTSE_Handle::CTSE_Handle(const CTSE_ScopeUserLock& lock)
68     : m_Scope(lock->GetScopeImpl().GetScope()),
69       m_TSE(lock)
70 {
71     _TRACE_TSE_LOCK("lock");
72     _CHECK();
73 }
74 
75 
CTSE_Handle(const CTSE_Handle & tse)76 CTSE_Handle::CTSE_Handle(const CTSE_Handle& tse)
77     : m_Scope(tse.m_Scope),
78       m_TSE(tse.m_TSE)
79 {
80     _TRACE_TSE_LOCK("lock");
81     _CHECK();
82 }
83 
84 
~CTSE_Handle(void)85 CTSE_Handle::~CTSE_Handle(void)
86 {
87     _CHECK();
88     _TRACE_TSE_LOCK("unlock");
89 }
90 
91 
operator =(const CTSE_Handle & tse)92 CTSE_Handle& CTSE_Handle::operator=(const CTSE_Handle& tse)
93 {
94     _CHECK();
95     if ( this != &tse ) {
96         _TRACE_TSE_LOCK("unlock");
97         m_TSE = tse.m_TSE;
98         m_Scope = tse.m_Scope;
99         _TRACE_TSE_LOCK("lock");
100         _CHECK();
101     }
102     return *this;
103 }
104 
105 
Reset(void)106 void CTSE_Handle::Reset(void)
107 {
108     _CHECK();
109     _TRACE_TSE_LOCK("unlock");
110     m_TSE.Reset();
111     m_Scope.Reset();
112     _CHECK();
113 }
114 
115 
x_GetTSE_Info(void) const116 const CTSE_Info& CTSE_Handle::x_GetTSE_Info(void) const
117 {
118     return *m_TSE->m_TSE_Lock;
119 }
120 
121 
GetBlobId(void) const122 CTSE_Handle::TBlobId CTSE_Handle::GetBlobId(void) const
123 {
124     return x_GetTSE_Info().GetBlobId();
125 }
126 
127 
GetDataLoader(void) const128 CDataLoader* CTSE_Handle::GetDataLoader(void) const
129 {
130     return x_GetTSE_Info().GetDataSource().GetDataLoader();
131 }
132 
133 
IsValid(void) const134 bool CTSE_Handle::IsValid(void) const
135 {
136     return m_TSE && m_TSE->IsAttached();
137 }
138 
139 
GetUsedMemory(void) const140 size_t CTSE_Handle::GetUsedMemory(void) const
141 {
142     return x_GetTSE_Info().GetUsedMemory();
143 }
144 
145 
OrderedBefore(const CTSE_Handle & tse) const146 bool CTSE_Handle::OrderedBefore(const CTSE_Handle& tse) const
147 {
148     if ( *this == tse ) {
149         return false;
150     }
151     const CTSE_ScopeInfo& info1 = x_GetScopeInfo();
152     const CTSE_ScopeInfo& info2 = tse.x_GetScopeInfo();
153     CTSE_ScopeInfo::TBlobOrder order1 = info1.GetBlobOrder();
154     CTSE_ScopeInfo::TBlobOrder order2 = info2.GetBlobOrder();
155     if ( order1 != order2 ) {
156         _ASSERT((order1 < order2) || (order2 < order1));
157         return order1 < order2;
158     }
159     if ( info1.GetLoadIndex() != info2.GetLoadIndex() ) {
160         return info1.GetLoadIndex() < info2.GetLoadIndex();
161     }
162     return *this < tse;
163 }
164 
165 
Blob_IsSuppressed(void) const166 bool CTSE_Handle::Blob_IsSuppressed(void) const
167 {
168     return Blob_IsSuppressedTemp()  ||  Blob_IsSuppressedPerm();
169 }
170 
171 
Blob_IsSuppressedTemp(void) const172 bool CTSE_Handle::Blob_IsSuppressedTemp(void) const
173 {
174     return (x_GetTSE_Info().GetBlobState() &
175             CBioseq_Handle::fState_suppress_temp) != 0;
176 }
177 
178 
Blob_IsSuppressedPerm(void) const179 bool CTSE_Handle::Blob_IsSuppressedPerm(void) const
180 {
181     return (x_GetTSE_Info().GetBlobState() &
182             CBioseq_Handle::fState_suppress_perm) != 0;
183 }
184 
185 
Blob_IsDead(void) const186 bool CTSE_Handle::Blob_IsDead(void) const
187 {
188     return (x_GetTSE_Info().GetBlobState() &
189             CBioseq_Handle::fState_dead) != 0;
190 }
191 
192 
GetCompleteTSE(void) const193 CConstRef<CSeq_entry> CTSE_Handle::GetCompleteTSE(void) const
194 {
195     return x_GetTSE_Info().GetCompleteSeq_entry();
196 }
197 
198 
GetTSECore(void) const199 CConstRef<CSeq_entry> CTSE_Handle::GetTSECore(void) const
200 {
201     return x_GetTSE_Info().GetSeq_entryCore();
202 }
203 
204 
GetTopLevelEntry(void) const205 CSeq_entry_Handle CTSE_Handle::GetTopLevelEntry(void) const
206 {
207     return CSeq_entry_Handle(x_GetTSE_Info(), *this);
208 }
209 
210 
GetBioseqHandle(const CSeq_id_Handle & id) const211 CBioseq_Handle CTSE_Handle::GetBioseqHandle(const CSeq_id_Handle& id) const
212 {
213     return x_GetScopeImpl().GetBioseqHandleFromTSE(id, *this);
214 }
215 
216 
GetBioseqHandle(const CSeq_id & id) const217 CBioseq_Handle CTSE_Handle::GetBioseqHandle(const CSeq_id& id) const
218 {
219     return GetBioseqHandle(CSeq_id_Handle::GetHandle(id));
220 }
221 
222 
AddUsedTSE(const CTSE_Handle & tse) const223 bool CTSE_Handle::AddUsedTSE(const CTSE_Handle& tse) const
224 {
225     return x_GetScopeInfo().AddUsedTSE(tse.m_TSE);
226 }
227 
228 
CanBeEdited(void) const229 bool CTSE_Handle::CanBeEdited(void) const
230 {
231     return x_GetScopeInfo().CanBeEdited();
232 }
233 
234 
GetTopLevelObjectType() const235 CTSE_Handle::ETopLevelObjectType CTSE_Handle::GetTopLevelObjectType() const
236 {
237     return x_GetTSE_Info().GetTopLevelObjectType();
238 }
239 
240 
GetTopLevelSeq_submit() const241 const CSeq_submit& CTSE_Handle::GetTopLevelSeq_submit() const
242 {
243     return x_GetTSE_Info().GetTopLevelSeq_submit();
244 }
245 
246 
IsTopLevelSeq_submit() const247 bool CTSE_Handle::IsTopLevelSeq_submit() const
248 {
249     return x_GetTSE_Info().IsTopLevelSeq_submit();
250 }
251 
252 
GetTopLevelSubmit_block() const253 const CSubmit_block& CTSE_Handle::GetTopLevelSubmit_block() const
254 {
255     return x_GetTSE_Info().GetTopLevelSubmit_block();
256 }
257 
258 
SetTopLevelSubmit_block() const259 CSubmit_block& CTSE_Handle::SetTopLevelSubmit_block() const
260 {
261     if ( !CanBeEdited() ) {
262         NCBI_THROW(CObjMgrException, eModifyDataError,
263                    "CTSE_Handle::SetTopLevelSubmit_block: entry cannot be edited");
264     }
265     return x_GetTSE_Info().SetTopLevelSubmit_block();
266 }
267 
268 
SetTopLevelSubmit_block(CSubmit_block & sub) const269 void CTSE_Handle::SetTopLevelSubmit_block(CSubmit_block& sub) const
270 {
271     if ( !CanBeEdited() ) {
272         NCBI_THROW(CObjMgrException, eModifyDataError,
273                    "CTSE_Handle::SetTopLevelSubmit_block: entry cannot be edited");
274     }
275     return x_GetTSE_Info().SetTopLevelSubmit_block(sub);
276 }
277 
278 
279 ////////////////////////////////////////////////////////////////////////////
280 // CHandleInfo_Base
281 ////////////////////////////////////////////////////////////////////////////
282 
283 
284 /*
285 *****************************************************************************
286 CScopeInfo_Base can be in the following states:
287 
288 S0. detached, unlocked:
289    TSE_ScopeInfo == 0,
290    LockCounter == 0,
291    TSE_Handle == 0,
292    ObjectInfo == 0.
293 
294 S1. attached, locked, indexed:
295    TSE_ScopeInfo != 0,
296    LockCounter > 0,
297    TSE_Handle != 0,
298    ObjectInfo != 0, indexed.
299  When unlocked by handles (LockCounter becomes 0) (A1):
300   1. TSE_Handle is reset,
301   New state: S4.
302  When removed explicitly (A2):
303   1. Do actual remove,
304   2. Scan for implicit removals,
305   3. Assert that this CScopeInfo_Base is removed (detached),
306   New state: S3 (implicitly).
307  When removed implicitly (found in ObjectInfo index as being removed) (A3):
308   1. TSE_Handle is reset,
309   2. Removed from index by ObjectInfo,
310   3. Detached from TSE,
311   New state: S3.
312 
313 S2. attached, unlocked, non-temporary:
314    TSE_ScopeInfo != 0,
315    LockCounter == 0,
316    TSE_Handle == 0,
317    ObjectInfo == 0.
318  When relocked (A5):
319   1. TSE_Handle is set,
320   2. ObjectInfo is set, adding to index by ObjectInfo,
321   New state: S1.
322  When removed implicitly (is it possible to determine?) (A3):
323   1. Detached from TSE,
324   New state: S0.
325  When TSE is unlocked completely, non-temporary (A4):
326   Same state: S2.
327 
328 S3. detached, locked:
329    TSE_ScopeInfo == 0,
330    LockCounter > 0,
331    TSE_Handle == 0,
332    ObjectInfo != 0, not indexed.
333  When unlocked by handles (LockCounter becomes 0) (A1):
334   1. ObjectInfo is reset,
335   New state: S0.
336  When added into another place (A7):
337   1. attached to TSE,
338   2. TSE_Handle is set,
339   3. ObjectInfo is set, adding to index by ObjectInfo,
340   New state: S1.
341 
342 S4. attached, unlocked, indexed:
343    TSE_ScopeInfo != 0,
344    LockCounter == 0,
345    TSE_Handle == 0,
346    ObjectInfo != 0, indexed.
347  When relocked (A5):
348   1. TSE_Handle is set,
349   New state: S1.
350  When removed implicitly (found in ObjectInfo index as being removed) (A3):
351   1. Removing from index by ObjectInfo,
352   2. Detached from TSE,
353   New state: S3.
354  When TSE is unlocked completely, temporary (A4):
355   1. ObjectInfo is reset, with removing from index by ObjectInfo,
356   2. Detached from TSE,
357   New state: S0.
358  When TSE is unlocked completely, non-temporary (A4):
359   1. ObjectInfo is reset, with removing from index by ObjectInfo,
360   New state: S2.
361 
362 S5. detached, locked, dummy:
363    TSE_ScopeInfo == 0,
364    LockCounter > 0,
365    TSE_Handle == 0,
366    ObjectInfo == 0.
367  When unlocked by handles (LockCounter becomes 0) (A1):
368   1. -> S0.
369 
370 *****************************************************************************
371 Meaning of members:
372 A. TSE_ScopeInfo != 0: attached, means it's used by some TSE_ScopeInfo.
373      S1,S4,S2.
374 
375 B. LockCounter > 0: locked, means it's used by some handle.
376      S1,S3,S5.
377 
378 C. TSE_Handle != 0 only when attached and locked.
379      S1.
380 
381 D. Indexed by ObjectInfo only when attached and ObjectInfo != 0.
382      S1,S4.
383 
384 E. Empty, only LockCounter can be set, other members are null.
385    Scope info cannot leave this state.
386      S0,S5.
387 
388 *****************************************************************************
389 Actions:
390 A1. Unlocking by handles: when LockCounter goes to zero.
391   Pre: locked (S1,S3,S5).
392   Post: unlocked (S4,S0).
393 
394   S1 (attached)    -> S4
395   S3,S5 (detached) -> S0
396 
397 A2. Explicit removal: when one of Remove/Reset methods is called.
398   Pre: attached, locked (S1).
399   Post: detached, locked (S3).
400 
401   Perform implicit removal A3.
402 
403 A3. Implicit removal: when one of Remove/Reset methods is called.
404   Pre: attached (S1,S4,S2).
405   Post: detached (S3,S0).
406 
407   S1 (locked) -> S3. // TSE_Handle.Reset(), unindex.
408   S4 (unlocked, indexed) -> S0.
409   S2 (unlocked, not indexed) -> ???
410 
411 A4. TSE unlocking: when TSE_Lock is removed from unlock queue.
412   Pre: unlocked, attached (S2,S4).
413   Post: unlocked, unindexed (S2,S0).
414 
415   S2 (non-temporary) -> S2.
416   S4 (non-temporary) -> S2.
417   S4 (temporary) -> S0.
418 
419 A5. Relocking: when ScopeInfo is requested again.
420   Pre: attached, unlocked (S2,S4).
421   Post: attached, locked (S1).
422 
423   S4 -> S1.
424   S2 -> S1.
425 
426 A6. Removing from history.
427   Pre:
428 
429 A7. Reattaching in new place.
430   Pre: detached, locked (S3).
431   Post: attached, locked (S1).
432 
433 */
434 
CScopeInfo_Base(void)435 CScopeInfo_Base::CScopeInfo_Base(void)
436     : m_TSE_ScopeInfo(0)
437 {
438 }
439 
440 
CScopeInfo_Base(const CTSE_ScopeUserLock & tse,const CTSE_Info_Object & info)441 CScopeInfo_Base::CScopeInfo_Base(const CTSE_ScopeUserLock& tse,
442                                  const CTSE_Info_Object& info)
443     : m_TSE_ScopeInfo(tse.GetNonNullNCPointer()),
444       m_TSE_Handle(tse),
445       m_ObjectInfo(&info)
446 {
447 }
448 
449 
CScopeInfo_Base(const CTSE_Handle & tse,const CTSE_Info_Object & info)450 CScopeInfo_Base::CScopeInfo_Base(const CTSE_Handle& tse,
451                                  const CTSE_Info_Object& info)
452     : m_TSE_ScopeInfo(&tse.x_GetScopeInfo()),
453       m_TSE_Handle(tse),
454       m_ObjectInfo(&info)
455 {
456 }
457 
458 
~CScopeInfo_Base(void)459 CScopeInfo_Base::~CScopeInfo_Base(void)
460 {
461 }
462 
463 
x_GetScopeImpl(void) const464 CScope_Impl& CScopeInfo_Base::x_GetScopeImpl(void) const
465 {
466     return x_GetTSE_ScopeInfo().GetScopeImpl();
467 }
468 
469 
GetIndexIds(void) const470 const CScopeInfo_Base::TIndexIds* CScopeInfo_Base::GetIndexIds(void) const
471 {
472     return 0;
473 }
474 
475 
476 DEFINE_STATIC_FAST_MUTEX(s_Info_TSE_HandleMutex);
477 
478 
x_SetTSE_Handle(const CTSE_Handle & tse)479 void CScopeInfo_Base::x_SetTSE_Handle(const CTSE_Handle& tse)
480 {
481     _ASSERT(IsAttached());
482     _ASSERT(!HasObject() || GetObjectInfo_Base().BelongsToTSE_Info(tse.x_GetTSE_Info()));
483     _ASSERT(m_LockCounter.Get() > 0);
484     CTSE_Handle save_tse;
485     CFastMutexGuard guard(s_Info_TSE_HandleMutex);
486     if ( !m_TSE_Handle.m_TSE ) {
487         _ASSERT(tse);
488         save_tse.Swap(m_TSE_Handle);
489         m_TSE_Handle = tse;
490     }
491     _ASSERT(m_TSE_Handle == tse);
492 }
493 
494 
x_SetTSE_Lock(const CTSE_ScopeUserLock & tse,const CTSE_Info_Object & info)495 void CScopeInfo_Base::x_SetTSE_Lock(const CTSE_ScopeUserLock& tse,
496                                     const CTSE_Info_Object& info)
497 {
498     _ASSERT(!IsDetached());
499     _ASSERT(tse);
500     _ASSERT(&*tse == m_TSE_ScopeInfo);
501     _ASSERT(m_LockCounter.Get() > 0);
502     CTSE_Handle save_tse;
503     CFastMutexGuard guard(s_Info_TSE_HandleMutex);
504     if ( !m_TSE_Handle.m_TSE || !m_ObjectInfo ) {
505         save_tse.Swap(m_TSE_Handle);
506         m_TSE_Handle = tse;
507         m_ObjectInfo = &info;
508     }
509     _ASSERT(&m_TSE_Handle.x_GetScopeInfo() == &*tse);
510     _ASSERT(!m_ObjectInfo || &GetObjectInfo_Base() == &info);
511 }
512 
513 
x_ResetTSE_Lock()514 void CScopeInfo_Base::x_ResetTSE_Lock()
515 {
516     if ( m_TSE_Handle.m_TSE && m_LockCounter.Get() == 0 ) {
517         CTSE_Handle save_tse; // prevent deletion of handle and scope under mutex
518         CFastMutexGuard guard(s_Info_TSE_HandleMutex);
519         if ( m_TSE_Handle.m_TSE && m_LockCounter.Get() == 0 ) {
520             save_tse.Swap(m_TSE_Handle);
521         }
522     }
523 }
524 
525 
x_AttachTSE(CTSE_ScopeInfo * tse)526 void CScopeInfo_Base::x_AttachTSE(CTSE_ScopeInfo* tse)
527 {
528     _ASSERT(tse);
529     _ASSERT(!m_TSE_ScopeInfo);
530     _ASSERT(IsDetached());
531     m_TSE_ScopeInfo = tse;
532 }
533 
534 
x_DetachTSE(CTSE_ScopeInfo * tse)535 void CScopeInfo_Base::x_DetachTSE(CTSE_ScopeInfo* tse)
536 {
537     _ASSERT(tse);
538     _ASSERT(!IsDetached());
539     _ASSERT(m_TSE_ScopeInfo == tse);
540     _ASSERT(!m_TSE_Handle);
541     m_TSE_ScopeInfo = 0;
542 }
543 
544 
545 /////////////////////////////////////////////////////////////////////////////
546 // FeatId support
547 CSeq_feat_Handle
x_MakeHandle(CAnnotObject_Info * info) const548 CTSE_Handle::x_MakeHandle(CAnnotObject_Info* info) const
549 {
550     return CSeq_feat_Handle(GetScope(), info);
551 }
552 
553 
554 CSeq_feat_Handle
x_MakeHandle(const TAnnotObjectList & infos) const555 CTSE_Handle::x_MakeHandle(const TAnnotObjectList& infos) const
556 {
557     return infos.empty()? CSeq_feat_Handle(): x_MakeHandle(*infos.begin());
558 }
559 
560 
561 CTSE_Handle::TSeq_feat_Handles
x_MakeHandles(const TAnnotObjectList & infos) const562 CTSE_Handle::x_MakeHandles(const TAnnotObjectList& infos) const
563 {
564     TSeq_feat_Handles handles;
565     handles.reserve(infos.size());
566     ITERATE ( TAnnotObjectList, it, infos ) {
567         handles.push_back(x_MakeHandle(*it));
568     }
569     return handles;
570 }
571 
572 
573 /////////////////////////////////////////////////////////////////////////////
574 // integer FeatId
575 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::E_Choice type,TFeatureIdInt id) const576 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::E_Choice type,
577                                TFeatureIdInt id) const
578 {
579     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id));
580 }
581 
582 
583 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::ESubtype subtype,TFeatureIdInt id) const584 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::ESubtype subtype,
585                                TFeatureIdInt id) const
586 {
587     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id));
588 }
589 
590 
591 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::E_Choice type,TFeatureIdInt id) const592 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::E_Choice type,
593                                  TFeatureIdInt id) const
594 {
595     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_xref));
596 }
597 
598 
599 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,TFeatureIdInt id) const600 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,
601                                  TFeatureIdInt id) const
602 {
603     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_xref));
604 }
605 
606 
GetFeatureWithId(CSeqFeatData::E_Choice type,TFeatureIdInt id) const607 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::E_Choice type,
608                                                TFeatureIdInt id) const
609 {
610     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id));
611 }
612 
613 
GetFeatureWithId(CSeqFeatData::ESubtype subtype,TFeatureIdInt id) const614 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::ESubtype subtype,
615                                                TFeatureIdInt id) const
616 {
617     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id));
618 }
619 
620 
621 /////////////////////////////////////////////////////////////////////////////
622 // string FeatId
623 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::E_Choice type,const TFeatureIdStr & id) const624 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::E_Choice type,
625                                const TFeatureIdStr& id) const
626 {
627     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id));
628 }
629 
630 
631 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::ESubtype subtype,const TFeatureIdStr & id) const632 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::ESubtype subtype,
633                                const TFeatureIdStr& id) const
634 {
635     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id));
636 }
637 
638 
639 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::E_Choice type,const TFeatureIdStr & id) const640 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::E_Choice type,
641                                  const TFeatureIdStr& id) const
642 {
643     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_xref));
644 }
645 
646 
647 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,const TFeatureIdStr & id) const648 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,
649                                  const TFeatureIdStr& id) const
650 {
651     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_xref));
652 }
653 
654 
GetFeatureWithId(CSeqFeatData::E_Choice type,const TFeatureIdStr & id) const655 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::E_Choice type,
656                                                const TFeatureIdStr& id) const
657 {
658     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id));
659 }
660 
661 
GetFeatureWithId(CSeqFeatData::ESubtype subtype,const TFeatureIdStr & id) const662 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::ESubtype subtype,
663                                                const TFeatureIdStr& id) const
664 {
665     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id));
666 }
667 
668 
669 /////////////////////////////////////////////////////////////////////////////
670 // CObject_id FeatId
671 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::E_Choice type,const TFeatureId & id) const672 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::E_Choice type,
673                                const TFeatureId& id) const
674 {
675     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id));
676 }
677 
678 
679 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::ESubtype subtype,const TFeatureId & id) const680 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::ESubtype subtype,
681                                const TFeatureId& id) const
682 {
683     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id));
684 }
685 
686 
687 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::E_Choice type,const TFeatureId & id) const688 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::E_Choice type,
689                                  const TFeatureId& id) const
690 {
691     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_xref));
692 }
693 
694 
695 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,const TFeatureId & id) const696 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,
697                                  const TFeatureId& id) const
698 {
699     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_xref));
700 }
701 
702 
GetFeatureWithId(CSeqFeatData::E_Choice type,const TFeatureId & id) const703 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::E_Choice type,
704                                                const TFeatureId& id) const
705 {
706     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id));
707 }
708 
709 
GetFeatureWithId(CSeqFeatData::ESubtype subtype,const TFeatureId & id) const710 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::ESubtype subtype,
711                                                const TFeatureId& id) const
712 {
713     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id));
714 }
715 
716 
717 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::E_Choice type,const TFeatureId & id,const CSeq_annot_Handle & src_annot) const718 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::E_Choice type,
719                                const TFeatureId& id,
720                                const CSeq_annot_Handle& src_annot) const
721 {
722     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
723     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id, src_annot_info));
724 }
725 
726 
727 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithId(CSeqFeatData::ESubtype subtype,const TFeatureId & id,const CSeq_annot_Handle & src_annot) const728 CTSE_Handle::GetFeaturesWithId(CSeqFeatData::ESubtype subtype,
729                                const TFeatureId& id,
730                                const CSeq_annot_Handle& src_annot) const
731 {
732     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
733     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id, src_annot_info));
734 }
735 
736 
737 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::E_Choice type,const TFeatureId & id,const CSeq_annot_Handle & src_annot) const738 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::E_Choice type,
739                                  const TFeatureId& id,
740                                  const CSeq_annot_Handle& src_annot) const
741 {
742     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
743     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_xref, src_annot_info));
744 }
745 
746 
747 CTSE_Handle::TSeq_feat_Handles
GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,const TFeatureId & id,const CSeq_annot_Handle & src_annot) const748 CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,
749                                  const TFeatureId& id,
750                                  const CSeq_annot_Handle& src_annot) const
751 {
752     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
753     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_xref, src_annot_info));
754 }
755 
756 
GetFeatureWithId(CSeqFeatData::E_Choice type,const TFeatureId & id,const CSeq_annot_Handle & src_annot) const757 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::E_Choice type,
758                                                const TFeatureId& id,
759                                                const CSeq_annot_Handle& src_annot) const
760 {
761     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
762     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(type, id, eFeatId_id, src_annot_info));
763 }
764 
765 
GetFeatureWithId(CSeqFeatData::ESubtype subtype,const TFeatureId & id,const CSeq_annot_Handle & src_annot) const766 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::ESubtype subtype,
767                                                const TFeatureId& id,
768                                                const CSeq_annot_Handle& src_annot) const
769 {
770     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
771     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesById(subtype, id, eFeatId_id, src_annot_info));
772 }
773 
774 
GetFeaturesWithId(CSeqFeatData::E_Choice type,const TFeatureId & id,const CSeq_feat_Handle & src) const775 CTSE_Handle::TSeq_feat_Handles CTSE_Handle::GetFeaturesWithId(CSeqFeatData::E_Choice type,
776                                                               const TFeatureId& id,
777                                                               const CSeq_feat_Handle& src) const
778 {
779     return GetFeaturesWithId(type, id, src.GetAnnot());
780 }
781 
782 
GetFeaturesWithId(CSeqFeatData::ESubtype subtype,const TFeatureId & id,const CSeq_feat_Handle & src) const783 CTSE_Handle::TSeq_feat_Handles CTSE_Handle::GetFeaturesWithId(CSeqFeatData::ESubtype subtype,
784                                                               const TFeatureId& id,
785                                                               const CSeq_feat_Handle& src) const
786 {
787     return GetFeaturesWithId(subtype, id, src.GetAnnot());
788 }
789 
790 
GetFeaturesWithXref(CSeqFeatData::E_Choice type,const TFeatureId & id,const CSeq_feat_Handle & src) const791 CTSE_Handle::TSeq_feat_Handles CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::E_Choice type,
792                                                                 const TFeatureId& id,
793                                                                 const CSeq_feat_Handle& src) const
794 {
795     return GetFeaturesWithXref(type, id, src.GetAnnot());
796 }
797 
798 
GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,const TFeatureId & id,const CSeq_feat_Handle & src) const799 CTSE_Handle::TSeq_feat_Handles CTSE_Handle::GetFeaturesWithXref(CSeqFeatData::ESubtype subtype,
800                                                                 const TFeatureId& id,
801                                                                 const CSeq_feat_Handle& src) const
802 {
803     return GetFeaturesWithXref(subtype, id, src.GetAnnot());
804 }
805 
806 
GetFeatureWithId(CSeqFeatData::E_Choice type,const TFeatureId & id,const CSeq_feat_Handle & src) const807 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::E_Choice type,
808                                                const TFeatureId& id,
809                                                const CSeq_feat_Handle& src) const
810 {
811     return GetFeatureWithId(type, id, src.GetAnnot());
812 }
813 
814 
GetFeatureWithId(CSeqFeatData::ESubtype subtype,const TFeatureId & id,const CSeq_feat_Handle & src) const815 CSeq_feat_Handle CTSE_Handle::GetFeatureWithId(CSeqFeatData::ESubtype subtype,
816                                                const TFeatureId& id,
817                                                const CSeq_feat_Handle& src) const
818 {
819     return GetFeatureWithId(subtype, id, src.GetAnnot());
820 }
821 
822 
823 /////////////////////////////////////////////////////////////////////////////
824 // gene id support
GetGeneWithLocus(const string & locus,bool tag) const825 CSeq_feat_Handle CTSE_Handle::GetGeneWithLocus(const string& locus,
826                                                bool tag) const
827 {
828     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesByLocus(locus, tag));
829 }
830 
831 
832 CTSE_Handle::TSeq_feat_Handles
GetGenesWithLocus(const string & locus,bool tag) const833 CTSE_Handle::GetGenesWithLocus(const string& locus,
834                                bool tag) const
835 {
836     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesByLocus(locus, tag));
837 }
838 
839 
GetGeneWithLocus(const string & locus,bool tag,const CSeq_annot_Handle & src_annot) const840 CSeq_feat_Handle CTSE_Handle::GetGeneWithLocus(const string& locus,
841                                                bool tag,
842                                                const CSeq_annot_Handle& src_annot) const
843 {
844     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
845     return x_MakeHandle(x_GetTSE_Info().x_GetFeaturesByLocus(locus, tag, src_annot_info));
846 }
847 
848 
849 CTSE_Handle::TSeq_feat_Handles
GetGenesWithLocus(const string & locus,bool tag,const CSeq_annot_Handle & src_annot) const850 CTSE_Handle::GetGenesWithLocus(const string& locus,
851                                bool tag,
852                                const CSeq_annot_Handle& src_annot) const
853 {
854     const CSeq_annot_Info* src_annot_info = src_annot? &src_annot.x_GetInfo(): 0;
855     return x_MakeHandles(x_GetTSE_Info().x_GetFeaturesByLocus(locus, tag, src_annot_info));
856 }
857 
858 
GetGeneByRef(const CGene_ref & ref) const859 CSeq_feat_Handle CTSE_Handle::GetGeneByRef(const CGene_ref& ref) const
860 {
861     CSeq_feat_Handle feat;
862     if ( ref.IsSetLocus_tag() ) {
863         feat = GetGeneWithLocus(ref.GetLocus_tag(), true);
864     }
865     if ( !feat && ref.IsSetLocus() ) {
866         feat = GetGeneWithLocus(ref.GetLocus(), false);
867     }
868     return feat;
869 }
870 
871 
872 CTSE_Handle::TSeq_feat_Handles
GetGenesByRef(const CGene_ref & ref) const873 CTSE_Handle::GetGenesByRef(const CGene_ref& ref) const
874 {
875     TSeq_feat_Handles ret;
876     if ( ref.IsSetLocus_tag() ) {
877         GetGenesWithLocus(ref.GetLocus_tag(), true).swap(ret);
878     }
879     if ( ref.IsSetLocus() ) {
880         TSeq_feat_Handles hh = GetGenesWithLocus(ref.GetLocus(), false);
881         ret.insert(ret.end(), hh.begin(), hh.end());
882     }
883     return ret;
884 }
885 
886 
GetGeneByRef(const CGene_ref & ref,const CSeq_annot_Handle & src_annot) const887 CSeq_feat_Handle CTSE_Handle::GetGeneByRef(const CGene_ref& ref,
888                                            const CSeq_annot_Handle& src_annot) const
889 {
890     CSeq_feat_Handle feat;
891     if ( ref.IsSetLocus_tag() ) {
892         feat = GetGeneWithLocus(ref.GetLocus_tag(), true);
893     }
894     if ( !feat && ref.IsSetLocus() ) {
895         feat = GetGeneWithLocus(ref.GetLocus(), false);
896     }
897     return feat;
898 }
899 
900 
901 CTSE_Handle::TSeq_feat_Handles
GetGenesByRef(const CGene_ref & ref,const CSeq_annot_Handle & src_annot) const902 CTSE_Handle::GetGenesByRef(const CGene_ref& ref,
903                            const CSeq_annot_Handle& src_annot) const
904 {
905     TSeq_feat_Handles ret;
906     if ( ref.IsSetLocus_tag() ) {
907         GetGenesWithLocus(ref.GetLocus_tag(), true, src_annot).swap(ret);
908     }
909     if ( ref.IsSetLocus() ) {
910         TSeq_feat_Handles hh = GetGenesWithLocus(ref.GetLocus(), false, src_annot);
911         ret.insert(ret.end(), hh.begin(), hh.end());
912     }
913     return ret;
914 }
915 
916 
GetGeneWithLocus(const string & locus,bool tag,const CSeq_feat_Handle & src) const917 CSeq_feat_Handle CTSE_Handle::GetGeneWithLocus(const string& locus,
918                                                bool tag,
919                                                const CSeq_feat_Handle& src) const
920 {
921     return GetGeneWithLocus(locus, tag, src.GetAnnot());
922 }
923 
924 
GetGenesWithLocus(const string & locus,bool tag,const CSeq_feat_Handle & src) const925 CTSE_Handle::TSeq_feat_Handles CTSE_Handle::GetGenesWithLocus(const string& locus,
926                                                               bool tag,
927                                                               const CSeq_feat_Handle& src) const
928 {
929     return GetGenesWithLocus(locus, tag, src.GetAnnot());
930 }
931 
932 
GetGeneByRef(const CGene_ref & ref,const CSeq_feat_Handle & src) const933 CSeq_feat_Handle CTSE_Handle::GetGeneByRef(const CGene_ref& ref,
934                                            const CSeq_feat_Handle& src) const
935 {
936     return GetGeneByRef(ref, src.GetAnnot());
937 }
938 
939 
GetGenesByRef(const CGene_ref & ref,const CSeq_feat_Handle & src) const940 CTSE_Handle::TSeq_feat_Handles CTSE_Handle::GetGenesByRef(const CGene_ref& ref,
941                                                           const CSeq_feat_Handle& src) const
942 {
943     return GetGenesByRef(ref, src.GetAnnot());
944 }
945 
946 
947 END_SCOPE(objects)
948 END_NCBI_SCOPE
949