nederror.h

Go to the documentation of this file.
00001 //==========================================================================
00002 // nederror.h  -
00003 //
00004 //                     OMNeT++/OMNEST
00005 //            Discrete System Simulation in C++
00006 //
00007 //==========================================================================
00008 
00009 /*--------------------------------------------------------------*
00010   Copyright (C) 2002-2008 Andras Varga
00011   Copyright (C) 2006-2008 OpenSim Ltd.
00012 
00013   This file is distributed WITHOUT ANY WARRANTY. See the file
00014   `license' for details on this and other legal matters.
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 // Note: this cannot be inner type because of swig wrapping
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 
Generated on Tue Dec 2 11:16:31 2014 for OMNeT++ NEDXML by  doxygen 1.6.3