1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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
52 template<class Err> class errorManip;
53 template<class Err> Ostream& operator<<(Ostream&, errorManip<Err>);
55 template<class Err, class T> class errorManipArg;
56 template<class Err, class T>
57 Ostream& operator<<(Ostream&, errorManipArg<Err, T>);
60 /*---------------------------------------------------------------------------*\
61 Class errorManip Declaration
62 \*---------------------------------------------------------------------------*/
72 errorManip(void (Err::*fPtr)(), Err& t)
78 friend Ostream& operator<< <Err>(Ostream& os, errorManip<Err> m);
83 inline Ostream& operator<<(Ostream& os, errorManip<Err> m)
90 /*---------------------------------------------------------------------------*\
91 Class errorManipArg Declaration
92 \*---------------------------------------------------------------------------*/
95 template<class Err, class T>
98 void (Err::*fPtr_)(const T);
104 errorManipArg(void (Err::*fPtr)(const T), Err& t, const T i)
111 friend Ostream& operator<< <Err, T>(Ostream& os, errorManipArg<Err, T> m);
115 template<class Err, class T>
116 inline Ostream& operator<<(Ostream& os, errorManipArg<Err, T> m)
118 (m.err_.*m.fPtr_)(m.arg_);
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 inline errorManipArg<error, int> exit(error& err, const int errNo = 1)
127 return errorManipArg<error, int>(&error::exit, err, errNo);
130 inline errorManip<error> abort(error& err)
132 return errorManip<error>(&error::abort, err);
136 inline errorManipArg<IOerror, int> exit(IOerror& err, const int errNo = 1)
138 return errorManipArg<IOerror, int>(&IOerror::exit, err, errNo);
141 inline errorManip<IOerror> abort(IOerror& err)
143 return errorManip<IOerror>(&IOerror::abort, err);
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 } // End namespace Foam
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 // ************************************************************************* //