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

Go to the SVN repository for this file.

1 /* $Id: ValidError.cpp 101346 2023-12-04 15:52:06Z 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: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'valerr.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 #include <objects/seq/Seqdesc.hpp>
40 
41 // generated includes
43 
44 // generated classes
45 
47 
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49 
50 // *********************** CValidError implementation **********************
51 
52 
54  m_Validated(obj)
55 {
56 }
57 
59  EDiagSev sev,
60  unsigned int ec,
61  const string& msg,
62  const string& desc,
63  const CSerialObject& obj,
64  const string& acc,
65  const int ver,
66  const string& location,
67  const int seq_offset)
68 {
69  if (ShouldSuppress(ec)) {
70  return;
71  }
72  CRef<CValidErrItem> item(new CValidErrItem(sev, ec, msg, desc, &obj, nullptr, acc, ver, seq_offset));
73  if (!NStr::IsBlank(location)) {
74  item->SetLocation(location);
75  }
76  SetErrs().push_back(item);
77  m_Stats[item->GetSeverity()]++;
78 }
79 
81  EDiagSev sev,
82  unsigned int ec,
83  const string& msg,
84  const string& desc,
85  const string& acc,
86  const int ver,
87  const string& location,
88  const int seq_offset)
89 {
90  if (ShouldSuppress(ec)) {
91  return;
92  }
93  CRef<CValidErrItem> item(new CValidErrItem(sev, ec, msg, desc, nullptr, nullptr, acc, ver, seq_offset));
94  if (!NStr::IsBlank(location)) {
95  item->SetLocation(location);
96  }
97  SetErrs().push_back(item);
98  m_Stats[item->GetSeverity()]++;
99 }
100 
101 
103  EDiagSev sev,
104  unsigned int ec,
105  const string& msg,
106  const string& desc,
107  const CSeqdesc& seqdesc,
108  const CSeq_entry& ctx,
109  const string& acc,
110  const int ver,
111  const int seq_offset)
112 {
113  if (ShouldSuppress(ec)) {
114  return;
115  }
116  CRef<CValidErrItem> item(new CValidErrItem(sev, ec, msg, desc, &seqdesc, &ctx, acc, ver, seq_offset));
117  SetErrs().push_back(item);
118  m_Stats[item->GetSeverity()]++;
119 }
120 
121 
122 void CValidError::AddValidErrItem(EDiagSev sev, unsigned int ec, const string& msg)
123 {
124  if (ShouldSuppress(ec)) {
125  return;
126  }
128  item->SetSev(sev);
129  item->SetErrIndex(ec);
130  item->SetMsg(msg);
131  item->SetErrorName(CValidErrItem::ConvertErrCode(ec));
132  item->SetErrorGroup(CValidErrItem::ConvertErrGroup(ec));
133 
134  SetErrs().push_back(item);
135  m_Stats[item->GetSeverity()]++;
136 }
137 
138 
140 {
141  if (!item || !item->IsSetErrIndex()) {
142  return;
143  }
144  if (ShouldSuppress(item->GetErrIndex())) {
145  return;
146  }
147  if (!item->IsSetSev()) {
148  item->SetSev(eDiag_Info);
149  }
150  item->SetErrorName(CValidErrItem::ConvertErrCode(item->GetErrIndex()));
151  item->SetErrorGroup(CValidErrItem::ConvertErrGroup(item->GetErrIndex()));
152  SetErrs().push_back(item);
153  m_Stats[item->GetSeverity()]++;
154 }
155 
156 
157 void CValidError::SuppressError(unsigned int ec)
158 {
159  m_SuppressionList.push_back(ec);
160  sort(m_SuppressionList.begin(), m_SuppressionList.end());
161  unique(m_SuppressionList.begin(), m_SuppressionList.end());
162 }
163 
164 
165 bool CValidError::ShouldSuppress(unsigned int ec)
166 {
167  vector<unsigned int>::iterator present = find (m_SuppressionList.begin(), m_SuppressionList.end(), ec);
168  if (present != m_SuppressionList.end() && *present == ec) {
169  return true;
170  } else {
171  return false;
172  }
173 }
174 
175 
177 {
178  m_SuppressionList.clear();
179 }
180 
181 
183 {
184 }
185 
186 
188 {
189  // Note:
190  // This function primarily serves as a loop terminator in the validator-
191  // if the error is catastrophic then don't attempt to read anything else
192  // and terminate with as much digity as possible.
193  // What counts as catastrophic is somewhat murky. Invalid ASN.1 qualifies.
194  // Error level eSev_critical alone does *not*.
195  // Feel free to amend with any other conditions that are discovered and verified
196  // to truly be catastrophic (verification: TeamCity tests).
197  //
198  for (const auto& errorItem: GetErrs()) {
199  if (errorItem->IsSetErrorName() && errorItem->GetErrorName() == "InvalidAsn") {
200  return true;
201  }
202  }
203  return false;
204 }
205 
206 
207 // ************************ CValidError_CI implementation **************
208 
210  m_Validator(0),
211  m_ErrCodeFilter(kEmptyStr), // eErr_UNKNOWN
212  m_MinSeverity(eDiagSevMin),
213  m_MaxSeverity(eDiagSevMax)
214 {
215 }
216 
217 
219  const CValidError& ve,
220  const string& errcode,
221  EDiagSev minsev,
222  EDiagSev maxsev) :
223  m_Validator(&ve),
224  m_Current(ve.GetErrs().begin()),
225  m_ErrCodeFilter(errcode),
226  m_MinSeverity(minsev),
227  m_MaxSeverity(maxsev)
228 {
229  if (IsValid() && ! Filter(**m_Current)) {
230  Next();
231  }
232 }
233 
234 
236 {
237  if ( this != &other ) {
238  *this = other;
239  }
240 }
241 
242 
244 {
245 }
246 
247 
249 {
250  if (this == &iter) {
251  return *this;
252  }
253 
254  m_Validator = iter.m_Validator;
255  m_Current = iter.m_Current;
259  return *this;
260 }
261 
262 
264 {
265  Next();
266  return *this;
267 }
268 
269 
270 bool CValidError_CI::IsValid(void) const
271 {
272  return m_Current != m_Validator->GetErrs().end();
273 }
274 
275 
277 {
278  return **m_Current;
279 }
280 
281 
283 {
284  return &(**m_Current);
285 }
286 
287 
288 bool CValidError_CI::Filter(const CValidErrItem& item) const
289 {
290  EDiagSev item_sev = (*m_Current)->GetSeverity();
291  if ( (m_ErrCodeFilter.empty() ||
293  ((item_sev >= m_MinSeverity) && (item_sev <= m_MaxSeverity)) ) {
294  return true;;
295  }
296  return false;
297 }
298 
299 
301 {
302  if ( AtEnd() ) {
303  return;
304  }
305 
306  do {
307  ++m_Current;
308  } while ( !AtEnd() && !Filter(**m_Current) );
309 }
310 
311 
312 bool CValidError_CI::AtEnd(void) const
313 {
314  return m_Current == m_Validator->GetErrs().end();
315 }
316 
317 
318 END_objects_SCOPE // namespace ncbi::objects::
319 
321 
322 /* Original file checksum: lines: 64, chars: 1869, CRC32: b677bbc2 */
User-defined methods of the data storage class.
CRef –.
Definition: ncbiobj.hpp:618
Definition: Seq_entry.hpp:56
Base class for all serializable objects.
Definition: serialbase.hpp:150
static const string & ConvertErrCode(unsigned int)
const string GetErrCode() const
static const string & ConvertErrGroup(unsigned int)
bool AtEnd() const
Definition: ValidError.cpp:312
bool Filter(const CValidErrItem &item) const
Definition: ValidError.cpp:288
CValidError_CI & operator++()
Definition: ValidError.cpp:263
EDiagSev m_MinSeverity
Definition: ValidError.hpp:224
CValidError_CI & operator=(const CValidError_CI &iter)
Definition: ValidError.cpp:248
CConstRef< CValidError > m_Validator
Definition: ValidError.hpp:219
string m_ErrCodeFilter
Definition: ValidError.hpp:223
const CValidErrItem & operator*() const
Definition: ValidError.cpp:276
EDiagSev m_MaxSeverity
Definition: ValidError.hpp:225
const CValidErrItem * operator->() const
Definition: ValidError.cpp:282
bool IsValid() const
Definition: ValidError.cpp:270
CValidError::TErrs::const_iterator m_Current
Definition: ValidError.hpp:220
virtual ~CValidError_CI()
Definition: ValidError.cpp:243
CValidError(const CSerialObject *obj=nullptr)
Definition: ValidError.cpp:53
void SuppressError(unsigned int ec)
Definition: ValidError.cpp:157
bool ShouldSuppress(unsigned int ec)
Definition: ValidError.cpp:165
TSevStats m_Stats
Definition: ValidError.hpp:182
void ClearSuppressions()
Definition: ValidError.cpp:176
bool IsCatastrophic() const
Definition: ValidError.cpp:187
vector< unsigned int > m_SuppressionList
Definition: ValidError.hpp:184
void AddValidErrItem(EDiagSev sev, unsigned int ec, const string &msg, const string &desc, const CSerialObject &obj, const string &acc, const int ver, const string &location=kEmptyStr, const int seq_offset=0) final
Definition: ValidError.cpp:58
virtual ~CValidError()
Definition: ValidError.cpp:182
CS_CONTEXT * ctx
Definition: t0006.c:12
static const char location[]
Definition: config.c:97
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
@ eDiagSevMin
Verbosity level for min. severity.
Definition: ncbidiag.hpp:660
@ eDiagSevMax
Verbosity level for max. severity.
Definition: ncbidiag.hpp:661
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
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 StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
const TErrs & GetErrs(void) const
Get the Errs member data.
TErrs & SetErrs(void)
Assign a value to Errs data member.
constexpr auto sort(_Init &&init)
Modified on Fri Jun 14 16:52:34 2024 by modify_doxy.py rev. 669887