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

Go to the SVN repository for this file.

1 #ifndef TABLE_FIELD__HPP
2 #define TABLE_FIELD__HPP
3 
4 /* $Id: table_field.hpp 66092 2015-01-30 04:26:01Z ucko $
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: Eugene Vasilchenko
30 *
31 * File Description:
32 * Table Seq-annot object information
33 *
34 */
35 
36 #include <corelib/ncbiobj.hpp>
37 
40 
41 #include <objmgr/feat_ci.hpp>
42 
45 
46 class CSeq_entry;
47 class CSeq_feat;
48 class CSeq_annot;
49 class CSeq_annot_Info;
50 class CSeq_annot_Handle;
51 class CTable_annot_Info;
52 
53 
55 {
56 public:
57  explicit
59  explicit
60  CTableFieldHandle_Base(const string& field_name);
62 
63  int GetFieldId(void) const {
64  return m_FieldId;
65  }
66  const string& GetFieldName(void) const {
67  return m_FieldName;
68  }
69 
70  bool IsSet(const CFeat_CI& feat_ci) const {
71  return x_GetColumn(feat_ci).IsSet(x_GetRow(feat_ci));
72  }
73  bool IsSet(const CSeq_annot_Handle& annot, size_t row) const {
74  return x_GetColumn(annot).IsSet(row);
75  }
76 
77  template<class Value>
78  bool TryGet(const CFeat_CI& feat_ci, Value& v) const {
79  if ( const CSeqTable_column* column = x_FindColumn(feat_ci) ) {
80  return column->TryGetValue(x_GetRow(feat_ci), v);
81  }
82  return false;
83  }
84 
85  template<class Value>
86  bool TryGet(const CSeq_annot_Handle& annot, size_t row, Value& v) const {
87  if ( const CSeqTable_column* column = x_FindColumn(annot) ) {
88  return column->TryGetValue(row, v);
89  }
90  return false;
91  }
92 
93  const string* GetPtr(const CFeat_CI& feat_ci,
94  const string* dummy,
95  bool force = false) const;
96  const vector<char>* GetPtr(const CFeat_CI& feat_ci,
97  const vector<char>* dummy,
98  bool force = false) const;
99  const string* GetPtr(const CSeq_annot_Handle& annot,
100  size_t row,
101  const string* dummy,
102  bool force = false) const;
103  const vector<char>* GetPtr(const CSeq_annot_Handle& annot,
104  size_t row,
105  const vector<char>* dummy,
106  bool force = false) const;
107 
108 protected:
109  bool x_ThrowUnsetValue(void) const;
110 
111  const CSeqTable_column* x_FindColumn(const CSeq_annot_Info& annot) const;
112  const CSeqTable_column& x_GetColumn(const CSeq_annot_Info& annot) const;
113 
114  const CSeqTable_column* x_FindColumn(const CSeq_annot_Handle& annot) const {
115  return x_FindColumn(annot.x_GetInfo());
116  }
117  const CSeqTable_column* x_FindColumn(const CFeat_CI& feat_ci) const {
118  return x_FindColumn(feat_ci.Get().GetSeq_annot_Info());
119  }
120 
121  const CSeqTable_column& x_GetColumn(const CSeq_annot_Handle& annot) const {
122  return x_GetColumn(annot.x_GetInfo());
123  }
124  const CSeqTable_column& x_GetColumn(const CFeat_CI& feat_ci) const {
125  return x_GetColumn(feat_ci.Get().GetSeq_annot_Info());
126  }
127 
128  size_t x_GetRow(const CFeat_CI& feat_ci) const {
129  return feat_ci.Get().GetAnnotIndex();
130  }
131 
133  string m_FieldName;
136 
137 private:
140 };
141 
142 template<typename FieldType>
144 {
145 public:
146  typedef FieldType TFieldType;
148  : CTableFieldHandle_Base(field_id) {
149  }
150  CTableFieldHandle(const string& field_name)
151  : CTableFieldHandle_Base(field_name) {
152  }
153  /*
154  const TFieldType* GetPtr(const CFeat_CI& feat_ci) const {
155  const TFieldType* dummy = 0;
156  return CTableFieldHandle_Base::GetPtr(feat_ci, dummy, false);
157  }
158  */
159  void Get(const CFeat_CI& feat_ci, TFieldType& v) const {
160  if ( !TryGet(feat_ci, v) ) {
162  }
163  }
164 
165  void Get(const CSeq_annot_Handle& annot, size_t row, TFieldType& v) const {
166  if ( !TryGet(annot, row, v) ) {
168  }
169  }
170 
171  TFieldType Get(const CFeat_CI& feat_ci) const {
173  Get(feat_ci, value);
174  return value;
175  }
176 
177  TFieldType Get(const CSeq_annot_Handle& annot, size_t row) const {
179  Get(annot, row, value);
180  return value;
181  }
182 };
183 
184 
185 /////////////////////////////////////////////////////////////////////////////
186 // CTable_annot_Info
187 /////////////////////////////////////////////////////////////////////////////
188 
189 
192 
193 #endif // TABLE_FIELD__HPP
User-defined methods of the data storage class.
User-defined methods of the data storage class.
static CBioSource dummy
const CSeq_annot_Info & GetSeq_annot_Info(void) const
TAnnotIndex GetAnnotIndex(void) const
const CAnnotObject_Ref & Get(void) const
CFeat_CI –.
Definition: feat_ci.hpp:64
CSeq_annot_Handle –.
Definition: Seq_entry.hpp:56
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
const string & GetFieldName(void) const
Definition: table_field.hpp:66
const CSeqTable_column * x_FindColumn(const CSeq_annot_Handle &annot) const
CTableFieldHandle_Base(const CTableFieldHandle_Base &)
CConstRef< CSeqTable_column > m_CachedFieldInfo
bool IsSet(const CFeat_CI &feat_ci) const
Definition: table_field.hpp:70
const CSeqTable_column & x_GetColumn(const CFeat_CI &feat_ci) const
CConstRef< CSeq_annot_Info > m_CachedAnnotInfo
bool x_ThrowUnsetValue(void) const
size_t x_GetRow(const CFeat_CI &feat_ci) const
const CSeqTable_column * x_FindColumn(const CFeat_CI &feat_ci) const
int GetFieldId(void) const
Definition: table_field.hpp:63
bool TryGet(const CFeat_CI &feat_ci, Value &v) const
Definition: table_field.hpp:78
void operator=(const CTableFieldHandle_Base &)
bool TryGet(const CSeq_annot_Handle &annot, size_t row, Value &v) const
Definition: table_field.hpp:86
bool IsSet(const CSeq_annot_Handle &annot, size_t row) const
Definition: table_field.hpp:73
const CSeqTable_column & x_GetColumn(const CSeq_annot_Handle &annot) const
CTableFieldHandle(const string &field_name)
TFieldType Get(const CSeq_annot_Handle &annot, size_t row) const
void Get(const CSeq_annot_Handle &annot, size_t row, TFieldType &v) const
void Get(const CFeat_CI &feat_ci, TFieldType &v) const
CTableFieldHandle(CSeqTable_column_info::TField_id field_id)
FieldType TFieldType
TFieldType Get(const CFeat_CI &feat_ci) const
char value[7]
Definition: config.c:431
const CSeq_annot_Info & x_GetInfo(void) const
#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
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2107
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static const char * column
Definition: stats.c:23
Modified on Mon Dec 11 02:35:08 2023 by modify_doxy.py rev. 669887