-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException_Handling.h
More file actions
130 lines (113 loc) · 4.16 KB
/
Exception_Handling.h
File metadata and controls
130 lines (113 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// Created by simonepanzeri on 25/11/2021.
//
#ifndef DEV_FDAPDE_EXCEPTION_HANDLING_H
#define DEV_FDAPDE_EXCEPTION_HANDLING_H
#include "FdaPDE.h"
#include "Bounding_Box.h"
#include "Mesh_Objects.h"
/** \class TreeException
*
* All exceptions thrown from the adtree library are derived from the base class TreeException.
*/
template<class Shape>
class TreeException {};
/** \class TreeLogicError
*
* This class is used to report a logic error concerning the tree, i.e. an error that, at least
* in theory, could be avoided by the program; for example, by performing additional tests of function arguments.
*/
template<class Shape>
class TreeLogicError : public TreeException<Shape> {};
/** \class TreeAlloc
*
* This class is used to report the exception condition in which there is no more space in the tree to store a new node.
*/
template<class Shape>
class TreeAlloc : public TreeLogicError<Shape> {};
/** \class TreeDomainError
*
* This class is used to report the exception condition in which an object is out of domain.
*/
template<class Shape>
class TreeDomainError : public TreeLogicError<Shape> {
protected:
//! Number of logical locations currently used in the tree plus 1.
int nelep1;
//! Size of the array storing the coordinates of the object which is out of domain.
int csize;
//! Coordinates of the object which is out of domain.
std::vector<Real> outobj;
public:
//! A constructor.
TreeDomainError(int const& np1, int const& size, std::vector<Real> const coord);
//! A method returning the number of logical locations currently used in the tree plus 1.
inline int getnelep1() const { return nelep1; }
//! Output operator
template<class T>
friend std::ostream& operator<<(std::ostream& ostr, TreeDomainError<T> const& de);
};
template<class Shape>
TreeDomainError<Shape>::TreeDomainError(int const& np1, int const& size, std::vector<Real> const coord) :
nelep1(np1), csize(size) {
outobj = coord;
}
template<class Shape>
std::ostream& operator<<(std::ostream& ostr, TreeDomainError<Shape> const& de) {
for(int i = 0; i < de.csize; ++i) {
ostr << "Coordinate " << i+1 << ": " << de.outobj[i] << std::endl;
}
return ostr;
}
/** \class TreeLengthError
*
* This class is used to report an attempt to do something that exceeds a maximum allowable size
* concerning the tree.
*/
template<class Shape>
class TreeLengthError : public TreeLogicError<Shape> {};
/** \class LocLengthError
* \brief This class is used to report an attempt to build a tree with more memory locations than a fixed limit.
*/
template<class Shape>
class LocLengthError : public TreeLengthError<Shape> {
protected:
//! Maximum tree memory locations available.
int max_tree_loc;
//! Tree memory locations needed.
int tree_loc;
public:
/** A constructor.
*
* Initialize the number of the required tree locations.
*/
LocLengthError(int const & mtree, int const & ntree): max_tree_loc(mtree), tree_loc(ntree) {}
//! A method to get the maximum number of tree memory locations available.
inline int const getmaxtreeloc() const { return max_tree_loc; }
//! A method to get the number of tree memory locations needed.
inline int const gettreeloc() const { return tree_loc; }
};
/** \class TreeRuntimeError
*
* Exceptions derived from runtime_error are provided to report events that are beyond the
* scope of a program and are not easily avoidable.
*/
template<class Shape>
class TreeRuntimeError : public TreeException<Shape> {};
/** \class LevRuntimeError
* \brief This class is used to report an attempt to build a tree with more levels than a fixed limit.
*/
template<class Shape>
class LevRuntimeError : public TreeRuntimeError<Shape> {
protected:
//! Maximum tree levels.
static int max_tree_lev;
public:
//! A method to set the maximum number of tree levels.
inline static void setmaxtreelev(int const& mlev) { max_tree_lev = mlev; }
//! A method to get the maximum number of tree levels.
inline static int getmaxtreelev() { return max_tree_lev; }
};
template<class Shape>
int LevRuntimeError<Shape>::max_tree_lev = 1.e3;
#endif //DEV_FDAPDE_EXCEPTION_HANDLING_H