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

Go to the SVN repository for this file.

1 /* $Id: validerror_suppress.cpp 102322 2024-04-23 12:29:28Z foleyjp $
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: Justin Foley, Colleen Bollin......
27  *
28  * File Description:
29  * Methods to facilitate runtime suppression of validation errors
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <objects/seq/Bioseq.hpp>
36 #include <objects/seq/Seqdesc.hpp>
47 
48 
51 BEGIN_SCOPE(validator)
52 
53 
54 
55 static const string kSuppressFieldLabel = "Suppress";
56 
58 {
59  return (field.IsSetLabel() &&
60  field.GetLabel().IsStr() &&
61  NStr::EqualNocase(field.GetLabel().GetStr(), kSuppressFieldLabel));
62 }
63 
64 
66 {
67  if (user.IsSetData()) {
68  for (auto pUserField : user.SetData()) {
69  if (s_IsSuppressField(*pUserField)) {
70  if (pUserField->IsSetData()) {
71  if (pUserField->GetData().IsInt()) {
72  const auto old_val = pUserField->GetData().GetInt();
73  if (old_val != error_code) {
74  pUserField->SetData().SetInts().push_back(old_val);
75  pUserField->SetData().SetInts().push_back(error_code);
76  }
77  return;
78  } else if (pUserField->GetData().IsInts()) {
79  const auto& ints = pUserField->GetData().GetInts();
80  if (find(ints.cbegin(), ints.cend(), error_code) == ints.cend()) {
81  pUserField->SetData().SetInts().push_back(error_code);
82  }
83  return;
84  }
85  }
86  }
87  }
88  }
89 
90  CRef<CUser_field> pField(new CUser_field());
91  pField->SetLabel().SetStr(kSuppressFieldLabel);
92  pField->SetData().SetInts().push_back(error_code);
93  user.SetData().push_back(pField);
94 }
95 
96 
97 
99 {
100  if (!user.IsSetData()) {
101  return;
102  }
103 
104  for (const auto& pUserField : user.GetData()) {
105  if (pUserField->IsSetData() && s_IsSuppressField(*pUserField)) {
106  if (pUserField->GetData().IsInt()) {
107  errCodes.insert(pUserField->GetData().GetInt());
108  } else if (pUserField->GetData().IsInts()) {
109  for (const auto& code : pUserField->GetData().GetInts()) {
110  errCodes.insert(code);
111  }
112  } else if (pUserField->GetData().IsStr()) {
113  unsigned int ec = CValidErrItem::ConvertToErrCode(pUserField->GetData().GetStr());
114  if (ec != eErr_MAX) {
115  errCodes.insert(ec);
116  }
117  } else if (pUserField->GetData().IsStrs()) {
118  for (const auto& errStr : pUserField->GetData().GetStrs()) {
119  unsigned int ec = CValidErrItem::ConvertToErrCode(errStr);
120  if (ec != eErr_MAX) {
121  errCodes.insert(ec);
122  }
123  }
124  }
125  }
126  }
127 }
128 
129 
131 {
132  if (se.IsSeq()) {
133  SetSuppressedCodes(se.GetSeq(), errCodes);
134  } else if (se.IsSet()) {
135  const CBioseq_set& set = se.GetSet();
136  if (set.IsSetDescr()) {
137  for (const auto& pDesc : set.GetDescr().Get()) {
138  if (pDesc->IsUser() &&
139  pDesc->GetUser().GetObjectType() == CUser_object::eObjectType_ValidationSuppression) {
140  SetSuppressedCodes(pDesc->GetUser(), errCodes);
141  }
142  }
143  }
144  if (set.IsSetSeq_set()) {
145  for (const auto& pEntry : set.GetSeq_set()) {
146  SetSuppressedCodes(*pEntry, errCodes);
147  }
148  }
149  }
150 }
151 
152 
154 {
155  SetSuppressedCodes(*(se.GetCompleteSeq_entry()), errCodes);
156 }
157 
158 
160 {
161  if (ss.IsEntrys()) {
162  for (const auto& pEntry : ss.GetData().GetEntrys()) {
163  SetSuppressedCodes(*pEntry, errCodes);
164  }
165  }
166 }
167 
168 
170 {
171  if (seq.IsSetDescr()) {
172  for (const auto& pDesc : seq.GetDescr().Get()) {
173  if (pDesc->IsUser() &&
174  pDesc->GetUser().GetObjectType() == CUser_object::eObjectType_ValidationSuppression) {
175  SetSuppressedCodes(pDesc->GetUser(), errCodes);
176  }
177  }
178  }
179 }
180 
181 
182 
183 
184 END_SCOPE(validator)
187 
#define static
User-defined methods of the data storage class.
@ eErr_MAX
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
bool IsEntrys(void) const
Definition: Seq_submit.cpp:54
@ eObjectType_ValidationSuppression
static unsigned int ConvertToErrCode(const string &str)
static void AddSuppression(CUser_object &user, TErrCode errCode)
CValidErrItem::TErrIndex TErrCode
static void SetSuppressedCodes(const CUser_object &user, TCodes &errCodes)
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
Include a standard set of the NCBI C++ Toolkit most basic headers.
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
#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 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:5347
bool IsSetData(void) const
the object itself Check if a value has been assigned to Data data member.
TData & SetData(void)
Assign a value to Data data member.
void SetLabel(TLabel &value)
Assign a value to Label data member.
const TData & GetData(void) const
Get the Data member data.
void SetData(TData &value)
Assign a value to Data data member.
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
const Tdata & Get(void) const
Get the member data.
Definition: Seq_descr_.hpp:166
bool IsSetDescr(void) const
descriptors Check if a value has been assigned to Descr data member.
Definition: Bioseq_.hpp:303
const TDescr & GetDescr(void) const
Get the Descr member data.
Definition: Bioseq_.hpp:315
const TEntrys & GetEntrys(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
The Object manager core.
Definition: inftrees.h:24
static const string kSuppressFieldLabel
static bool s_IsSuppressField(const CUser_field &field)
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:27 2024 by modify_doxy.py rev. 669887