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

Go to the SVN repository for this file.

1 /* $Id: line_error.cpp 102637 2024-06-17 14:09:43Z 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  * Authors: Aaron Ucko, NCBI
27  *
28  * File Description:
29  * Basic reader interface
30  *
31  * ===========================================================================
32  */
33 
34 #include <ncbi_pch.hpp>
35 
37 
40 
41 // static
43  EProblem eProblem,
44  EDiagSev eSeverity,
45  const std::string& strSeqId,
46  unsigned int uLine,
47  const std::string& strFeatureName,
48  const std::string& strQualifierName,
49  const std::string& strQualifierValue,
50  const std::string& strErrorMessage,
51  const TVecOfLines& vecOfOtherLines)
52 {
53  // this triggers a deprecated-call warning, which should disappear
54  // once the constructors become protected instead of deprecated.
55  return new CLineError(
56  eProblem,
57  eSeverity,
58  strSeqId,
59  uLine,
60  strFeatureName,
61  strQualifierName,
62  strQualifierValue,
63  strErrorMessage,
64  vecOfOtherLines);
65 }
66 
67 void CLineError::Throw(void) const
68 {
69  // this triggers a deprecated-call warning, which should disappear
70  // once the constructors become protected instead of deprecated.
71  throw *this;
72 }
73 
75  EProblem eProblem,
76  EDiagSev eSeverity,
77  const std::string& strSeqId,
78  unsigned int uLine,
79  const std::string& strFeatureName,
80  const std::string& strQualifierName,
81  const std::string& strQualifierValue,
82  const std::string& strErrorMessage,
83  const TVecOfLines& vecOfOtherLines) :
84  m_eProblem(eProblem),
85  m_eSeverity(eSeverity),
86  m_strSeqId(strSeqId),
87  m_uLine(uLine),
88  m_strFeatureName(strFeatureName),
89  m_strQualifierName(strQualifierName),
90  m_strQualifierValue(strQualifierValue),
91  m_strErrorMessage(strErrorMessage),
92  m_vecOfOtherLines(vecOfOtherLines)
93 {
94 }
95 
97  m_eProblem(rhs.m_eProblem),
98  m_eSeverity(rhs.m_eSeverity),
99  m_strSeqId(rhs.m_strSeqId),
100  m_uLine(rhs.m_uLine),
101  m_strFeatureName(rhs.m_strFeatureName),
102  m_strQualifierName(rhs.m_strQualifierName),
103  m_strQualifierValue(rhs.m_strQualifierValue),
104  m_strErrorMessage(rhs.m_strErrorMessage),
105  m_vecOfOtherLines(rhs.m_vecOfOtherLines)
106 {
107 }
108 
109 
110 string ILineError::Message() const
111 {
113  result << "On SeqId '" << SeqId() << "', line " << Line() << ", severity " << SeverityStr() << ": '"
114  << ProblemStr() << "'";
115  if (! FeatureName().empty()) {
116  result << ", with feature name '" << FeatureName() << "'";
117  }
118  if (! QualifierName().empty()) {
119  result << ", with qualifier name '" << QualifierName() << "'";
120  }
121  if (! QualifierValue().empty()) {
122  result << ", with qualifier value '" << QualifierValue() << "'";
123  }
124  if (! OtherLines().empty()) {
125  result << ", with other possibly relevant line(s):";
126  ITERATE (TVecOfLines, line_it, OtherLines()) {
127  result << ' ' << *line_it;
128  }
129  }
130  return (string)CNcbiOstrstreamToString(result);
131 }
132 
133 
135 {
137 }
138 
139 
140 const string& ILineError::ErrorMessage() const
141 {
142  return kEmptyStr;
143 }
144 
145 
147 {
148  return ProblemStr(Problem());
149 }
150 
151 
154 {
155  switch (eProblem) {
156  case eProblem_Unset:
157  return "Unset";
159  return "Unrecognized feature name";
161  return "Unrecognized qualifier name";
163  return "Numeric qualifier value has extra trailing characters after the number";
165  return "Numeric qualifier value should be a number";
167  return "Feature name not allowed";
169  return "No feature provided on intervals";
171  return "No feature provided for qualifiers";
173  return "Feature bad start and/or stop";
175  return "General parsing error";
177  return "Bad feature interval";
179  return "Qualifier had bad value";
181  return "Invalid score value";
183  return "Value ignored due to missing context";
185  return "Bad track line: Expected \"track key1=value1 key2=value2 ...\"";
187  return "Feature's location has internal partials";
189  return "Feature has xref to a gene, but that gene does NOT contain the feature.";
191  return "Feature is trying to create a gene that conflicts with the gene created by another feature.";
193  return "Unrecognized square bracket command";
194  case eProblem_TooLong:
195  return "Feature is too long";
197  return "Nucleotide residues unexpectedly found in feature";
199  return "Amino acid residues unexpectedly found in feature";
201  return "Too many ambiguous residues";
203  return "Invalid residue(s)";
205  return "Modifiers were found where none were expected";
207  return "Extraneous modifiers found";
209  return "Expected modifier missing";
210  case eProblem_Missing:
211  return "Feature is missing";
213  return "Feature's length must be greater than zero.";
215  return "Could not parse modifiers.";
217  return "Multiple different values for modifier";
219  return "Feature had invalid length, but this was automatically corrected.";
221  return "An invalid residue has been ignored";
223  return "Invalid qualifier for feature";
224 
226  return "Broken ##INFO line";
228  return "Broken ##FORMAT line";
230  return "Broken ##FILTER line";
231 
233  return "Just a progress info message (no error)";
234  default:
235  return "Unknown problem";
236  }
237 }
238 
239 
241  CNcbiOstream& out) const
242 {
243 
244  out << " " << SeverityStr() << ":" << endl;
245  out << "Problem: " << ProblemStr() << endl;
246  if (GetCode()) {
247  out << "Code: " << GetCode();
248  if (GetSubCode()) {
249  out << "." << GetSubCode();
250  }
251  out << endl;
252  }
253  const string& seqid = SeqId();
254  if (! seqid.empty()) {
255  out << "SeqId: " << seqid << endl;
256  }
257  if (Line()) {
258  out << "Line: " << Line() << endl;
259  }
260  const string& feature = FeatureName();
261  if (! feature.empty()) {
262  out << "FeatureName: " << feature << endl;
263  }
264  const string& qualname = QualifierName();
265  if (! qualname.empty()) {
266  out << "QualifierName: " << qualname << endl;
267  }
268  const string& qualval = QualifierValue();
269  if (! qualval.empty()) {
270  out << "QualifierValue: " << qualval << endl;
271  }
272  const TVecOfLines& vecOfLines = OtherLines();
273  if (! vecOfLines.empty()) {
274  out << "OtherLines:";
275  ITERATE (TVecOfLines, line_it, vecOfLines) {
276  out << ' ' << *line_it;
277  }
278  out << endl;
279  }
280  out << endl;
281 }
282 
283 
285  CNcbiOstream& out) const
286 {
287  out << "<message severity=\"" << NStr::XmlEncode(SeverityStr()) << "\" "
288  << "problem=\"" << NStr::XmlEncode(ProblemStr()) << "\" ";
289  if (GetCode()) {
290  string code = NStr::IntToString(GetCode());
291  if (GetSubCode()) {
292  code += "." + NStr::IntToString(GetSubCode());
293  }
294  out << "code=\"" << NStr::XmlEncode(code) << "\" ";
295  }
296  const string& seqid = SeqId();
297  if (! seqid.empty()) {
298  out << "seqid=\"" << NStr::XmlEncode(seqid) << "\" ";
299  }
300  out << "line=\"" << Line() << "\" ";
301  const string& feature = FeatureName();
302  if (! feature.empty()) {
303  out << "feature_name=\"" << NStr::XmlEncode(feature) << "\" ";
304  }
305  const string& qualname = QualifierName();
306  if (! qualname.empty()) {
307  out << "qualifier_name=\"" << NStr::XmlEncode(qualname) << "\" ";
308  }
309  const string& qualval = QualifierValue();
310  if (! qualval.empty()) {
311  out << "qualifier_value=\"" << NStr::XmlEncode(qualval) << "\" ";
312  }
313  out << ">";
314 
315  // child nodes
316  ITERATE (TVecOfLines, line_it, OtherLines()) {
317  out << "<other_line>" << *line_it << "</other_line>";
318  }
319 
320  out << "</message>" << endl;
321 }
322 
323 
325 {
326  return new CLineError(*this);
327 }
328 
330  EProblem eProblem,
331  EDiagSev eSeverity,
332  int code,
333  int subcode,
334  const std::string& strSeqId,
335  unsigned int uLine,
336  const std::string& strErrorMessage,
337  const std::string& strFeatureName,
338  const std::string& strQualifierName,
339  const std::string& strQualifierValue,
340  const TVecOfLines& vecOfOtherLines)
341 {
342  // this triggers a deprecated-call warning, which should disappear
343  // once the constructors become protected instead of deprecated.
344  return new CLineErrorEx(
345  eProblem,
346  eSeverity,
347  code,
348  subcode,
349  strSeqId,
350  uLine,
351  strErrorMessage,
352  strFeatureName,
353  strQualifierName,
354  strQualifierValue,
355  vecOfOtherLines);
356 }
357 
358 
359 void CLineErrorEx::Throw(void) const
360 {
361  // this triggers a deprecated-call warning, which should disappear
362  // once the constructors become protected instead of deprecated.
363  throw *this;
364 }
365 
366 
368  EProblem eProblem,
369  EDiagSev eSeverity,
370  int code,
371  int subcode,
372  const std::string& strSeqId,
373  unsigned int uLine,
374  const std::string& strErrorMessage,
375  const std::string& strFeatureName,
376  const std::string& strQualifierName,
377  const std::string& strQualifierValue,
378  const TVecOfLines& vecOfOtherLines) :
379  m_eProblem(eProblem),
380  m_eSeverity(eSeverity),
381  m_Code(code),
382  m_Subcode(subcode),
383  m_strSeqId(strSeqId),
384  m_uLine(uLine),
385  m_strFeatureName(strFeatureName),
386  m_strQualifierName(strQualifierName),
387  m_strQualifierValue(strQualifierValue),
388  m_strErrorMessage(strErrorMessage),
389  m_vecOfOtherLines(vecOfOtherLines)
390 {
391 }
392 
393 
395  CLineErrorEx(rhs.m_eProblem,
396  rhs.m_eSeverity,
397  rhs.m_Code,
398  rhs.m_Subcode,
399  rhs.m_strSeqId,
400  rhs.m_uLine,
401  rhs.m_strErrorMessage,
402  rhs.m_strFeatureName,
403  rhs.m_strQualifierName,
404  rhs.m_strQualifierValue,
405  rhs.m_vecOfOtherLines)
406 {
407 }
408 
409 
411 {
412  return new CLineErrorEx(*this);
413 }
414 
415 
418  EDiagSev eSeverity,
419  unsigned int uLine,
420  const std::string& strMessage,
421  EProblem eProblem,
422  const std::string& strSeqId,
423  const std::string& strFeatureName,
424  const std::string& strQualifierName,
425  const std::string& strQualifierValue,
427  const TVecOfLines& vecOfOtherLines)
428 {
429  // this triggers a deprecated-call warning, which should disappear
430  // once the constructors become protected instead of deprecated.
431  return new CObjReaderLineException(
432  eSeverity, uLine, strMessage, eProblem, strSeqId, strFeatureName, strQualifierName, strQualifierValue, eErrCode, vecOfOtherLines);
433 }
434 
436 {
437  return new CObjReaderLineException(*this);
438 }
439 
441 {
442  // this triggers a deprecated-call warning, which should disappear
443  // once the constructors become protected instead of deprecated.
444  throw *this;
445 }
446 
448  EDiagSev eSeverity,
449  unsigned int uLine,
450  const std::string& strMessage,
451  EProblem eProblem,
452  const std::string& strSeqId,
453  const std::string& strFeatureName,
454  const std::string& strQualifierName,
455  const std::string& strQualifierValue,
457  const TVecOfLines& vecOfOtherLines) :
458  CObjReaderParseException(DIAG_COMPILE_INFO, 0, static_cast<CObjReaderParseException::EErrCode>(CException::eInvalid), strMessage, uLine, eDiag_Info),
459  m_eProblem(eProblem),
460  m_strSeqId(strSeqId),
461  m_uLineNumber(uLine),
462  m_strFeatureName(strFeatureName),
463  m_strQualifierName(strQualifierName),
464  m_strQualifierValue(strQualifierValue),
465  m_strErrorMessage(strMessage),
466  m_vecOfOtherLines(vecOfOtherLines)
467 {
468  SetSeverity(eSeverity);
469  x_InitErrCode(static_cast<CException::EErrCode>(eErrCode));
470 }
471 
474  m_eProblem(rhs.Problem()),
475  m_strSeqId(rhs.SeqId()),
476  m_uLineNumber(rhs.Line()),
477  m_strFeatureName(rhs.FeatureName()),
478  m_strQualifierName(rhs.QualifierName()),
479  m_strQualifierValue(rhs.QualifierValue()),
480  m_strErrorMessage(rhs.ErrorMessage()),
481  m_vecOfOtherLines(rhs.m_vecOfOtherLines),
482  m_pObject(rhs.m_pObject)
483 {
484  SetSeverity(rhs.Severity());
485  x_InitErrCode(static_cast<CException::EErrCode>(rhs.x_GetErrCode()));
486 }
487 
488 // this is here because of an apparent compiler bug
491 {
492  if (! m_strErrorMessage.empty()) {
493  return m_strErrorMessage;
494  }
495  return ILineError::ProblemStr();
496 }
497 
499 {
500  m_pObject = pObject;
501 }
502 
504 {
505  return m_pObject;
506 }
507 
void Throw(void) const
copy constructor is protected so please use this function to throw the object.
Definition: line_error.cpp:359
static CLineErrorEx * Create(EProblem eProblem, EDiagSev eSeverity, int code, int subcode, const std::string &strSeqId, unsigned int uLine, const std::string &strErrorMessage=string(""), const std::string &strFeatureName=string(""), const std::string &strQualifierName=string(""), const std::string &strQualifierValue=string(""), const TVecOfLines &vecOfOtherLines=TVecOfLines())
Use this because the constructor is protected.
Definition: line_error.cpp:329
virtual ILineError * Clone(void) const override
Use this because copy ctor is protected.
Definition: line_error.cpp:410
CLineErrorEx(EProblem eProblem, EDiagSev eSeverity, int code, int subcode, const std::string &strSeqId, unsigned int uLine, const std::string &strErrorMessage, const std::string &strFeatureName, const std::string &strQualifierName, const std::string &strQualifierValue, const TVecOfLines &m_vecOfOtherLine)
protected instead of public. Please use the Create function instead.
Definition: line_error.cpp:367
CLineError(EProblem eProblem, EDiagSev eSeverity, const std::string &strSeqId, unsigned int uLine, const std::string &strFeatureName, const std::string &strQualifierName, const std::string &strQualifierValue, const std::string &strErrorMessage, const TVecOfLines &m_vecOfOtherLine)
protected instead of public. Please use the Create function instead.
Definition: line_error.cpp:74
void Throw(void) const
copy constructor is protected so please use this function to throw the object.
Definition: line_error.cpp:67
virtual ILineError * Clone(void) const
Use this because copy ctor is protected.
Definition: line_error.cpp:324
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
std::string ProblemStr() const
Definition: line_error.cpp:490
CObjReaderLineException(EDiagSev eSeverity, unsigned int uLine, const std::string &strMessage, EProblem eProblem=eProblem_GeneralParsingError, const std::string &strSeqId=string(""), const std::string &strFeatureName=string(""), const std::string &strQualifierName=string(""), const std::string &strQualifierValue=string(""), CObjReaderLineException::EErrCode eErrCode=eFormat, const TVecOfLines &vecOfOtherLines=TVecOfLines())
private instead of public. Please use the Create function instead.
Definition: line_error.cpp:447
CConstRef< CSerialObject > GetObject() const
Definition: line_error.cpp:503
EDiagSev Severity(void) const
Definition: line_error.hpp:439
virtual ILineError * Clone(void) const
Use instead of copy constructor, which is private.
Definition: line_error.cpp:435
void SetObject(CRef< CSerialObject > pObject)
Definition: line_error.cpp:498
void Throw(void) const
this function to throw this object.
Definition: line_error.cpp:440
static CObjReaderLineException * Create(EDiagSev eSeverity, unsigned int uLine, const std::string &strMessage, EProblem eProblem=eProblem_GeneralParsingError, const std::string &strSeqId=string(""), const std::string &strFeatureName=string(""), const std::string &strQualifierName=string(""), const std::string &strQualifierValue=string(""), CObjReaderLineException::EErrCode eErrCode=eFormat, const TVecOfLines &vecOfOtherLines=TVecOfLines())
Please use this instead of the constructor because the ctor is protected.
Definition: line_error.cpp:417
std::string m_strErrorMessage
Definition: line_error.hpp:479
CRef< CSerialObject > m_pObject
Definition: line_error.hpp:481
virtual const string & QualifierName(void) const =0
virtual EDiagSev Severity(void) const
Definition: line_error.hpp:161
virtual string Message() const
Definition: line_error.cpp:110
@ eProblem_InvalidQualifier
Definition: line_error.hpp:91
@ eProblem_BadInfoLine
Definition: line_error.hpp:96
@ eProblem_QualifierBadValue
Definition: line_error.hpp:67
@ eProblem_BadFormatLine
Definition: line_error.hpp:97
@ eProblem_NumericQualifierValueIsNotANumber
Definition: line_error.hpp:60
@ eProblem_InternalPartialsInFeatLocation
Definition: line_error.hpp:71
@ eProblem_InvalidResidue
Definition: line_error.hpp:79
@ eProblem_FeatMustBeInXrefdGene
Definition: line_error.hpp:72
@ eProblem_IgnoredResidue
Definition: line_error.hpp:88
@ eProblem_TooLong
Definition: line_error.hpp:75
@ eProblem_Missing
Definition: line_error.hpp:83
@ eProblem_CreatedGeneFromMultipleFeats
Definition: line_error.hpp:73
@ eProblem_UnrecognizedFeatureName
Definition: line_error.hpp:57
@ eProblem_ParsingModifiers
Definition: line_error.hpp:85
@ eProblem_MissingContext
Definition: line_error.hpp:69
@ eProblem_BadScoreValue
Definition: line_error.hpp:68
@ eProblem_UnexpectedAminoAcids
Definition: line_error.hpp:77
@ eProblem_FeatureNameNotAllowed
Definition: line_error.hpp:61
@ eProblem_BadTrackLine
Definition: line_error.hpp:70
@ eProblem_ModifierFoundButNoneExpected
Definition: line_error.hpp:80
@ eProblem_QualifierWithoutFeature
Definition: line_error.hpp:63
@ eProblem_UnexpectedNucResidues
Definition: line_error.hpp:76
@ eProblem_FeatureBadStartAndOrStop
Definition: line_error.hpp:65
@ eProblem_NumericQualifierValueHasExtraTrailingCharacters
Definition: line_error.hpp:59
@ eProblem_TooManyAmbiguousResidues
Definition: line_error.hpp:78
@ eProblem_UnrecognizedSquareBracketCommand
Definition: line_error.hpp:74
@ eProblem_UnrecognizedQualifierName
Definition: line_error.hpp:58
@ eProblem_BadFilterLine
Definition: line_error.hpp:98
@ eProblem_BadFeatureInterval
Definition: line_error.hpp:66
@ eProblem_NonPositiveLength
Definition: line_error.hpp:84
@ eProblem_ContradictoryModifiers
Definition: line_error.hpp:86
@ eProblem_ExpectedModifierMissing
Definition: line_error.hpp:82
@ eProblem_InvalidLengthAutoCorrected
Definition: line_error.hpp:87
@ eProblem_GeneralParsingError
Definition: line_error.hpp:105
@ eProblem_ExtraModifierFound
Definition: line_error.hpp:81
@ eProblem_NoFeatureProvidedOnIntervals
Definition: line_error.hpp:62
@ eProblem_ProgressInfo
Definition: line_error.hpp:103
vector< unsigned int > TVecOfLines
Definition: line_error.hpp:121
virtual int GetCode(void) const
Definition: line_error.hpp:151
virtual int GetSubCode(void) const
Definition: line_error.hpp:152
string SeverityStr() const
Definition: line_error.cpp:134
virtual void Write(CNcbiOstream &out) const
Definition: line_error.cpp:240
virtual EProblem Problem(void) const =0
virtual string ProblemStr() const
Definition: line_error.cpp:146
virtual const string & SeqId(void) const =0
virtual unsigned int Line(void) const =0
virtual const TVecOfLines & OtherLines(void) const =0
virtual void WriteAsXML(CNcbiOstream &out) const
Definition: line_error.cpp:284
virtual const string & QualifierValue(void) const =0
virtual const string & ErrorMessage() const
Definition: line_error.cpp:140
virtual const string & FeatureName(void) const =0
Definition: svg.hpp:432
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:690
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
Definition: ncbidiag.hpp:170
static const char * SeverityName(EDiagSev sev)
Get a common symbolic name for the severity levels.
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiag_Info
Informational message.
Definition: ncbidiag.hpp:651
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
#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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5078
static string XmlEncode(const CTempString str, TXmlEncode flags=eXmlEnc_Contents)
Encode a string for XML.
Definition: ncbistr.cpp:4027
constexpr bool empty(list< Ts... >) noexcept
Definition: inftrees.h:24
else result
Definition: token2.c:20
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:40 2024 by modify_doxy.py rev. 669887