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

Go to the SVN repository for this file.

1 /* $Id: gb_block_field.cpp 95056 2021-10-01 16:40:21Z stakhovv $
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: Colleen Bollin, NCBI
27 *
28 * File Description:
29 * CGBBlockField class
30 */
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbistd.hpp>
33 #include <corelib/ncbiobj.hpp>
37 #include <objmgr/seq_entry_ci.hpp>
39 
43 
45 {
46  vector<string> vals = GetVals(object);
47  if (vals.size() > 0) {
48  return vals[0];
49  } else {
50  return "";
51  }
52 }
53 
54 
55 vector<string> CGBBlockField::GetVals(const CObject& object)
56 {
57  vector<string> rval;
58 
59  const CSeqdesc* desc = dynamic_cast<const CSeqdesc *>(&object);
60  if (desc && desc->IsGenbank()) {
61  switch (m_FieldType) {
63  if (desc->GetGenbank().IsSetKeywords()) {
65  rval.push_back(*it);
66  }
67  }
68  break;
70  if (desc->GetGenbank().IsSetExtra_accessions()) {
72  rval.push_back(*it);
73  }
74  }
75  break;
76  default:
77  break;
78  }
79  }
80  return rval;
81 }
82 
83 
84 bool CGBBlockField::IsEmpty(const CObject& object) const
85 {
86  const CSeqdesc* desc = dynamic_cast<const CSeqdesc *>(&object);
87  if (!desc || !desc->IsGenbank()) {
88  return false;
89  }
90  const CGB_block& block = desc->GetGenbank();
91  return block.IsEmpty();
92 }
93 
94 
96 {
97  CSeqdesc* desc = dynamic_cast<CSeqdesc *>(&object);
98  if (!desc || !desc->IsGenbank()) {
99  return;
100  }
101  switch (m_FieldType) {
103  desc->SetGenbank().ResetKeywords();
104  break;
107  break;
108  default:
109  break;
110  }
111 }
112 
113 
114 bool CGBBlockField::SetVal(CObject& object, const string& val, EExistingText existing_text)
115 {
116  bool rval = false;
117 
118  CSeqdesc* desc = dynamic_cast<CSeqdesc *>(&object);
119  if (!desc) {
120  return false;
121  }
122  switch (m_FieldType) {
124  if (!desc->IsGenbank()
125  || !desc->GetGenbank().IsSetKeywords()
126  || desc->GetGenbank().GetKeywords().empty()
127  || existing_text == eExistingText_add_qual) {
128  desc->SetGenbank().SetKeywords().push_back(val);
129  rval = true;
130  } else {
131  CGB_block::TKeywords::iterator it = desc->SetGenbank().SetKeywords().begin();
132  while (it != desc->SetGenbank().SetKeywords().end()) {
133  string curr_val = *it;
135  if (AddValueToString(curr_val, val, existing_text)) {
136  *it = curr_val;
137  rval = true;
138  }
139  }
140  if(NStr::IsBlank(*it)) {
141  it = desc->SetGenbank().SetKeywords().erase(it);
142  } else {
143  ++it;
144  }
145  }
146  }
147  break;
149  if (!desc->IsGenbank()
150  || !desc->GetGenbank().IsSetExtra_accessions()
151  || desc->GetGenbank().GetExtra_accessions().empty()
152  || existing_text == eExistingText_add_qual) {
153  desc->SetGenbank().SetExtra_accessions().push_back(val);
154  rval = true;
155  } else {
156  CGB_block::TExtra_accessions::iterator it = desc->SetGenbank().SetExtra_accessions().begin();
157  while (it != desc->SetGenbank().SetExtra_accessions().end()) {
158  string curr_val = *it;
160  if (AddValueToString(curr_val, val, existing_text)) {
161  *it = curr_val;
162  rval = true;
163  }
164  }
165  if(NStr::IsBlank(*it)) {
166  it = desc->SetGenbank().SetExtra_accessions().erase(it);
167  } else {
168  ++it;
169  }
170  }
171  }
172  break;
173  default:
174  break;
175  }
176  return rval;
177 }
178 
179 
180 void CGBBlockField::SetConstraint(const string& field, CConstRef<CStringConstraint> string_constraint)
181 {
182  EGBBlockFieldType field_type = GetTypeForLabel(field);
183  if (field_type == m_FieldType && string_constraint) {
185  m_StringConstraint->Assign(*string_constraint);
186  } else {
188  }
189 }
190 
191 
193 {
194  bool rval = false;
195  switch (m_FieldType) {
198  rval = true;
199  break;
200  default:
201  break;
202  }
203 
204  return rval;
205 }
206 
207 
209 {
212  if (NStr::EqualNocase(label, match)) {
213  return (EGBBlockFieldType)i;
214  }
215  }
217 }
218 
219 
221 {
222  string rval;
223  switch (field_type) {
225  rval = kGenbankBlockKeyword;
226  break;
228  rval = "Extra Accession";
229  break;
231  break;
232  }
233  return rval;
234 }
235 
236 
240 
User-defined methods of the data storage class.
CConstRef –.
Definition: ncbiobj.hpp:1266
void ClearVal(CObject &object) override
static EGBBlockFieldType GetTypeForLabel(string label)
bool SetVal(CObject &object, const string &val, EExistingText existing_text) override
vector< string > GetVals(const CObject &object) override
CRef< CStringConstraint > m_StringConstraint
@ eGBBlockFieldType_ExtraAccession
EGBBlockFieldType m_FieldType
static string GetLabelForType(EGBBlockFieldType field_type)
bool IsEmpty(const CObject &object) const override
bool AllowMultipleValues() override
void SetConstraint(const string &field, CConstRef< CStringConstraint > string_constraint) override
bool IsEmpty(void) const
Definition: GB_block.cpp:55
CObject –.
Definition: ncbiobj.hpp:180
bool DoesTextMatch(const string &text)
void Assign(const CStringConstraint &other)
Include a standard set of the NCBI C++ Toolkit most basic headers.
const char * kGenbankBlockKeyword
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
static const char label[]
TKeywords & SetKeywords(void)
Assign a value to Keywords data member.
Definition: GB_block_.hpp:532
bool IsSetExtra_accessions(void) const
Check if a value has been assigned to Extra_accessions data member.
Definition: GB_block_.hpp:442
void ResetKeywords(void)
Reset Keywords data member.
Definition: GB_block_.cpp:63
list< string > TKeywords
Definition: GB_block_.hpp:93
TExtra_accessions & SetExtra_accessions(void)
Assign a value to Extra_accessions data member.
Definition: GB_block_.hpp:460
const TExtra_accessions & GetExtra_accessions(void) const
Get the Extra_accessions member data.
Definition: GB_block_.hpp:454
const TKeywords & GetKeywords(void) const
Get the Keywords member data.
Definition: GB_block_.hpp:526
bool IsSetKeywords(void) const
Check if a value has been assigned to Keywords data member.
Definition: GB_block_.hpp:514
void ResetExtra_accessions(void)
Reset Extra_accessions data member.
Definition: GB_block_.cpp:51
bool IsGenbank(void) const
Check if variant Genbank is selected.
Definition: Seqdesc_.hpp:1090
TGenbank & SetGenbank(void)
Select the variant.
Definition: Seqdesc_.cpp:340
const TGenbank & GetGenbank(void) const
Get the variant data.
Definition: Seqdesc_.cpp:334
int i
Definition: fix_pub.hpp:45
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
EExistingText
@ eExistingText_add_qual
bool AddValueToString(string &str, const string &value, EExistingText existing_text)
Add text to an existing string, using the "existing_text" directive to combine new text with existing...
#define const
Definition: zconf.h:230
Modified on Thu Feb 22 17:12:13 2024 by modify_doxy.py rev. 669887