//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00015 #ifndef _STREAMABLE_H 00016 #define _STREAMABLE_H 00017 00018 #include <iostream> 00019 #include <iomanip> 00020 #include "GoTools/utils/errormacros.h" 00021 #include "GoTools/utils/config.h" 00022 00023 namespace Go 00024 { 00025 00031 class GO_API Streamable 00032 { 00033 public: 00034 virtual ~Streamable(); 00035 00038 virtual void read (std::istream& is) = 0; 00041 virtual void write (std::ostream& os) const = 0; 00042 00043 // Exception class 00044 class EofException{}; 00045 }; 00046 00047 inline std::istream& operator >> (std::istream& is, Go::Streamable& obj) 00048 { 00049 ALWAYS_ERROR_IF(is.eof(), "End of file reached. Cannot read."); 00050 obj.read(is); 00051 return is; 00052 } 00053 00054 inline std::ostream& operator << (std::ostream& os, 00055 const Go::Streamable& obj) 00056 { 00057 obj.write(os); 00058 return os; 00059 } 00060 00061 } // namespace Go 00062 00063 00064 00065 #endif // _STREAMABLE_H 00066