cptraits.h

Go to the documentation of this file.
00001 00005 /* Copyright © 2002 Michael Geddes 00006 * 00007 * This material is provided "as is", with absolutely no warranty 00008 * expressed or implied. Any use is at your own risk. Permission to 00009 * use or copy this software for any purpose is hereby granted without 00010 * fee, provided the above notices are retained on all copies. 00011 * Permission to modify the code and to distribute modified code is 00012 * granted, provided the above notices are retained, and a notice that 00013 * the code was modified is included with the above copyright notice. 00014 * 00015 * This header is part of comet. 00016 * http://www.lambdasoft.dk/comet 00017 */ 00018 00019 #ifndef INCLUDE_COMET_CPTRAITS_H 00020 #define INCLUDE_COMET_CPTRAITS_H 00021 00022 #ifdef _SHOW_INC 00023 #pragma message(" #Include " __FILE__) 00024 #endif 00025 00026 #include <comet/config.h> 00027 00028 namespace comet 00029 { 00036 struct cp_throw 00037 { 00038 00040 cp_throw() : _hr_(S_OK) { } 00041 00043 ~cp_throw() { _hr_ | raise_exception ; } 00044 00051 bool check_fail(HRESULT hr) 00052 { 00053 if( FAILED(hr) ) 00054 _hr_ = hr; 00055 return false; 00056 } 00057 00062 template<typename CONNECTIONS> 00063 static bool on_fail(CONNECTIONS &par_connects, const typename CONNECTIONS::iterator &par_it ) 00064 { return false;} 00065 00066 protected: 00067 HRESULT _hr_; 00068 00069 }; 00070 00078 struct cp_nothrow_remove 00079 { 00081 bool check_fail( HRESULT _hr_) throw() { return FAILED(_hr_); } 00082 00084 template<typename CONNECTIONS> 00085 static bool on_fail(CONNECTIONS &par_connects, const typename CONNECTIONS::iterator &par_it ) throw() 00086 { 00087 try{ par_connects.erase(par_it); }catch(...) {} 00088 return false; 00089 } 00090 }; 00091 00092 00100 struct cp_nothrow 00101 { 00103 bool check_fail( HRESULT _hr_) throw() { return FAILED(_hr_); } 00104 00106 template<typename CONNECTIONS> 00107 static bool on_fail(CONNECTIONS &par_connects, const typename CONNECTIONS::iterator &par_it ) throw() { return false; } 00108 }; 00109 }; 00110 #endif /* INCLUDE_COMET_CPTRAITS_H */