FIX issue #19 where multiple widget values led to bad replacements in the command
[qgit4/redivivus.git] / src / exceptionmanager.h
blobe60d79612a7bc9597d60bc9b24102e6f0ec1eb44
1 /*
2 Author: Marco Costalba (C) 2005-2007
4 Copyright: See COPYING file that comes with this distribution
6 */
7 #ifndef EXCEPTIONMANAGER_H
8 #define EXCEPTIONMANAGER_H
10 #include <QVector>
11 #include <QString>
12 #include <QMap>
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; \
34 } while (false)
36 #define EM_PROCESS_EVENTS_NO_INPUT do { EM_BEFORE_PROCESS_EVENTS; \
37 qApp->processEvents(QEventLoop::ExcludeUserInputEvents); \
38 EM_AFTER_PROCESS_EVENTS; \
39 } while (false)
41 class ExceptionManager { // singleton class
42 protected:
43 ExceptionManager();
44 ExceptionManager(const ExceptionManager&);
45 ExceptionManager& operator=(const ExceptionManager&);
47 public:
48 static ExceptionManager* em() {
49 static ExceptionManager private_em;
50 return &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);
56 void throwPending();
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);
63 private:
64 int excpId;
65 int regionId;
66 int currentRegionId;
68 class Exception {
69 public:
70 Exception() {}
71 Exception(int ex, bool v) : excpId(ex), verbose(v), isRaised(false) {}
72 int excpId;
73 bool verbose;
74 bool isRaised;
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);
87 #endif