00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __NEDERROR_H
00018 #define __NEDERROR_H
00019
00020 #include <vector>
00021 #include <exception>
00022 #include <stdexcept>
00023 #include <string>
00024 #include "nedxmldefs.h"
00025
00026 NAMESPACE_BEGIN
00027
00028 class NEDElement;
00029
00030
00031 enum NEDErrorSeverity {NED_SEVERITY_INFO, NED_SEVERITY_WARNING, NED_SEVERITY_ERROR};
00032
00036 class NEDXML_API NEDErrorStore
00037 {
00038 private:
00039 struct Entry {
00040 NEDElement *context;
00041 int severity;
00042 std::string location;
00043 std::string message;
00044 };
00045
00046 std::vector<Entry> entries;
00047 bool doprint;
00048
00049 private:
00050 void doAdd(NEDElement *context, const char *loc, int severity, const char *message);
00051
00052 public:
00056 NEDErrorStore() {doprint = false;}
00057 ~NEDErrorStore() {}
00058
00062 void setPrintToStderr(bool p) {doprint = p;}
00063
00067 void addError(NEDElement *context, const char *messagefmt, ...);
00068
00072 void addError(const char *location, const char *messagefmt, ...);
00073
00077 void addWarning(NEDElement *context, const char *messagefmt, ...);
00078
00082 void addWarning(const char *location, const char *messagefmt, ...);
00083
00087 void add(NEDElement *context, int severity, const char *messagefmt, ...);
00088
00092 void add(const char *location, int severity, const char *messagefmt, ...);
00093
00097 bool empty() const {return entries.empty();}
00098
00102 int numMessages() const {return entries.size();}
00103
00107 bool containsError() const;
00108
00112 void clear() {entries.clear();}
00113
00116 const char *errorSeverity(int i) const;
00117 int errorSeverityCode(int i) const;
00118 const char *errorLocation(int i) const;
00119 NEDElement *errorContext(int i) const;
00120 const char *errorText(int i) const;
00122
00127 int findFirstErrorFor(NEDElement *node, int startIndex) const;
00128
00132 static const char *severityName(int severity);
00133 };
00134
00135
00136 #define INTERNAL_ERROR0(context,msg) NEDInternalError(__FILE__,__LINE__,context,msg)
00137 #define INTERNAL_ERROR1(context,msg,arg1) NEDInternalError(__FILE__,__LINE__,context,msg,arg1)
00138 #define INTERNAL_ERROR2(context,msg,arg1,arg2) NEDInternalError(__FILE__,__LINE__,context,msg,arg1,arg2)
00139 #define INTERNAL_ERROR3(context,msg,arg1,arg2,arg3) NEDInternalError(__FILE__,__LINE__,context,msg,arg1,arg2,arg3)
00140
00146 void NEDInternalError(const char *file, int line, NEDElement *context, const char *messagefmt, ...);
00147
00148
00149 NAMESPACE_END
00150
00151
00152 #endif
00153