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

Go to the SVN repository for this file.

1 /* $Id: errors.cpp 99402 2023-03-22 18:09:14Z satskyse $
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: Sergey Satskiy, NCBI
27  * Credits: Denis Vakatov, NCBI (help with the original design)
28  *
29  */
30 
31 
32 /** @file
33  * Various XML parser's and validator's errors related code for XmlWrapp.
34 **/
35 
36 #include <misc/xmlwrapp/errors.hpp>
38 
39 using namespace xml;
40 
41 
42 // xml::error_message class implementation
44  switch (mt) {
45  case type_fatal_error: return std::string("fatal error");
46  case type_error: return std::string("error");
47  case type_warning: return std::string("warning");
48  default: ;
49  }
50  throw xml::exception("unknown message type");
51 }
52 
54  message_type msg_type,
55  long line, const std::string& filename) :
56  message_type_(msg_type), message_(message),
57  line_(line), filename_(filename)
58 {}
59 
61  return message_type_;
62 }
63 
65  return message_;
66 }
67 
68 
69 long error_message::get_line (void) const {
70  return line_;
71 }
72 
74  return filename_;
75 }
76 
78  message_type_(other.message_type_),
79  message_(std::move(other.message_)),
80  line_(other.line_),
81  filename_(std::move(other.filename_))
82 {}
83 
85 {
86  if (this != &other) {
87  message_type_ = other.message_type_;
88  message_ = std::move(other.message_);
89  line_ = other.line_;
90  filename_ = std::move(other.filename_);
91  }
92  return *this;
93 }
94 
95 
96 // xml::error_messages class implementation
99 {
100  return error_messages_;
101 }
102 
104  return error_messages_;
105 }
106 
107 bool
109 {
110  error_messages_type::const_iterator end(error_messages_.end());
111  for (error_messages_type::const_iterator k(error_messages_.begin());
112  k != end; ++k)
113  if (k->get_message_type() == type)
114  return true;
115  return false;
116 }
117 
118 bool error_messages::has_warnings (void) const {
120 }
121 
122 bool error_messages::has_errors (void) const {
124 }
125 
128 }
129 
131 {
133  try {
134  error_messages_type::const_iterator begin(error_messages_.begin());
135  error_messages_type::const_iterator end(error_messages_.end());
136  for (error_messages_type::const_iterator k(begin); k != end; ++k) {
137  if (k != begin) buffer += std::string( "\n" );
138  buffer += error_message::message_type_str(k->get_message_type()) +
139  ": " + k->get_message();
140  }
141  }
142  catch (...)
143  {}
144  return buffer;
145 }
146 
148 {
149  for (error_messages_type::const_iterator k = other.get_messages().begin();
150  k != other.get_messages().end(); ++k)
151  error_messages_.push_back(*k);
152 }
153 
154 
155 // xml::parser_exception class implementation
157  messages_(msgs)
158 {}
159 
160 const char* parser_exception::what() const throw() {
161  buffer = messages_.print();
162  return buffer.c_str();
163 }
164 
166  return messages_;
167 }
The xml::error_message class is used to store a single error message which may appear while parsing o...
Definition: errors.hpp:50
std::string get_message(void) const
Get the error message.
Definition: errors.cpp:64
message_type
A type for different type of errors.
Definition: errors.hpp:53
@ type_fatal_error
fatal error
Definition: errors.hpp:54
@ type_warning
warning
Definition: errors.hpp:56
@ type_error
error
Definition: errors.hpp:55
message_type message_type_
Definition: errors.hpp:124
error_message & operator=(const error_message &&other)
Moving assignment.
Definition: errors.cpp:84
error_message(const std::string &message, message_type msg_type, long line, const std::string &filename)
Create a new xml::error_message object.
Definition: errors.cpp:53
std::string filename_
Definition: errors.hpp:127
std::string get_filename(void) const
Get the file name.
Definition: errors.cpp:73
static std::string message_type_str(message_type mt)
Convert an error type to a string.
Definition: errors.cpp:43
std::string message_
Definition: errors.hpp:125
long get_line(void) const
Get the line number.
Definition: errors.cpp:69
message_type get_message_type(void) const
Get the error message type.
Definition: errors.cpp:60
The xml::error_messages class is used to store all the error message which are collected while parsin...
Definition: errors.hpp:137
void append_messages(const error_messages &other)
Appends the messages from the other container.
Definition: errors.cpp:147
bool has_fatal_errors(void) const
Check if there are fatal errors in the error messages.
Definition: errors.cpp:126
const error_messages_type & get_messages(void) const
Get the error messages.
Definition: errors.cpp:98
std::list< error_message > error_messages_type
A type to store multiple messages.
Definition: errors.hpp:140
bool has_warnings(void) const
Check if there are warnings in the error messages.
Definition: errors.cpp:118
bool has_errors(void) const
Check if there are errors in the error messages.
Definition: errors.cpp:122
std::string print(void) const
Convert error messages into a single printable string.
Definition: errors.cpp:130
error_messages_type error_messages_
Definition: errors.hpp:202
bool has_messages_of_type(error_message::message_type type) const
Definition: errors.cpp:108
This exception class is thrown by xmlwrapp for all runtime XML-related errors along with the xml::par...
Definition: exception.hpp:64
virtual const char * what() const noexcept
Convert error messages into a printable C-style string.
Definition: errors.cpp:160
error_messages messages_
Definition: errors.hpp:253
parser_exception(const error_messages &msgs)
Create a new object using the given list of error messages.
Definition: errors.cpp:156
const error_messages & get_messages(void) const
Get error messages.
Definition: errors.cpp:165
std::string buffer
Definition: errors.hpp:254
Various XML parser's and validator's errors related code for XmlWrapp.
string
Definition: cgiapp.hpp:690
This file contains the definition of the xml::exception class.
XML library namespace.
Definition: attributes.hpp:57
static uint8_t * buffer
Definition: pcre2test.c:1016
Definition: type.c:6
Modified on Fri Sep 20 14:57:31 2024 by modify_doxy.py rev. 669887