PLaSK library

Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1/*
2 * This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3 * Copyright (c) 2022 Lodz University of Technology
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14#ifndef PLASK__UTILS_XML_EXCEPTIONS_H
15#define PLASK__UTILS_XML_EXCEPTIONS_H
16
21#include <stdexcept>
22#include "../format.hpp"
23#include "../string.hpp"
24
25 namespace plask {
26
27 class XMLReader;
28
29#ifdef _MSC_VER
30#pragma warning(push)
31#pragma warning( disable : 4275 ) // Disable MSVC warnings "non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'"
32#endif
33
37 struct PLASK_API XMLWriterException: public std::runtime_error {
41 XMLWriterException(const std::string& msg): std::runtime_error(msg) {}
42};
43
47 struct PLASK_API XMLException: public std::runtime_error {
48
49 const int line;
50
55 XMLException(const XMLReader& reader, const std::string& msg);
56
62 XMLException(const std::string& where, const std::string& msg, int line = -1);
63
68 XMLException(const std::string& msg, int line = -1);
69
70};
71
72#ifdef _MSC_VER
73#pragma warning(pop)
74#endif
75
79 struct PLASK_API XMLUnexpectedAttrException: public XMLException {
84 XMLUnexpectedAttrException(const XMLReader& reader, const std::string& attr_name):
85 XMLException(reader, "tag has unexpected attribute '" + attr_name + "'") {}
86};
87
91 struct PLASK_API XMLNoAttrException: public XMLException {
96 XMLNoAttrException(const XMLReader& reader, const std::string& attr_name):
97 XMLException(reader, "tag has no required attribute '" + attr_name + "'") {}
98};
99
103 struct PLASK_API XMLBadAttrException: public XMLException {
109 XMLBadAttrException(const XMLReader& reader, const std::string& attr_name, const std::string& attr_value):
110 XMLException(reader, "tag attribute '" + attr_name + "' has bad value \"" + attr_value + "\"") {}
111
118 XMLBadAttrException(const XMLReader& reader, const std::string& attr_name, const std::string& attr_value, const std::string& attr_required):
119 XMLException(reader, "tag attribute '" + attr_name + "' has bad value \"" + attr_value + "\", required was " + attr_required) {}
120
121};
122
126 struct PLASK_API XMLUnexpectedEndException: public XMLException {
127 XMLUnexpectedEndException(const XMLReader& reader):
128 XMLException(reader, "unexpected end of data") {}
129};
130
134 struct PLASK_API XMLUnexpectedElementException: public XMLException {
139 XMLUnexpectedElementException(const XMLReader& reader, const std::string& what_is_expected);
140
146 XMLUnexpectedElementException(const XMLReader& reader, const std::string& what_is_expected, const std::string& what_is_got):
147 XMLException(reader, "expected " + what_is_expected + ", got " + what_is_got + " instead") {}
148};
149
153 struct PLASK_API XMLDuplicatedElementException: public XMLException {
158 XMLDuplicatedElementException(const XMLReader& reader, const std::string& duplicated):
159 XMLException(reader, duplicated + " should appear only once in the current scope") {}
164 XMLDuplicatedElementException(const std::string& parent, const std::string& duplicated):
165 XMLException(parent, duplicated + " should appear only once in the current scope") {}
166};
167
171 struct PLASK_API XMLConflictingAttributesException: public XMLException {
177 XMLConflictingAttributesException(const XMLReader& reader, const std::string& attr1, const std::string& attr2)
178 : XMLException(reader, "conflicting attributes '" + attr1 + "' and '" + attr2 + "'") {}
179};
180
181
182} // namespace plask
183
184#endif //PLASK__UTILS_XML_EXCEPTIONS_H