00001 #ifndef NMWR_UTILITY_CHECKED_ISTREAM_H 00002 #define NMWR_UTILITY_CHECKED_ISTREAM_H 00003 00004 // $LICENSE 00005 00006 #include <iostream> 00007 #include "Utility/pre-post-conditions.h" 00008 00018 class checked_istream { 00019 private: 00020 std::istream* in; 00021 public: 00022 checked_istream(std::istream* in_ = 0) : in(in_) {} 00023 00024 template<class T> 00025 friend checked_istream& operator>>(checked_istream& in, T & t) 00026 { 00027 REQUIRE( (in.in != 0), "no istream!\n",1); 00028 *(in.in) >> t; 00029 REQUIRE( (in.in->good()), "bad istream, reading " << t << " failed!\n",1); 00030 return in; 00031 } 00032 }; 00033 00034 #endif