00001
00002
00003
00004
00005
00006
00007 #ifndef EXCEPTIONMANAGER_H
00008 #define EXCEPTIONMANAGER_H
00009
00010 #include <qvaluevector.h>
00011 #include <qmap.h>
00012 #include <qstring.h>
00013
00014
00015 #define EM_DECLARE(x) int x
00016 #define EM_INIT(x,y) ExceptionManager::em()->init(&x, QString(y))
00017 #define EM_REGISTER(x) ExceptionManager::em()->add(x, true)
00018 #define EM_REGISTER_Q(x) ExceptionManager::em()->add(x, false)
00019 #define EM_REMOVE(x) ExceptionManager::em()->remove(x)
00020 #define EM_RAISE(x) ExceptionManager::em()->raise(x)
00021 #define EM_MATCH(x,y,z) ExceptionManager::em()->isMatch(x,y,QString(z))
00022 #define EM_DESC(x) ExceptionManager::em()->desc(x)
00023 #define EM_IS_PENDING(x) ExceptionManager::em()->isPending(x)
00024 #define EM_THROW_PENDING ExceptionManager::em()->throwPending()
00025
00026 #define EM_BEFORE_PROCESS_EVENTS int _region = ExceptionManager::em()->saveThrowableSet()
00027
00028 #define EM_AFTER_PROCESS_EVENTS ExceptionManager::em()->restoreThrowableSet(_region); \
00029 ExceptionManager::em()->throwPending()
00030
00031 #define EM_PROCESS_EVENTS do { EM_BEFORE_PROCESS_EVENTS; \
00032 qApp->processEvents(); \
00033 EM_AFTER_PROCESS_EVENTS; \
00034 } while (false)
00035
00036 #define EM_PROCESS_EVENTS_NO_INPUT do { EM_BEFORE_PROCESS_EVENTS; \
00037 qApp->processEvents(QEventLoop::ExcludeUserInput); \
00038 EM_AFTER_PROCESS_EVENTS; \
00039 } while (false)
00040
00041 class ExceptionManager {
00042 protected:
00043 ExceptionManager();
00044 ExceptionManager(const ExceptionManager&);
00045 ExceptionManager& operator=(const ExceptionManager&);
00046
00047 public:
00048 static ExceptionManager* em() {
00049 static ExceptionManager private_em;
00050 return &private_em;
00051 }
00052 void init(int* excpId, const QString& desc);
00053 void add(int excpId, bool verbose);
00054 void remove(int excpId);
00055 void raise(int excpId);
00056 void throwPending();
00057 int saveThrowableSet();
00058 void restoreThrowableSet(int regionId);
00059 bool isMatch(int value, int excpId, const QString& context);
00060 const QString desc(int excpId);
00061 bool isPending(int excpId);
00062
00063 private:
00064 int excpId;
00065 int regionId;
00066 int currentRegionId;
00067
00068 class Exception {
00069 public:
00070 Exception() {}
00071 Exception(int ex, bool v) : excpId(ex), verbose(v), isRaised(false) {}
00072 int excpId;
00073 bool verbose;
00074 bool isRaised;
00075 };
00076 typedef QValueList<Exception> ThrowableSet;
00077 typedef ThrowableSet::iterator SetIt;
00078 QMap<int, ThrowableSet> throwableSetMap;
00079 ThrowableSet totalThrowableSet;
00080 ThrowableSet regionThrowableSet;
00081 QValueVector<QString> descriptions;
00082
00083 SetIt findExcp(ThrowableSet& ts, const SetIt& startIt, int excpId);
00084 void setRaisedFlag(ThrowableSet& ts, int excpId);
00085 };
00086
00087 #endif