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-2015 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  {
95  << msg << endl;
96  }
97 
98  //- Handle a general warning 'msg'
99  virtual void Warning(int line, int col, const StringClass& msg)
100  {
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  {
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  {
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 // ************************************************************************* //
Foam::CocoParserErrors
Templated class to shadow the error handling for Coco/R parsers.
Definition: CocoParserErrors.H:47
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::CocoParserErrors::Warning
virtual void Warning(int line, int col, const StringClass &msg)
Handle a general warning 'msg'.
Definition: CocoParserErrors.H:98
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::CocoParserErrors::~CocoParserErrors
virtual ~CocoParserErrors()
Destructor.
Definition: CocoParserErrors.H:69
Foam::CocoParserErrors::Error
virtual void Error(int line, int col, const StringClass &msg)
Handle general error 'msg' (eg, a semantic error)
Definition: CocoParserErrors.H:106
error.H
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
wchar.H
A wide-character and a pointer to a wide-character string.
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::CocoParserErrors::name_
word name_
The name issued in warnings and errors.
Definition: CocoParserErrors.H:54
Foam::CocoParserErrors::CocoParserErrors
CocoParserErrors(const word &name)
Construct with given name.
Definition: CocoParserErrors.H:61
Foam::CocoParserErrors::Exception
virtual void Exception(const StringClass &msg)
Handle a general exception 'msg'.
Definition: CocoParserErrors.H:122
Foam::line
A line primitive.
Definition: line.H:56
Foam::CocoParserErrors::Error
virtual void Error(const StringClass &msg)
Handle general error 'msg' (eg, a semantic error)
Definition: CocoParserErrors.H:114
Foam::CocoParserErrors::Warning
virtual void Warning(const StringClass &msg)
Handle a general warning 'msg'.
Definition: CocoParserErrors.H:91
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::CocoParserErrors::name
virtual const word & name() const
Return the name issued for warnings.
Definition: CocoParserErrors.H:76
Foam::CocoParserErrors::name
virtual word & name()
Return the name issued for warnings.
Definition: CocoParserErrors.H:82