00001 //=========================================================================== 00002 // GoTools - SINTEF Geometry Tools version 1.1 00003 // 00004 // GoTools module: CORE 00005 // 00006 // Copyright (C) 2000-2007 SINTEF ICT, Applied Mathematics, Norway. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation version 2 of the License. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 00020 // 59 Temple Place - Suite 330, 00021 // Boston, MA 02111-1307, USA. 00022 // 00023 // Contact information: E-mail: tor.dokken@sintef.no 00024 // SINTEF ICT, Department of Applied Mathematics, 00025 // P.O. Box 124 Blindern, 00026 // 0314 Oslo, Norway. 00027 // 00028 // Other licenses are also available for this software, notably licenses 00029 // for: 00030 // - Building commercial software. 00031 // - Building software whose source code you wish to keep private. 00032 //=========================================================================== 00033 #ifndef _GOSTREAMABLE_H 00034 #define _GOSTREAMABLE_H 00035 00036 #include <iostream> 00037 #include <iomanip> 00038 #include "errormacros.h" 00039 00040 namespace Go 00041 { 00044 00045 00051 class Streamable 00052 { 00053 public: 00054 virtual ~Streamable(); 00055 00058 virtual void read (std::istream& is) = 0; 00061 virtual void write (std::ostream& os) const = 0; 00062 00063 // Exception class 00064 class EofException{}; 00065 }; 00066 00067 inline std::istream& operator >> (std::istream& is, Go::Streamable& obj) 00068 { 00069 ALWAYS_ERROR_IF(is.eof(), "End of file reached. Cannot read."); 00070 obj.read(is); 00071 return is; 00072 } 00073 00074 inline std::ostream& operator << (std::ostream& os, 00075 const Go::Streamable& obj) 00076 { 00077 obj.write(os); 00078 return os; 00079 } 00080 00082 } // namespace Go 00083 00084 00085 00086 #endif // _GOSTREAMABLE_H 00087 00088