00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 \*---------------------------------------------------------------------------*/ 00025 00026 #include "wordRe.H" 00027 #include <OpenFOAM/IOstreams.H> 00028 #include <OpenFOAM/InfoProxy.H> 00029 00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00031 00032 Foam::wordRe::wordRe(Istream& is) 00033 : 00034 word(), 00035 re_(NULL) 00036 { 00037 is >> *this; 00038 } 00039 00040 00041 Foam::Istream& Foam::operator>>(Istream& is, wordRe& w) 00042 { 00043 token t(is); 00044 00045 if (!t.good()) 00046 { 00047 is.setBad(); 00048 return is; 00049 } 00050 00051 if (t.isWord()) 00052 { 00053 w = t.wordToken(); 00054 } 00055 else if (t.isString()) 00056 { 00057 // Auto-tests for regular expression 00058 w = t.stringToken(); 00059 } 00060 else 00061 { 00062 is.setBad(); 00063 FatalIOErrorIn("operator>>(Istream&, wordRe&)", is) 00064 << "wrong token type - expected word or string found " 00065 << t.info() 00066 << exit(FatalIOError); 00067 00068 return is; 00069 } 00070 00071 // Check state of IOstream 00072 is.check("Istream& operator>>(Istream&, wordRe&)"); 00073 00074 return is; 00075 } 00076 00077 00078 Foam::Ostream& Foam::operator<<(Ostream& os, const wordRe& w) 00079 { 00080 os.writeQuoted(w, w.isPattern()); 00081 os.check("Ostream& operator<<(Ostream&, const wordRe&)"); 00082 return os; 00083 } 00084 00085 00086 Foam::Ostream& Foam::wordRe::info(Ostream& os) const 00087 { 00088 if (isPattern()) 00089 { 00090 os << "wordRe(regex) " << *this; 00091 } 00092 else 00093 { 00094 os << "wordRe(plain) \"" << *this << '"'; 00095 } 00096 os.flush(); 00097 00098 return os; 00099 } 00100 00101 00102 // ************************ vim: set sw=4 sts=4 et: ************************ //