Wexus2 0.20
wexus2.src/wexus/AssertException.h
00001 
00002 /*
00003  * Copyright (c) 2011 Aleksander B. Demko
00004  * This source code is distributed under the MIT license.
00005  * See the accompanying file LICENSE.MIT.txt for details.
00006  */
00007 
00008 #ifndef __INCLUDED_WEXUS_ASSERT_H__
00009 #define __INCLUDED_WEXUS_ASSERT_H__
00010 
00011 #include <assert.h>
00012 
00013 #include <QVariant>
00014 #include <QString>
00015 
00016 #include <wexus/Exception.h>
00017 
00018 namespace wexus
00019 {
00020   /**
00021    * An assert exception. These are critical and shouldn't be user-presented.
00022    *
00023    * @author Aleksander Demko
00024    */ 
00025   class AssertException : public wexus::Exception
00026   {
00027     public:
00028       /// constructor
00029       AssertException(const char *msg);
00030       /// for QString
00031       AssertException(const QString &msg);
00032   };
00033 
00034   /**
00035    * If b is false, an AssertException will be thrown
00036    * with the given msg.
00037    *
00038    * @author Aleksander Demko
00039    */
00040   void assertThrowMsg(bool b, const char *msg);
00041 
00042 #define assertThrow_QUOTEME_(x) #x
00043 #define assertThrow_QUOTEME(x) assertThrow_QUOTEME_(x)
00044 
00045   /**
00046    * assertThrow is always defined, debug mode or not.
00047    *
00048    * @author Aleksander Demko
00049    */ 
00050 #define assertThrow(b) \
00051   wexus::assertThrowMsg((b), "assertThrow failed at: " __FILE__ ":" assertThrow_QUOTEME(__LINE__) )
00052 // so we can switch between them sometimes :)
00053 #define assertThrow__(b) assert(b)
00054 
00055   class AssertThrower
00056   {
00057     bool operator = (bool b);
00058     const QVariant & operator = (const QVariant &v);
00059     const QString & operator = (const QString &s);
00060     // int version too? conflicts with bool?
00061     // ActiveRecord version?
00062   };
00063 
00064   /**
00065    * The global instance of AssertThrower that you can use.
00066    *
00067    * @author Aleksander Demko
00068    */ 
00069   extern AssertThrower required;
00070 }
00071 
00072 #endif
00073 
 All Classes Namespaces Functions Variables Enumerations Enumerator