NCBI C++ ToolKit
annot_type_index.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef OBJECTS_OBJMGR_IMPL___ANNOT_TYPE_INDEX__HPP
2 #define OBJECTS_OBJMGR_IMPL___ANNOT_TYPE_INDEX__HPP
3 
4 /* $Id: annot_type_index.hpp 99883 2023-05-18 17:55:27Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Aleksey Grichenko
30 *
31 * File Description:
32 * Annotation type indexes
33 *
34 */
35 
36 
37 #include <corelib/ncbistd.hpp>
40 
41 #include <vector>
42 
45 
46 
47 struct SAnnotTypeSelector;
48 struct SIdAnnotObjs;
49 class CAnnotObject_Info;
50 struct SAnnotObject_Key;
51 
52 ////////////////////////////////////////////////////////////////////
53 //
54 // CAnnotType_Index::
55 //
56 // Helper class to convert annotation type/subtype to an index
57 //
58 
59 
61 {
62 public:
63  typedef pair<size_t, size_t> TIndexRange;
64 
65  static void Initialize(void);
66 
67  static TIndexRange GetAnnotTypeRange(CSeq_annot::C_Data::E_Choice type);
68  static TIndexRange GetFeatTypeRange(CSeqFeatData::E_Choice type);
69  static size_t GetSubtypeIndex(CSeqFeatData::ESubtype subtype);
70 
71  static TIndexRange GetIndexRange(const SAnnotTypeSelector& sel);
72  static TIndexRange GetIndexRange(const SAnnotTypeSelector& sel,
73  const SIdAnnotObjs& objs);
74  static TIndexRange GetTypeIndex(const CAnnotObject_Info& info);
75 
76  static CSeqFeatData::ESubtype GetSubtypeForIndex(size_t index);
77  static SAnnotTypeSelector GetTypeSelector(size_t index);
78 
79 private:
80  enum ETypeSizes {
82  kFeatType_size = CSeqFeatData::e_MaxChoice,
83  kFeatSubtype_size = CSeqFeatData::eSubtype_max
84  };
90  kAnnotIndex_size = kAnnotIndex_Ftable + kFeatSubtype_size
91  };
92 
93  static void x_InitIndexTables(void);
94 
95  // Initialization flag
96  static atomic<bool> sm_TablesInitialized;
97  // Table: annot type -> index
98  // (for Ftable it's just the first feature type index)
99  static Uint1 sm_AnnotTypeIndexRange[kAnnotType_size][2];
100  // Table: feat type -> index range, [)
101  static Uint1 sm_FeatTypeIndexRange[kFeatType_size][2];
102  // Table feat subtype -> index
103  static Uint1 sm_FeatSubtypeIndex[kFeatSubtype_size];
104  // Table index -> subtype
105  static Uint1 sm_IndexSubtype[kAnnotIndex_size];
106 };
107 
108 
109 inline
111 {
112  if ( !sm_TablesInitialized.load(memory_order_acquire) ) {
114  }
115 }
116 
117 
118 inline
121 {
122  Initialize();
123  size_t start, end;
124  if ( size_t(type) < kAnnotType_size ) {
125  start = sm_AnnotTypeIndexRange[type][0];
126  end = sm_AnnotTypeIndexRange[type][1];
127  }
128  else {
129  start = end = 0;
130  }
131  return TIndexRange(start, end);
132 }
133 
134 
135 inline
138 {
139  Initialize();
140  size_t start, end;
141  if ( size_t(type) < kFeatType_size ) {
142  start = sm_FeatTypeIndexRange[type][0];
143  end = sm_FeatTypeIndexRange[type][1];
144  }
145  else {
146  start = end = 0;
147  }
148  return TIndexRange(start, end);
149 }
150 
151 
152 inline
154 {
155  Initialize();
156  if ( size_t(subtype) < kFeatSubtype_size ) {
157  return sm_FeatSubtypeIndex[subtype];
158  }
159  else {
160  return 0;
161  }
162 }
163 
164 
165 inline
167 {
168  Initialize();
169  if ( index < kAnnotIndex_size ) {
171  }
172  else {
174  }
175 }
176 
177 
180 
181 #endif// OBJECTS_OBJMGR_IMPL___ANNOT_TYPE_INDEX__HPP
static void x_InitIndexTables(void)
static CSeqFeatData::ESubtype GetSubtypeForIndex(size_t index)
pair< size_t, size_t > TIndexRange
static TIndexRange GetFeatTypeRange(CSeqFeatData::E_Choice type)
static size_t GetSubtypeIndex(CSeqFeatData::ESubtype subtype)
static Uint1 sm_FeatSubtypeIndex[kFeatSubtype_size]
static Uint1 sm_FeatTypeIndexRange[kFeatType_size][2]
static void Initialize(void)
static Uint1 sm_AnnotTypeIndexRange[kAnnotType_size][2]
static Uint1 sm_IndexSubtype[kAnnotIndex_size]
static TIndexRange GetAnnotTypeRange(CSeq_annot::C_Data::E_Choice type)
static atomic< bool > sm_TablesInitialized
@ eSubtype_bad
These no longer need to match the FEATDEF values in the C toolkit's objfdef.h.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static int type
Definition: getdata.c:31
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
E_Choice
Choice variants.
@ e_MaxChoice
== e_Variation+1
E_Choice
Choice variants.
Definition: Seq_annot_.hpp:131
@ e_MaxChoice
== e_Seq_table+1
Definition: Seq_annot_.hpp:142
static MDB_envinfo info
Definition: mdb_load.c:37
Definition: type.c:6
Modified on Sat Dec 02 09:20:40 2023 by modify_doxy.py rev. 669887