1 /* $Id: ValidError.cpp 538191 2017-06-08 13:45:09Z bollin $
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
42 #include <objects/valerr/ValidError.hpp>
43
44 // generated classes
45
46 BEGIN_NCBI_SCOPE
47
48 BEGIN_objects_SCOPE // namespace ncbi::objects::
49
50 // *********************** CValidError implementation **********************
51
52
CValidError(const CSerialObject * obj)53 CValidError::CValidError(const CSerialObject* obj) :
54 m_Validated(obj)
55 {
56 }
57
AddValidErrItem(EDiagSev sev,unsigned int ec,const string & msg,const string & desc,const CSerialObject & obj,const string & acc,const int ver,const string & location,const int seq_offset)58 void CValidError::AddValidErrItem
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, 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
80
AddValidErrItem(EDiagSev sev,unsigned int ec,const string & msg,const string & desc,const CSerialObject & obj,const string & acc,const int ver,const string & feature_id,const string & location,const int seq_offset)81 void CValidError::AddValidErrItem
82 (EDiagSev sev,
83 unsigned int ec,
84 const string& msg,
85 const string& desc,
86 const CSerialObject& obj,
87 const string& acc,
88 const int ver,
89 const string& feature_id,
90 const string& location,
91 const int seq_offset)
92 {
93 if (ShouldSuppress(ec)) {
94 return;
95 }
96 CRef<CValidErrItem> item(new CValidErrItem(sev, ec, msg, desc, obj, acc, ver, feature_id, seq_offset));
97 if (!NStr::IsBlank(location)) {
98 item->SetLocation(location);
99 }
100 SetErrs().push_back(item);
101 m_Stats[item->GetSeverity()]++;
102 }
103
104
AddValidErrItem(EDiagSev sev,unsigned int ec,const string & msg,const string & desc,const CSeqdesc & seqdesc,const CSeq_entry & ctx,const string & acc,const int ver,const int seq_offset)105 void CValidError::AddValidErrItem
106 (EDiagSev sev,
107 unsigned int ec,
108 const string& msg,
109 const string& desc,
110 const CSeqdesc& seqdesc,
111 const CSeq_entry& ctx,
112 const string& acc,
113 const int ver,
114 const int seq_offset)
115 {
116 if (ShouldSuppress(ec)) {
117 return;
118 }
119 CRef<CValidErrItem> item(new CValidErrItem(sev, ec, msg, desc, seqdesc, ctx, acc, ver, seq_offset));
120 SetErrs().push_back(item);
121 m_Stats[item->GetSeverity()]++;
122 }
123
124
AddValidErrItem(EDiagSev sev,unsigned int ec,const string & msg)125 void CValidError::AddValidErrItem(EDiagSev sev, unsigned int ec, const string& msg)
126 {
127 if (ShouldSuppress(ec)) {
128 return;
129 }
130 CRef<CValidErrItem> item(new CValidErrItem());
131 item->SetSev(sev);
132 item->SetErrIndex(ec);
133 item->SetMsg(msg);
134 item->SetErrorName(CValidErrItem::ConvertErrCode(ec));
135 item->SetErrorGroup(CValidErrItem::ConvertErrGroup(ec));
136
137 SetErrs().push_back(item);
138 m_Stats[item->GetSeverity()]++;
139 }
140
141
AddValidErrItem(CRef<CValidErrItem> item)142 void CValidError::AddValidErrItem(CRef<CValidErrItem> item)
143 {
144 if (!item || !item->IsSetErrIndex()) {
145 return;
146 }
147 if (ShouldSuppress(item->GetErrIndex())) {
148 return;
149 }
150 if (!item->IsSetSev()) {
151 item->SetSev(eDiag_Info);
152 }
153 item->SetErrorName(CValidErrItem::ConvertErrCode(item->GetErrIndex()));
154 item->SetErrorGroup(CValidErrItem::ConvertErrGroup(item->GetErrIndex()));
155 SetErrs().push_back(item);
156 m_Stats[item->GetSeverity()]++;
157 }
158
159
SuppressError(unsigned int ec)160 void CValidError::SuppressError(unsigned int ec)
161 {
162 m_SuppressionList.push_back(ec);
163 sort(m_SuppressionList.begin(), m_SuppressionList.end());
164 unique(m_SuppressionList.begin(), m_SuppressionList.end());
165 }
166
167
ShouldSuppress(unsigned int ec)168 bool CValidError::ShouldSuppress(unsigned int ec)
169 {
170 vector<unsigned int>::iterator present = find (m_SuppressionList.begin(), m_SuppressionList.end(), ec);
171 if (present != m_SuppressionList.end() && *present == ec) {
172 return true;
173 } else {
174 return false;
175 }
176 }
177
178
ClearSuppressions()179 void CValidError::ClearSuppressions()
180 {
181 m_SuppressionList.clear();
182 }
183
184
~CValidError()185 CValidError::~CValidError()
186 {
187 }
188
189
190 // ************************ CValidError_CI implementation **************
191
CValidError_CI(void)192 CValidError_CI::CValidError_CI(void) :
193 m_Validator(0),
194 m_ErrCodeFilter(kEmptyStr), // eErr_UNKNOWN
195 m_MinSeverity(eDiagSevMin),
196 m_MaxSeverity(eDiagSevMax)
197 {
198 }
199
200
CValidError_CI(const CValidError & ve,const string & errcode,EDiagSev minsev,EDiagSev maxsev)201 CValidError_CI::CValidError_CI
202 (const CValidError& ve,
203 const string& errcode,
204 EDiagSev minsev,
205 EDiagSev maxsev) :
206 m_Validator(&ve),
207 m_Current(ve.GetErrs().begin()),
208 m_ErrCodeFilter(errcode),
209 m_MinSeverity(minsev),
210 m_MaxSeverity(maxsev)
211 {
212 if ( IsValid() && !Filter(**m_Current) ) {
213 Next();
214 }
215 }
216
217
CValidError_CI(const CValidError_CI & other)218 CValidError_CI::CValidError_CI(const CValidError_CI& other)
219 {
220 if ( this != &other ) {
221 *this = other;
222 }
223 }
224
225
~CValidError_CI(void)226 CValidError_CI::~CValidError_CI(void)
227 {
228 }
229
230
operator =(const CValidError_CI & iter)231 CValidError_CI& CValidError_CI::operator=(const CValidError_CI& iter)
232 {
233 if (this == &iter) {
234 return *this;
235 }
236
237 m_Validator = iter.m_Validator;
238 m_Current = iter.m_Current;
239 m_ErrCodeFilter = iter.m_ErrCodeFilter;
240 m_MinSeverity = iter.m_MinSeverity;
241 m_MaxSeverity = iter.m_MaxSeverity;
242 return *this;
243 }
244
245
operator ++(void)246 CValidError_CI& CValidError_CI::operator++(void)
247 {
248 Next();
249 return *this;
250 }
251
252
IsValid(void) const253 bool CValidError_CI::IsValid(void) const
254 {
255 return m_Current != m_Validator->GetErrs().end();
256 }
257
258
operator *(void) const259 const CValidErrItem& CValidError_CI::operator*(void) const
260 {
261 return **m_Current;
262 }
263
264
operator ->(void) const265 const CValidErrItem* CValidError_CI::operator->(void) const
266 {
267 return &(**m_Current);
268 }
269
270
Filter(const CValidErrItem & item) const271 bool CValidError_CI::Filter(const CValidErrItem& item) const
272 {
273 EDiagSev item_sev = (*m_Current)->GetSeverity();
274 if ( (m_ErrCodeFilter.empty() ||
275 NStr::StartsWith(item.GetErrCode(), m_ErrCodeFilter)) &&
276 ((item_sev >= m_MinSeverity) && (item_sev <= m_MaxSeverity)) ) {
277 return true;;
278 }
279 return false;
280 }
281
282
Next(void)283 void CValidError_CI::Next(void)
284 {
285 if ( AtEnd() ) {
286 return;
287 }
288
289 do {
290 ++m_Current;
291 } while ( !AtEnd() && !Filter(**m_Current) );
292 }
293
294
AtEnd(void) const295 bool CValidError_CI::AtEnd(void) const
296 {
297 return m_Current == m_Validator->GetErrs().end();
298 }
299
300
301 END_objects_SCOPE // namespace ncbi::objects::
302
303 END_NCBI_SCOPE
304
305 /* Original file checksum: lines: 64, chars: 1869, CRC32: b677bbc2 */
306