ut_exceptions.hpp

Go to the documentation of this file.
00001 #ifndef __ut_exceptions_hpp__
00002 #define __ut_exceptions_hpp__
00003 
00004 #include "common/gx_exception.hpp"
00005 #include "common/sh_utils.h"
00006 
00007 #include <stdlib.h>
00008 
00009 #include <exception>
00010 
00011 #include <glib.h>
00012 
00013 #if defined(QT_CORE_LIB)
00014 #include <QString>
00015 #endif
00016 
00017 //xxx do want functions that that strdup the text, and also allows for formatting and optionally position info
00018 
00019 NONSHARABLE_CLASS(CstrLitException) :
00020   public std::exception
00021 {
00022  private:
00023   const char* iText; // not owned
00024  public:
00025   CstrLitException(const char* aText) throw() : iText(aText) {}
00026   virtual const char* what() const throw() { return iText; }
00027 };
00028 
00029 NONSHARABLE_CLASS(CstrExceptionFree) :
00030   public std::exception
00031 {
00032  private:
00033   char* iText; // owned
00034  public:
00035   CstrExceptionFree(char* aText) throw() : iText(aText) {}
00036   virtual ~CstrExceptionFree() throw() { if (iText) free(iText); }
00037   virtual const char* what() const throw() { return iText; }
00038 };
00039 
00040 // Note that free and g_free do not necessarily rely on the same
00041 // memory allocation scheme. You may use g_mem_is_system_malloc() to
00042 // find out whether this is the case.
00043 NONSHARABLE_CLASS(CstrExceptionGfree) :
00044   public std::exception
00045 {
00046  private:
00047   gchar* iText; // owned
00048  public:
00049   CstrExceptionGfree(gchar* aText) throw() : iText(aText) {}
00050   virtual ~CstrExceptionGfree() throw() { g_free(iText); }
00051   virtual const char* what() const throw() { return iText; }
00052 };
00053 
00054 #define throw_cstr_unless(_v, _msg) \
00055   if (!(_v)) { throw CstrLitException(_msg); }
00056 
00057 #endif /* __ut_exceptions_hpp__ */
00058 
00059 /**
00060 
00061 Copyright 2010 Helsinki Institute for Information Technology (HIIT)
00062 and the authors. All rights reserved.
00063 
00064 Authors: Tero Hasu <tero.hasu@hut.fi>
00065 
00066 Permission is hereby granted, free of charge, to any person
00067 obtaining a copy of this software and associated documentation files
00068 (the "Software"), to deal in the Software without restriction,
00069 including without limitation the rights to use, copy, modify, merge,
00070 publish, distribute, sublicense, and/or sell copies of the Software,
00071 and to permit persons to whom the Software is furnished to do so,
00072 subject to the following conditions:
00073 
00074 The above copyright notice and this permission notice shall be
00075 included in all copies or substantial portions of the Software.
00076 
00077 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00078 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00079 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00080 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00081 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00082 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00083 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00084 SOFTWARE.
00085 
00086  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:57 2011 by Doxygen 1.6.1