1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Error stream manipulators for exit and abort which may terminate the
29 program or throw an exception depending if the exception
30 handling has been switched on (off by default).
34 error << "message1" << "message2" << FoamDataType << exit(error, errNo);
35 error << "message1" << "message2" << FoamDataType << abort(error);
38 \*---------------------------------------------------------------------------*/
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // Forward declaration of friend functions and operators
51 template<class Err> class errorManip;
52 template<class Err> Ostream& operator<<(Ostream&, errorManip<Err>);
54 template<class Err, class T> class errorManipArg;
55 template<class Err, class T>
56 Ostream& operator<<(Ostream&, errorManipArg<Err, T>);
59 /*---------------------------------------------------------------------------*\
60 Class errorManip Declaration
61 \*---------------------------------------------------------------------------*/
71 errorManip(void (Err::*fPtr)(), Err& t)
77 friend Ostream& operator<< <Err>(Ostream& os, errorManip<Err> m);
82 inline Ostream& operator<<(Ostream& os, errorManip<Err> m)
89 /*---------------------------------------------------------------------------*\
90 Class errorManipArg Declaration
91 \*---------------------------------------------------------------------------*/
94 template<class Err, class T>
97 void (Err::*fPtr_)(const T);
103 errorManipArg(void (Err::*fPtr)(const T), Err& t, const T i)
110 friend Ostream& operator<< <Err, T>(Ostream& os, errorManipArg<Err, T> m);
114 template<class Err, class T>
115 inline Ostream& operator<<(Ostream& os, errorManipArg<Err, T> m)
117 (m.err_.*m.fPtr_)(m.arg_);
122 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 inline errorManipArg<error, int>
125 exit(error& err, const int errNo = 1)
127 return errorManipArg<error, int>(&error::exit, err, errNo);
131 inline errorManip<error>
134 return errorManip<error>(&error::abort, err);
138 inline errorManipArg<IOerror, int>
139 exit(IOerror& err, const int errNo = 1)
141 return errorManipArg<IOerror, int>(&IOerror::exit, err, errNo);
145 inline errorManip<IOerror>
148 return errorManip<IOerror>(&IOerror::abort, err);
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 } // End namespace Foam
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 // ************************************************************************* //