errorManip.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::errorManip
28
29Description
30 Error stream manipulators for exit and abort which may terminate the
31 program or throw an exception depending if the exception
32 handling has been switched on (off by default).
33
34Usage
35 \code
36 error << "message " << someType << abort(error);
37 error << "message " << someType << exit(error, errNo);
38 \endcode
39
40Class
41 Foam::errorManipArg
42
43Description
44 Error stream manipulators for functions with an argument.
45
46\*---------------------------------------------------------------------------*/
47
48#ifndef errorManip_H
49#define errorManip_H
50
51#include "error.H"
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54
55namespace Foam
56{
57
58// Forward Declarations
59template<class Err> class errorManip;
60template<class Err> Ostream& operator<<(Ostream&, errorManip<Err>);
61
62template<class Err, class T> class errorManipArg;
63template<class Err, class T>
64Ostream& operator<<(Ostream&, errorManipArg<Err, T>);
65
66
67/*---------------------------------------------------------------------------*\
68 Class errorManip Declaration
69\*---------------------------------------------------------------------------*/
71template<class Err>
72class errorManip
73{
74 void (Err::*fPtr_)();
75 Err& err_;
76
77public:
78
79 errorManip(void (Err::*fPtr)(), Err& t)
80 :
81 fPtr_(fPtr),
82 err_(t)
83 {}
84
85 friend Ostream& operator<< <Err>(Ostream& os, errorManip<Err> m);
86};
87
89template<class Err>
91{
92 (m.err_.*m.fPtr_)();
93 return os;
94}
95
96
97/*---------------------------------------------------------------------------*\
98 Class errorManipArg Declaration
99\*---------------------------------------------------------------------------*/
101template<class Err, class T>
102class errorManipArg
103{
104 void (Err::*fPtr_)(const T);
105 Err& err_;
106 T arg_;
107
108public:
109
110 errorManipArg(void (Err::*fPtr)(const T), Err& t, const T i)
111 :
112 fPtr_(fPtr),
113 err_(t),
114 arg_(i)
115 {}
116
117 friend Ostream& operator<< <Err, T>(Ostream& os, errorManipArg<Err, T> m);
118};
119
121template<class Err, class T>
123{
124 (m.err_.*m.fPtr_)(m.arg_);
125 return os;
126}
127
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132exit(error& err, const int errNo = 1)
133{
134 return errorManipArg<error, int>(&error::exit, err, errNo);
135}
136
139exit(IOerror& err, const int errNo = 1)
140{
141 return errorManipArg<IOerror, int>(&IOerror::exit, err, errNo);
142}
143
146abort(error& err)
147{
148 return errorManip<error>(&error::abort, err);
149}
150
153abort(IOerror& err)
154{
156}
157
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161} // End namespace Foam
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165#endif
166
167// ************************************************************************* //
Report an I/O error.
Definition: error.H:282
void exit()
Job end with "exit" termination.
Definition: JobInfo.C:234
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Error stream manipulators for functions with an argument.
Definition: errorManip.H:101
errorManipArg(void(Err::*fPtr)(const T), Err &t, const T i)
Definition: errorManip.H:108
Error stream manipulators for exit and abort which may terminate the program or throw an exception de...
Definition: errorManip.H:71
errorManip(void(Err::*fPtr)(), Err &t)
Definition: errorManip.H:77
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:77
Watches for presence of the named trigger file in the case directory and signals a simulation stop (o...
Definition: abort.H:128
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
errorManip< error > abort(error &err)
Definition: errorManip.H:144
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130