00001 00008 /************************************************************************** 00009 00010 begin : Mon Jan 20 2003 00011 copyright : (C) 2002-2010 by Ewald Arnold 00012 email : mockpp at ewald-arnold dot de 00013 00014 This program is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU Lesser General Public License as 00016 published by the Free Software Foundation; either version 2 of the License, 00017 or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 00028 **/ 00029 00030 #ifndef MOCKPP_THROWABLE_H 00031 #define MOCKPP_THROWABLE_H 00032 00033 #include <mockpp/mockpp.h> // always first 00034 00035 00036 MOCKPP_NS_START 00037 00038 00042 class Throwable 00043 { 00044 public: 00045 00049 virtual void throw_me() = 0; 00050 00055 virtual bool hasThrown() const = 0; 00056 00060 virtual ~Throwable() 00061 {} 00062 }; 00063 00064 00068 template <class T> 00069 class ThrowableWrapper : public Throwable 00070 { 00071 public: 00072 00076 virtual void throw_me() 00077 { 00078 ++thrown; 00079 MOCKPP_THROW(obj); 00080 } 00081 00082 00087 virtual bool hasThrown() const 00088 { 00089 return thrown > 0; 00090 } 00091 00092 00096 void reset() 00097 { 00098 thrown = 0; 00099 } 00100 00101 00106 ThrowableWrapper(const T &o) 00107 : obj(o), 00108 thrown(0) 00109 {} 00110 00111 private: 00112 00113 T obj; 00114 unsigned thrown; 00115 }; 00116 00117 00123 template <class T> 00124 Throwable *make_throwable(const T &w) 00125 { 00126 return new ThrowableWrapper<T> (w); 00127 } 00128 00129 00136 class MOCKPP_API_DECL0 ThrowableItem 00137 { 00138 public: 00139 00144 ThrowableItem(Throwable *it = 0); 00145 00151 ThrowableItem(const ThrowableItem &it); 00152 00158 ThrowableItem &operator = (const ThrowableItem &it); 00159 00163 virtual ~ThrowableItem() throw(); 00164 00171 void take(Throwable *it); 00172 00177 template <class T> 00178 void take(const T &w) 00179 { 00180 take(make_throwable(w)); 00181 } 00182 00187 Throwable *release(); 00188 00193 Throwable *get() const; 00194 00198 void reset(); 00199 00205 bool wasUsed() const; 00206 00207 private: 00208 00209 Throwable *item; 00210 }; 00211 00212 00213 MOCKPP_NS_END 00214 00215 00216 #endif // MOCKPP_THROWABLE_H