Loading...
Searching...
No Matches
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>
66
67/*---------------------------------------------------------------------------*\
68 Class errorManip Declaration
69\*---------------------------------------------------------------------------*/
70
71template<class Err>
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
88
89template<class Err>
90inline Ostream& operator<<(Ostream& os, errorManip<Err> m)
91{
92 (m.err_.*m.fPtr_)();
93 return os;
94}
96
97/*---------------------------------------------------------------------------*\
98 Class errorManipArg Declaration
99\*---------------------------------------------------------------------------*/
100
101template<class Err, class T>
102class errorManipArg
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
120
121template<class Err, class T>
123{
124 (m.err_.*m.fPtr_)(m.arg_);
125 return os;
126}
127
128
129// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130
131inline errorManipArg<error, int>
132exit(error& err, const int errNo = 1)
133{
134 return errorManipArg<error, int>(&error::exit, err, errNo);
135}
136
137
138inline errorManipArg<IOerror, int>
139exit(IOerror& err, const int errNo = 1)
140{
141 return errorManipArg<IOerror, int>(&IOerror::exit, err, errNo);
142}
143
144
145inline errorManip<error>
147{
148 return errorManip<error>(&error::abort, err);
149}
150
151
152inline errorManip<IOerror>
153abort(IOerror& err)
154{
155 return errorManip<IOerror>(&IOerror::abort, err);
156}
157
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161} // End namespace Foam
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165#endif
166
167// ************************************************************************* //
Report an I/O error.
Definition error.H:370
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition IOerror.C:240
void abort()
Abort : used to stop code for fatal errors.
Definition IOerror.C:246
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Error stream manipulators for functions with an argument.
Definition errorManip.H:96
friend Ostream & operator(Ostream &os, errorManipArg< Err, T > m)
errorManipArg(void(Err::*fPtr)(const T), Err &t, const T i)
Definition errorManip.H:103
Error stream manipulators for exit and abort which may terminate the program or throw an exception de...
Definition errorManip.H:66
errorManip(void(Err::*fPtr)(), Err &t)
Definition errorManip.H:72
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition error.H:74
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
Definition error.C:352
void abort()
Abort : used to stop code for fatal errors.
Definition error.C:358
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
errorManip< error > abort(error &err)
Definition errorManip.H:139
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)