CocoParserErrors.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::CocoParserErrors
26 
27 Description
28  Templated class to shadow the error handling for Coco/R parsers
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef CocoParserErrors_H
33 #define CocoParserErrors_H
34 
35 #include "error.H"
36 #include "wchar.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 /*---------------------------------------------------------------------------*\
44  Class CocoParserErrors Declaration
45 \*---------------------------------------------------------------------------*/
46 
47 template<class BaseClass, class StringClass=std::wstring>
48 class CocoParserErrors
49 :
50  public BaseClass
51 {
52  // Private data
53 
54  //- The name issued in warnings and errors
55  word name_;
56 
57 public:
58 
59  // Constructors
60 
61  //- Construct with given name
62  CocoParserErrors(const word& name)
63  :
64  BaseClass(),
65  name_(name)
66  {}
67 
68 
69  //- Destructor
70  virtual ~CocoParserErrors()
71  {}
72 
73 
74  // Member functions
75 
76  //- Return the name issued for warnings
77  virtual const word& name() const
78  {
79  return name_;
80  }
81 
82  //- Return the name issued for warnings
83  virtual word& name()
84  {
85  return name_;
86  }
87 
88 
89  // Error Handling
90 
91  //- Handle a general warning 'msg'
92  virtual void Warning(const StringClass& msg)
93  {
94  WarningIn(name_)
95  << msg << endl;
96  }
97 
98  //- Handle a general warning 'msg'
99  virtual void Warning(int line, int col, const StringClass& msg)
100  {
101  WarningIn(name_)
102  <<"line " << line << " col " << col << ": "
103  << msg << endl;
104  }
105 
106  //- Handle general error 'msg' (eg, a semantic error)
107  virtual void Error(int line, int col, const StringClass& msg)
108  {
109  FatalErrorIn(name_)
110  << "line " << line << " col " << col <<": " << msg << endl
111  << exit(FatalError);
112  }
113 
114  //- Handle general error 'msg' (eg, a semantic error)
115  virtual void Error(const StringClass& msg)
116  {
117  FatalErrorIn(name_)
118  << msg << endl
119  << exit(FatalError);
120  }
121 
122  //- Handle a general exception 'msg'
123  virtual void Exception(const StringClass& msg)
124  {
125  this->Error(msg);
126  }
127 
128 };
129 
130 
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 } // End namespace Foam
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 #endif
139 
140 // ************************************************************************* //
virtual void Error(int line, int col, const StringClass &msg)
Handle general error &#39;msg&#39; (eg, a semantic error)
virtual const word & name() const
Return the name issued for warnings.
virtual void Exception(const StringClass &msg)
Handle a general exception &#39;msg&#39;.
A class for handling words, derived from string.
Definition: word.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual void Warning(const StringClass &msg)
Handle a general warning &#39;msg&#39;.
Namespace for OpenFOAM.
A line primitive.
Definition: line.H:56
CocoParserErrors(const word &name)
Construct with given name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Templated class to shadow the error handling for Coco/R parsers.
A wide-character and a pointer to a wide-character string.
virtual ~CocoParserErrors()
Destructor.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
error FatalError