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 "string.H" 00027 #include <OpenFOAM/IOstreams.H> 00028 00029 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 00030 00031 Foam::string::string(Istream& is) 00032 { 00033 is >> *this; 00034 } 00035 00036 00037 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // 00038 00039 Foam::Istream& Foam::operator>>(Istream& is, string& s) 00040 { 00041 token t(is); 00042 00043 if (!t.good()) 00044 { 00045 is.setBad(); 00046 return is; 00047 } 00048 00049 if (t.isString()) 00050 { 00051 s = t.stringToken(); 00052 } 00053 else 00054 { 00055 is.setBad(); 00056 FatalIOErrorIn("operator>>(Istream&, string&)", is) 00057 << "wrong token type - expected string found " << t.info() 00058 << exit(FatalIOError); 00059 00060 return is; 00061 } 00062 00063 // Check state of Istream 00064 is.check("Istream& operator>>(Istream&, string&)"); 00065 00066 return is; 00067 } 00068 00069 00070 Foam::Ostream& Foam::operator<<(Ostream& os, const string& s) 00071 { 00072 os.write(s); 00073 os.check("Ostream& operator<<(Ostream&, const string&)"); 00074 return os; 00075 } 00076 00077 00078 Foam::Ostream& Foam::operator<<(Ostream& os, const std::string& s) 00079 { 00080 os.write(string(s)); 00081 os.check("Ostream& operator<<(Ostream&, const std::string&)"); 00082 return os; 00083 } 00084 00085 00086 // ************************ vim: set sw=4 sts=4 et: ************************ //