-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContratException.h
102 lines (87 loc) · 2.38 KB
/
ContratException.h
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
/**
* \file ContratException.h
* \brief Fichier contenant la déclaration de la classe ContratException et de ses héritiers
* \author administrateur
* \date 16 janvier 2014
* \version révisée balises Doxygen C++ normes H2014
*/
#ifndef CONTRATEXCEPTION_H_DEJA_INCLU
#define CONTRATEXCEPTION_H_DEJA_INCLU
#include <string>
#include <stdexcept>
/**
* \class ContratException
* \brief Classe de base des exceptions de contrat.
*/
class ContratException: public std::logic_error
{
public:
ContratException(std::string, unsigned int, std::string, std::string);
~ContratException() throw ()
{
}
;
std::string reqTexteException() const;
private:
std::string m_expression;
std::string m_fichier;
unsigned int m_ligne;
};
/**
* \class AssertionException
* \brief Classe pour la gestion des erreurs d'assertion.
*/
class AssertionException: public ContratException
{
public:
AssertionException(std::string, unsigned int, std::string);
};
/**
* \class PreconditionException
* \brief Classe pour la gestion des erreurs de précondition.
*/
class PreconditionException: public ContratException
{
public:
PreconditionException(std::string, unsigned int, std::string);
};
/**
* \class PostconditionException
* \brief Classe pour la gestion des erreurs de postcondition.
*/
class PostconditionException: public ContratException
{
public:
PostconditionException(std::string, unsigned int, std::string);
};
/**
* \class InvariantException
* \brief Classe pour la gestion des erreurs d'invariant.
*/
class InvariantException: public ContratException
{
public:
InvariantException(std::string, unsigned int, std::string);
};
// --- Définition des macros de contrôle de la théorie du contrat
#if !defined(NDEBUG)
// --- Mode debug
# define INVARIANTS() \
verifieInvariant()
# define ASSERTION(f) \
if (!(f)) throw AssertionException(__FILE__,__LINE__, #f);
# define PRECONDITION(f) \
if (!(f)) throw PreconditionException(__FILE__, __LINE__, #f);
# define POSTCONDITION(f) \
if (!(f)) throw PostconditionException(__FILE__, __LINE__, #f);
# define INVARIANT(f) \
if (!(f)) throw InvariantException(__FILE__,__LINE__, #f);
// --- LE MODE RELEASE
#else
# define PRECONDITION(f);
# define POSTCONDITION(f);
# define INVARIANTS();
# define INVARIANT(f);
# define ASSERTION(f);
#endif // --- if !defined (NDEBUG)
#endif // --- ifndef CONTRATEXCEPTION_H_DEJA_INCLU