except.hh

Go to the documentation of this file.
00001 /*************************************************************************
00002 
00003 Copyright Rice University, 2004, 2005, 2006.
00004 All rights reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the "Software"),
00008 to deal in the Software without restriction, including without limitation
00009 the rights to use, copy, modify, merge, publish, distribute, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, provided that the above copyright notice(s) and this
00012 permission notice appear in all copies of the Software and that both the
00013 above copyright notice(s) and this permission notice appear in supporting
00014 documentation.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
00019 RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
00020 NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
00021 DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
00022 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00023 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
00024 THIS SOFTWARE.
00025 
00026 Except as contained in this notice, the name of a copyright holder shall
00027 not be used in advertising or otherwise to promote the sale, use or other
00028 dealings in this Software without prior written authorization of the
00029 copyright holder.
00030 
00031 **************************************************************************/
00032 
00033 #ifndef __RVL_EXCEPT
00034 #define __RVL_EXCEPT
00035 
00036 #define BUFLEN 100
00037 
00038 #include "std_cpp_includes.hh"
00039 
00040 namespace RVL {
00041 
00046   class RVLException: public std::exception {
00047   private:
00048     string msg;
00049   public:
00050     RVLException(): msg("") {}
00051     RVLException(const RVLException & s): msg("") { msg +=s.msg; }
00052     virtual ~RVLException() throw() {}
00053 
00054     const char* what() const throw() { return msg.c_str(); }
00055 
00056     RVLException & operator<< ( string str ) { 
00057       msg += str;
00058       return *this;
00059     }
00060     RVLException & operator<< ( const char* str ) { 
00061       msg += str;
00062       return *this;
00063     }
00064     RVLException & operator<< ( int i ) {
00065       char buf[ BUFLEN ];
00066       sprintf( buf, "%d", i );
00067       msg += buf;
00068       return *this;
00069     }
00070     RVLException & operator<< ( unsigned int i ) {
00071       char buf[ BUFLEN ];
00072       sprintf( buf, "%u", i );
00073       msg += buf;
00074       return *this;
00075     }
00076     RVLException & operator<< ( long i ) {
00077       char buf[ BUFLEN ];
00078       sprintf( buf, "%ld", i );
00079       msg += buf;
00080       return *this;
00081     }
00082     RVLException & operator<< ( unsigned long i ) {
00083       char buf[ BUFLEN ];
00084       sprintf( buf, "%lu", i );
00085       msg += buf;
00086       return *this;
00087     }
00088     RVLException & operator<< ( short i ) {
00089       char buf[ BUFLEN ];
00090       sprintf( buf, "%d", i );
00091       msg += buf;
00092       return *this;
00093     }
00094     RVLException & operator<< ( unsigned short i ) {
00095       char buf[ BUFLEN ];
00096       sprintf( buf, "%d", i );
00097       msg += buf;
00098       return *this;
00099     }
00100     /*
00101     RVLException & operator<< ( off_t i ) {
00102       char buf[ BUFLEN ];
00103       sprintf( buf, "%zd", i );
00104       msg += buf;
00105       return *this;
00106     }
00107     */
00108     RVLException & operator<< ( double d ) {
00109       char buf[ BUFLEN ];
00110       sprintf( buf, "%g", d );
00111       msg += buf;
00112       return *this;
00113     }
00114     RVLException & operator<< ( float d ) {
00115       char buf[ BUFLEN ];
00116       sprintf( buf, "%g", d );
00117       msg += buf;
00118       return *this;
00119     }
00120     template<class T>
00121     RVLException & operator<< ( complex<T> d ) {
00122       char buf[ BUFLEN ];
00123       sprintf( buf, "(%g,%g)", d.real(),d.imag() );
00124       msg += buf;
00125       return *this;
00126     }
00127 
00128     RVLException & operator<< ( char c ) {
00129       char buf[ BUFLEN ];
00130       buf[ 0 ] = c;
00131       buf[ 1 ] = '\0';
00132       msg += buf;
00133       return *this;
00134     }
00135 
00136     ostream & write(ostream & str) const {
00137       str<<msg<<endl;
00138       return str;
00139     }
00140   };
00141 
00142 }
00143 
00144 #endif

Generated on 5 Jan 2017 for RVL by  doxygen 1.4.7