GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException_xml.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException_xml.cpp - XML exception handlers *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2011 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GException_xml.cpp
23  * @brief Implement exceptions for the XML module
24  * @author J. Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 
34 
35 /***********************************************************************//**
36  * @brief XML syntax error
37  *
38  * @param[in] origin Method that throws the error.
39  * @param[in] segment XML segment for which syntax error was encountered.
40  * @param[in] message Optional error message.
41  ***************************************************************************/
43  std::string segment,
44  std::string message)
45 {
46  // Set origin and message
47  m_origin = origin;
48 
49  // Set message
50  m_message = "XML syntax error ("+message+")";
51 
52  // Set segment
53  if (segment.length() > 0) {
54  m_message += " occured in " + segment;
55  }
56 
57  // Return
58  return;
59 }
60 
61 
62 /***********************************************************************//**
63  * @brief Invalid XML attribute value
64  *
65  * @param[in] origin Method that throws the error.
66  * @param[in] value XML attribute value.
67  ***************************************************************************/
69  std::string value)
70 {
71  // Set origin and message
72  m_origin = origin;
73  m_message = "Invalid XML attribute value: "+value;
74 
75  // Return
76  return;
77 }
78 
79 
80 /***********************************************************************//**
81  * @brief Invalid XML node type
82  *
83  * @param[in] origin Method that throws the error.
84  * @param[in] type XML node type.
85  * @param[in] message Optional error message.
86  ***************************************************************************/
88  std::string type,
89  std::string message)
90 {
91  // Set origin and message
92  m_origin = origin;
93  m_message = "Invalid XML node type ("+type+").";
94  if (message.length() > 0) {
95  m_message += " " + message;
96  }
97 
98  // Return
99  return;
100 }
101 
102 
103 /***********************************************************************//**
104  * @brief XML element name not found
105  *
106  * @param[in] origin Method that throws the error.
107  * @param[in] name XML element name.
108  * @param[in] message Optional error message.
109  ***************************************************************************/
111  std::string name,
112  std::string message)
113 {
114  // Set origin and message
115  m_origin = origin;
116  m_message = "XML element name \""+name+"\" not found.";
117  if (message.length() > 0) {
118  m_message += " " + message;
119  }
120 
121  // Return
122  return;
123 }
124 
125 
126 /***********************************************************************//**
127  * @brief Invalid number of parameters in XML element
128  *
129  * @param[in] origin Method that throws the error.
130  * @param[in] xml XML element.
131  * @param[in] message Optional error message.
132  ***************************************************************************/
134  GXmlElement xml,
135  std::string message)
136 {
137  // Set origin and message
138  m_origin = origin;
139  m_message = "Invalid number of parameters found in XML element.";
140  if (message.length() > 0) {
141  m_message += " " + message;
142  }
143 
144  // Return
145  return;
146 }
147 
148 
149 /***********************************************************************//**
150  * @brief Invalid parameter names in XML element
151  *
152  * @param[in] origin Method that throws the error.
153  * @param[in] xml XML element.
154  * @param[in] message Optional error message.
155  ***************************************************************************/
157  GXmlElement xml,
158  std::string message)
159 {
160  // Set origin and message
161  m_origin = origin;
162  m_message = "Invalid parameter names found in XML element." ;
163  if (message.length() > 0) {
164  m_message += " " + message;
165  }
166 
167  // Return
168  return;
169 }
170 
171 
xml_bad_node_type(std::string origin, std::string type, std::string message="")
Invalid XML node type.
XML element node class.
Definition: GXmlElement.hpp:48
Gammalib tools definition.
xml_syntax_error(std::string origin, std::string segment, std::string message="")
XML syntax error.
xml_attribute_value(std::string origin, std::string value)
Invalid XML attribute value.
std::string m_message
Definition: GException.hpp:51
xml_invalid_parnames(std::string origin, GXmlElement xml, std::string message="")
Invalid parameter names in XML element.
xml_invalid_parnum(std::string origin, GXmlElement xml, std::string message="")
Invalid number of parameters in XML element.
Exception handler interface definition.
std::string m_origin
Definition: GException.hpp:50
xml_name_not_found(std::string origin, std::string type, std::string message="")
XML element name not found.