IgnoreExceptionCommand.hh

00001 //********************************************************************
00002 //*** ResourcePool/IgnoreExceptionCommand.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: IgnoreExceptionCommand.hh,v 1.5 2009-03-08 14:37:56 mws Exp $
00005 //********************************************************************
00006 /*
00007 This file is part of ResourcePool.
00008 
00009 ResourcePool is free software; you can redistribute it
00010 and/or modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2 of
00012 the License, or (at your option) any later version.
00013 
00014 ResourcePool is distributed in the hope that it will be
00015 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00016 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with ResourcePool; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00022 02111-1307  USA */
00023 
00024 #ifndef RESOURCEPOOL_IGNOREEXCEPTIONCOMMAND_HH
00025 #define RESOURCEPOOL_IGNOREEXCEPTIONCOMMAND_HH
00026 
00027 #include <iostream>
00028 
00029 #include "mm/gc_ptr.hh"
00030 #include "util/Clone.hh"
00031 
00032 namespace fatalmind {
00033 
00039 // TODO
00040 //  * addtional Template Parameter to catch only specified exceptions
00041 //  * make a getter for this exception
00042 template<class CommandType>
00043 class IgnoreExceptionCommand: public CommandType
00044 {
00045     protected:
00046     private:
00047         gc_ptr<CommandType> m;
00048 
00049         IgnoreExceptionCommand(const IgnoreExceptionCommand& rho) 
00050         : CommandType(rho)
00051         , m(rho.m)
00052         {
00053         }
00054     public:
00055         IgnoreExceptionCommand(const CommandType& a_m) 
00056         : CommandType(a_m)
00057         , m(a_m.template clone<CommandType>())
00058         {
00059         };
00060         virtual ~IgnoreExceptionCommand() {
00061         }
00062 
00063         virtual void execute(typename CommandType::pool_type::resource_t& r) {
00064             try {
00065                 m->execute(r);
00066             } catch (...) {
00067             }
00068         }
00069 
00070         const CommandType& getCommandRef() const {
00071             return *m.get();
00072         }
00073 
00074         virtual void outputoperator(std::ostream& s) const {
00075             s << "IgnoreExceptionCommand[" << (*m) << ']';
00076         }
00077 
00078     protected:
00079         virtual Clone* DoClone() const {
00080             return new IgnoreExceptionCommand(*this);
00081         }
00082 
00083 }; // class IgnoreExceptionCommand
00084 
00085 } // namespace fatalmind
00086 #endif

Generated on Mon Nov 9 16:21:24 2009 for ResourcePool by  doxygen 1.5.3