Equalizer 1.0

commandFunc.h

00001 
00002 /* Copyright (c) 2006-2011, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef CO_COMMANDFUNC_H
00019 #define CO_COMMANDFUNC_H
00020 
00021 #include <co/base/api.h>
00022 #include <co/base/debug.h>
00023 
00024 namespace co
00025 {
00026     class Command;
00027 
00034     template< typename T > class CommandFunc
00035     {
00036     public:
00037         CommandFunc( T* object, 
00038                      bool (T::*func)( Command& ))
00039             : _object( object ), _func( func ) {}
00040 
00041         template< typename O > CommandFunc( const CommandFunc< O >& from )
00042                 : _object( from._object ),
00043                   _func( static_cast<bool (T::*)( Command& )>(from._func))
00044             {}
00045 
00046         bool operator()( Command& command )
00047         {
00048             EQASSERT( _object );
00049             EQASSERT( _func );
00050             return (_object->*_func)( command );
00051         }
00052 
00053         void clear() { _object = 0; _func = 0; }
00054         bool isValid() const { return _object && _func; }
00055 
00056         // Can't make private because copy constructor needs access. Can't
00057         // declare friend because C++ does not allow generic template friends in
00058         // template classes.
00059         //private:
00060         T* _object;
00061         bool (T::*_func)( Command& );
00062     };
00063 
00064     template< typename T >
00065     inline std::ostream& operator << ( std::ostream& os,
00066                                        const CommandFunc<T>& func )
00067     {
00068         if( func._object && func._func )
00069             os << "CommandFunc of " << base::className( func._object );
00070         else
00071             os << "invalid CommandFunc";
00072         return os;
00073     }
00074 }
00075 
00076 #endif //CO_COMMANDFUNC_H
Generated on Sun May 8 2011 19:11:05 for Equalizer 1.0 by  doxygen 1.7.3