2 Author: Marco Costalba (C) 2005-2007
4 Copyright: See COPYING file that comes with this distribution
7 #ifndef EXCEPTIONMANAGER_H
8 #define EXCEPTIONMANAGER_H
14 // exception manager sugar macro
15 #define EM_DECLARE(x) int x
16 #define EM_INIT(x,y) ExceptionManager::em()->init(&x, QString(y))
17 #define EM_REGISTER(x) ExceptionManager::em()->add(x, true)
18 #define EM_REGISTER_Q(x) ExceptionManager::em()->add(x, false)
19 #define EM_REMOVE(x) ExceptionManager::em()->remove(x)
20 #define EM_RAISE(x) ExceptionManager::em()->raise(x)
21 #define EM_MATCH(x,y,z) ExceptionManager::em()->isMatch(x,y,QString(z))
22 #define EM_DESC(x) ExceptionManager::em()->desc(x)
23 #define EM_IS_PENDING(x) ExceptionManager::em()->isPending(x)
24 #define EM_THROW_PENDING ExceptionManager::em()->throwPending()
26 #define EM_BEFORE_PROCESS_EVENTS int _region = ExceptionManager::em()->saveThrowableSet()
28 #define EM_AFTER_PROCESS_EVENTS ExceptionManager::em()->restoreThrowableSet(_region); \
29 ExceptionManager::em()->throwPending()
31 #define EM_PROCESS_EVENTS do { EM_BEFORE_PROCESS_EVENTS; \
32 qApp->processEvents(); \
33 EM_AFTER_PROCESS_EVENTS; \
36 #define EM_PROCESS_EVENTS_NO_INPUT do { EM_BEFORE_PROCESS_EVENTS; \
37 qApp->processEvents(QEventLoop::ExcludeUserInputEvents); \
38 EM_AFTER_PROCESS_EVENTS; \
41 class ExceptionManager
{ // singleton class
44 ExceptionManager(const ExceptionManager
&);
45 ExceptionManager
& operator=(const ExceptionManager
&);
48 static ExceptionManager
* em() {
49 static ExceptionManager private_em
;
52 void init(int* excpId
, const QString
& desc
);
53 void add(int excpId
, bool verbose
);
54 void remove(int excpId
);
55 void raise(int excpId
);
57 int saveThrowableSet();
58 void restoreThrowableSet(int regionId
);
59 bool isMatch(int value
, int excpId
, const QString
& context
);
60 const QString
desc(int excpId
);
61 bool isPending(int excpId
);
71 Exception(int ex
, bool v
) : excpId(ex
), verbose(v
), isRaised(false) {}
76 typedef QList
<Exception
> ThrowableSet
;
77 typedef ThrowableSet::iterator SetIt
;
78 QMap
<int, ThrowableSet
> throwableSetMap
;
79 ThrowableSet totalThrowableSet
;
80 ThrowableSet regionThrowableSet
;
81 QVector
<QString
> descriptions
;
83 SetIt
findExcp(ThrowableSet
& ts
, const SetIt
& startIt
, int excpId
);
84 void setRaisedFlag(ThrowableSet
& ts
, int excpId
);