Command.hh

00001 //********************************************************************
00002 //*** ResourcePool/Command.hh
00003 //*** Copyright (c) 2003-2009 by Markus Winand <mws@fatalmind.com>
00004 //*** $Id: Command.hh,v 1.22 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_COMMAND_HH
00025 #define RESOURCEPOOL_COMMAND_HH
00026 
00027 #include "util/Clone.hh"
00028 
00029 namespace fatalmind {
00030 
00031 template<class PT>class ResourcePool; // Fwd decl
00032 
00033 // helper for non-templated methods & data
00034 // really required to make operator<< work properly
00035 
00036 class NonTemplateCommand: public Clone {
00037     public:
00038         NonTemplateCommand();
00039         ~NonTemplateCommand();
00040     protected:
00041         bool topLevel() const {
00042             return _tl;
00043         }
00044         void topLevel(bool tl) {
00045             _tl = tl;
00046         }
00047     private:
00048         bool _tl;
00049         virtual void outputoperator(std::ostream&) const;
00050 
00051     template<class charT, class traits>
00052     friend 
00053         std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& s, const fatalmind::NonTemplateCommand& rho);
00054 };
00055 
00059 template<class PT>
00060 class Command: public NonTemplateCommand {
00061     protected:
00062         Command() 
00063         : NonTemplateCommand()
00064         {
00065         };
00066     public:
00067         typedef PT pool_type;
00068 
00069         virtual ~Command() {
00070         }
00071 
00083         virtual void execute(typename PT::resource_t& rr) = 0;
00084 
00085     protected:
00086         const typename PT::factory_t& getFactory(const ResourcePool<PT>& p) const {
00087             return p.getFactory();
00088         }
00089 
00090     friend 
00091         class ResourcePool<PT>;
00092 };
00093 
00094 } // namespace fatalmind
00095 
00096 template<class charT, class traits>
00097 std::basic_ostream<charT, traits>& fatalmind::operator<<(std::basic_ostream<charT, traits>& s, const fatalmind::NonTemplateCommand& rho) {
00098     rho.outputoperator(s);
00099     return s;
00100 }
00101 
00102 
00103 #endif

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