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
25namespace plask {
26
27class 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
37struct PLASK_API XMLWriterException: public std::runtime_error {
41 XMLWriterException(const std::string& msg): std::runtime_error(msg) {}
42};
43
47struct 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
84 XMLUnexpectedAttrException(const XMLReader& reader, const std::string& attr_name):
85 XMLException(reader, "tag has unexpected attribute '" + attr_name + "'") {}
86};
87
96 XMLNoAttrException(const XMLReader& reader, const std::string& attr_name):
97 XMLException(reader, "tag has no required attribute '" + attr_name + "'") {}
98};
99
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
128 XMLException(reader, "unexpected end of data") {}
129};
130
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
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
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