BatchCommand.hh

00001 //********************************************************************
00002 //*** ResourcePool/BatchCommand.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: BatchCommand.hh,v 1.21 2009-06-23 18:51:39 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_BATCHCOMMAND_HH
00025 #define RESOURCEPOOL_BATCHCOMMAND_HH
00026 
00027 #include <vector>
00028 
00029 #include "mm/gc_ptr.hh"
00030 #include "util/Clone.hh"
00031 
00032 namespace fatalmind {
00033 
00034 /*
00035  * developers note:
00036  * i would actually love to have a error handling interface with something like BatchException.
00037  * However, thats hard/impossible to implement in C++, since it is impossible to maintain
00038  * exception neutral behavior and storing the exception's somewhere.
00039  */
00040 
00046 template<class CommandType>
00047 class BatchCommand: public CommandType
00048 {
00049     protected:
00050         typedef gc_ptr<CommandType> member_t;
00051         typedef std::vector<member_t> list_t;
00052     public:
00053         typedef CommandType innercommand_t;
00054         typedef typename list_t::const_iterator const_iterator;
00055         static const int NOT_STARTED;
00056         static const int NO_FURTHER_ERROR;
00057 
00084         BatchCommand(bool cont = false);
00085 
00086         BatchCommand(const BatchCommand&);
00087         virtual ~BatchCommand() {
00088         }
00089 
00100         virtual void add(const CommandType&);
00101         virtual void execute(typename CommandType::pool_type::resource_t&);
00102 
00141         int getError();
00147         const_iterator getExecPosition() const;
00148 
00154         bool doesContinue() const {
00155             return cont;
00156         }
00157 
00162         const_iterator end() const;
00168         const_iterator begin() const;
00173         bool empty() const;
00174 
00175         virtual void outputoperator(std::ostream&) const;
00176     protected:
00177         virtual Clone* DoClone() const {
00178             return new BatchCommand(*this);
00179         }
00180 
00181         member_t getLast() const {
00182             return list.back();
00183         }
00184 
00185         bool wasStarted() const {
00186             return started;
00187         }
00188 
00189 
00190     private:
00191         list_t list;
00192         const bool cont;
00193         bool started;
00194     protected:
00195         const_iterator exec_pos;
00196         typedef std::vector<int> errors_t;
00197         errors_t errors;
00198         unsigned int error_pos;
00199 }; // class Batch
00200 
00201 } // namespace fatalmind
00202 #endif

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