OMNeT++ NEDXML  6.0.3
errorstore.h
Go to the documentation of this file.
1 //==========================================================================
2 // errorstore.h -
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 //==========================================================================
8 
9 /*--------------------------------------------------------------*
10  Copyright (C) 2002-2017 Andras Varga
11  Copyright (C) 2006-2017 OpenSim Ltd.
12 
13  This file is distributed WITHOUT ANY WARRANTY. See the file
14  `license' for details on this and other legal matters.
15 *--------------------------------------------------------------*/
16 
17 #ifndef __OMNETPP_NEDXML_ERRORSTORE_H
18 #define __OMNETPP_NEDXML_ERRORSTORE_H
19 
20 #include <vector>
21 #include <exception>
22 #include <stdexcept>
23 #include <string>
24 #include "nedxmldefs.h"
25 
26 namespace omnetpp {
27 namespace nedxml {
28 
29 class ASTNode;
30 
31 // Note: this cannot be inner type because of swig wrapping
33 
38 {
39  private:
40  struct Entry {
41  ASTNode *context;
42  int severity;
43  std::string location;
44  std::string message;
45  };
46 
47  std::vector<Entry> entries;
48  bool doprint;
49 
50  private:
51  void doAdd(ASTNode *context, const char *loc, int severity, const char *message);
52 
53  public:
57  ErrorStore() {doprint = false;}
59 
63  void setPrintToStderr(bool p) {doprint = p;}
64 
68  _OPP_GNU_ATTRIBUTE(format(printf, 3, 4))
69  void addError(ASTNode *context, const char *messagefmt, ...);
70 
74  _OPP_GNU_ATTRIBUTE(format(printf, 3, 4))
75  void addError(const char *location, const char *messagefmt, ...);
76 
80  _OPP_GNU_ATTRIBUTE(format(printf, 3, 4))
81  void addWarning(ASTNode *context, const char *messagefmt, ...);
82 
86  _OPP_GNU_ATTRIBUTE(format(printf, 3, 4))
87  void addWarning(const char *location, const char *messagefmt, ...);
88 
92  _OPP_GNU_ATTRIBUTE(format(printf, 4, 5))
93  void add(ASTNode *context, int severity, const char *messagefmt, ...);
94 
98  _OPP_GNU_ATTRIBUTE(format(printf, 4, 5))
99  void add(const char *location, int severity, const char *messagefmt, ...);
100 
104  bool empty() const {return entries.empty();}
105 
109  int numMessages() const {return entries.size();}
110 
114  bool containsError() const;
115 
119  void clear() {entries.clear();}
120 
123  const char *errorSeverity(int i) const;
124  int errorSeverityCode(int i) const;
125  const char *errorLocation(int i) const;
126  ASTNode *errorContext(int i) const;
127  const char *errorText(int i) const;
129 
134  int findFirstErrorFor(ASTNode *node, int startIndex) const;
135 
139  static const char *severityName(int severity);
140 };
141 
142 
143 #define INTERNAL_ERROR0(context,msg) NedInternalError(__FILE__,__LINE__,context,msg)
144 #define INTERNAL_ERROR1(context,msg,arg1) NedInternalError(__FILE__,__LINE__,context,msg,arg1)
145 #define INTERNAL_ERROR2(context,msg,arg1,arg2) NedInternalError(__FILE__,__LINE__,context,msg,arg1,arg2)
146 #define INTERNAL_ERROR3(context,msg,arg1,arg2,arg3) NedInternalError(__FILE__,__LINE__,context,msg,arg1,arg2,arg3)
147 
153 _OPP_GNU_ATTRIBUTE(format(printf, 4, 5))
154 void NedInternalError(const char *file, int line, ASTNode *context, const char *messagefmt, ...);
155 
156 
157 } // namespace nedxml
158 } // namespace omnetpp
159 
160 
161 #endif
162 
omnetpp::nedxml::ErrorStore::clear
void clear()
Definition: errorstore.h:119
omnetpp::nedxml::ErrorStore::setPrintToStderr
void setPrintToStderr(bool p)
Definition: errorstore.h:63
omnetpp::nedxml::NedInternalError
void NedInternalError(const char *file, int line, ASTNode *context, const char *messagefmt,...)
NEDXML_API
#define NEDXML_API
Definition: nedxmldefs.h:31
omnetpp
Definition: astbuilder.h:25
omnetpp::nedxml::ASTNode
Definition: astnode.h:87
omnetpp::nedxml::SEVERITY_ERROR
@ SEVERITY_ERROR
Definition: errorstore.h:32
omnetpp::nedxml::ErrorStore::numMessages
int numMessages() const
Definition: errorstore.h:109
omnetpp::nedxml::ErrorStore::~ErrorStore
~ErrorStore()
Definition: errorstore.h:58
omnetpp::nedxml::SEVERITY_INFO
@ SEVERITY_INFO
Definition: errorstore.h:32
omnetpp::nedxml::ProblemSeverity
ProblemSeverity
Definition: errorstore.h:32
nedxmldefs.h
omnetpp::nedxml::ErrorStore
Definition: errorstore.h:37
omnetpp::nedxml::SEVERITY_WARNING
@ SEVERITY_WARNING
Definition: errorstore.h:32
omnetpp::nedxml::ErrorStore::ErrorStore
ErrorStore()
Definition: errorstore.h:57