1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Error stream manipulators for exit and abort which may terminate the
30 program or throw an exception depending if the exception
31 handling has been switched on (off by default).
35 error << "message1" << "message2" << FoamDataType << exit(error, errNo);
36 error << "message1" << "message2" << FoamDataType << abort(error);
39 \*---------------------------------------------------------------------------*/
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // Forward declaration of friend functions and operators
53 template<class Err> class errorManip;
54 template<class Err> Ostream& operator<<(Ostream&, errorManip<Err>);
56 template<class Err, class T> class errorManipArg;
57 template<class Err, class T>
58 Ostream& operator<<(Ostream&, errorManipArg<Err, T>);
61 /*---------------------------------------------------------------------------*\
62 Class errorManip Declaration
63 \*---------------------------------------------------------------------------*/
73 errorManip(void (Err::*fPtr)(), Err& t)
79 friend Ostream& operator<< <Err>(Ostream& os, errorManip<Err> m);
84 inline Ostream& operator<<(Ostream& os, errorManip<Err> m)
91 /*---------------------------------------------------------------------------*\
92 Class errorManipArg Declaration
93 \*---------------------------------------------------------------------------*/
96 template<class Err, class T>
99 void (Err::*fPtr_)(const T);
105 errorManipArg(void (Err::*fPtr)(const T), Err& t, const T i)
112 friend Ostream& operator<< <Err, T>(Ostream& os, errorManipArg<Err, T> m);
116 template<class Err, class T>
117 inline Ostream& operator<<(Ostream& os, errorManipArg<Err, T> m)
119 (m.err_.*m.fPtr_)(m.arg_);
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 inline errorManipArg<error, int> exit(error& err, const int errNo = 1)
128 return errorManipArg<error, int>(&error::exit, err, errNo);
131 inline errorManip<error> abort(error& err)
133 return errorManip<error>(&error::abort, err);
137 inline errorManipArg<IOerror, int> exit(IOerror& err, const int errNo = 1)
139 return errorManipArg<IOerror, int>(&IOerror::exit, err, errNo);
142 inline errorManip<IOerror> abort(IOerror& err)
144 return errorManip<IOerror>(&IOerror::abort, err);
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 } // End namespace Foam
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 // ************************************************************************* //