From: Christian P. <cp...@us...> - 2005-06-29 20:52:38
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24487/include/pclasses Modified Files: CallbackN.sh Makefile.am Signal.h Added Files: SignalN.sh Log Message: - Added shell script for generating SignalN classes - Fixed Makefile.am --- NEW FILE: SignalN.sh --- #! /bin/bash #/*************************************************************************** # * Copyright (C) 2005 by Christian Prochnow * # * cp...@se... * # * * # * This program is free software; you can redistribute it and/or modify * # * it under the terms of the GNU Library General Public License as * # * published by the Free Software Foundation; either version 2 of the * # * License, or (at your option) any later version. * # * * # * This program is distributed in the hope that it will be useful, * # * but WITHOUT ANY WARRANTY; without even the implied warranty of * # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * # * GNU General Public License for more details. * # * * # * You should have received a copy of the GNU Library General Public * # * License along with this program; if not, write to the * # * Free Software Foundation, Inc., * # * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * # ***************************************************************************/ # # this shell-script generates code for Signals with n arguments.... # generare_signalN() { templateargs="typename ArgType1" argtypescp="ArgType1" argtypes="ArgType1 arg1" args="arg1" num=1 while [ "$num" -lt "$1" ] do num=`expr $num + 1` templateargs="$templateargs, typename ArgType$num" argtypescp="$argtypescp, ArgType$num" argtypes="$argtypes, ArgType$num arg$num" args="$args, arg$num" done cat << EOF > "SignalN$1.h" namespace P { /* -------------------- Signal$num ---------------- */ //! Base class for Signal$num template <typename RetType, $templateargs> class SignalBase$num { public: typedef std::list< Callback$num<RetType, $argtypescp>* > CallbackList; SignalBase$num() { } virtual ~SignalBase$num() { unbind_slots(_slots); } template <class CallbackType> void bind(CallbackType slot) { bind_slot(_slots, slot); } template <class CallbackType> void unbind(CallbackType slot) { unbind_slot(_slots, slot); } virtual RetType fire($argtypes) const = 0; protected: CallbackList _slots; }; //! Signal with $num argument(s) template <typename RetType, $templateargs> class Signal$num: public SignalBase$num<RetType, $argtypescp> { typedef SignalBase$num<RetType, $argtypescp> BaseType; public: RetType fire($argtypes) const { RetType ret = RetType(); typename BaseType::CallbackList::const_iterator i = this->_slots.begin(); while(i != this->_slots.end()) { ret = (*i)->exec($args); if(ret) break; ++i; } return ret; } }; //! Signal with $num argument(s) (void specialisation) template <$templateargs> class Signal$num<void, $argtypescp>: public SignalBase$num<void, $argtypescp> { typedef SignalBase$num<void, $argtypescp> BaseType; public: void fire($argtypes) const { typename BaseType::CallbackList::const_iterator i = this->_slots.begin(); while(i != this->_slots.end()) { (*i)->exec($args); ++i; } } }; } // !namespace P EOF } generare_signalN 1 generare_signalN 2 generare_signalN 3 generare_signalN 4 Index: CallbackN.sh =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/CallbackN.sh,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- CallbackN.sh 2 Feb 2005 15:54:42 -0000 1.3 +++ CallbackN.sh 29 Jun 2005 20:52:29 -0000 1.4 @@ -51,7 +51,7 @@ cat << EOF > "CallbackN$1.h" namespace P { -/* ----------------- Callback1 ------------------ */ +/* ----------------- Callback$num ------------------ */ template <$templateargs> class CallbackArgs$num: public CallbackArgs { @@ -73,7 +73,7 @@ return args; } -//! Callback base class with $num argument +//! Callback base class with $num argument(s) template <typename _RetT, $templateargs> class Callback$num: public Callback { public: @@ -95,7 +95,7 @@ virtual _RetT exec($argtypes) const = 0; }; -//! Callback base class with $num argument (void specialisation) +//! Callback base class with $num argument(s) (void specialisation) template <$templateargs> class Callback$num<void $argtypescp>: public Callback { public: @@ -116,9 +116,9 @@ virtual void exec($argtypes) const = 0; }; -/* -------------- Function1 ------------- */ +/* -------------- Function$num ------------- */ -//! Function callback class with $num argument +//! Function callback class with $num argument(s) template <typename _RetT, $templateargs> class Function$num: public Callback$num<_RetT, $argtypes> { public: @@ -140,7 +140,7 @@ FuncPtr _funcPtr; }; -//! Function callback class with $num argument (void specialisation) +//! Function callback class with $num argument(s) (void specialisation) template <$templateargs> class Function$num<void, $argtypes>: public Callback$num<void, $argtypes> { public: @@ -167,9 +167,9 @@ Function$num<_RetT, $argtypes> make_function(_RetT (*ptr)($argtypes)) throw() { return Function$num<_RetT, $argtypes>(ptr); } -/* ---------- Method1 ------------ */ +/* ---------- Method$num ------------ */ -//! Method callback class with $num arguments +//! Method callback class with $num argument(s) template <typename _RetT, class _ObjT, $templateargs> class Method$num: public Callback$num<_RetT, $argtypes> { public: @@ -192,7 +192,7 @@ FuncPtr _funcPtr; }; -//! Method callback class with $num arguments (void specialisation) +//! Method callback class with $num argument(s) (void specialisation) template <class _ObjT, $templateargs> class Method$num<void, _ObjT, $argtypes>: public Callback$num<void, $argtypes> { public: Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Makefile.am,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- Makefile.am 22 Jun 2005 11:33:41 -0000 1.16 +++ Makefile.am 29 Jun 2005 20:52:29 -0000 1.17 @@ -4,12 +4,15 @@ INCLUDES = METASOURCES = AUTO +BUILT_SOURCES = all_callbacks all_signals + all_callbacks: if [ ! -e "$(top_builddir)/include/pclasses/CallbackN1.h" ]; then bash $(top_srcdir)/include/pclasses/CallbackN.sh; fi if [ "$(top_builddir)/include/pclasses/CallbackN.sh" -nt "$(top_builddir)/include/pclasses/CallbackN1.h" ]; then bash $(top_srcdir)/include/pclasses/CallbackN.sh; fi -all_callbacks_clean: - rm -f CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h +all_signals: + if [ ! -e "$(top_builddir)/include/pclasses/SignalN1.h" ]; then bash $(top_srcdir)/include/pclasses/SignalN.sh; fi + if [ "$(top_builddir)/include/pclasses/SignalN.sh" -nt "$(top_builddir)/include/pclasses/SignalN1.h" ]; then bash $(top_srcdir)/include/pclasses/SignalN.sh; fi pkginclude_HEADERS = Exception.h IntTypes.h ScopedArrayPtr.h ScopedPtr.h \ SharedPtr.h Alloc.h SourceInfo.h Atomic.h AtomicTraits.h ValueType.h LockTraits.h \ @@ -17,10 +20,8 @@ Stack.h LinkedItem.h Pair.h IntTypeLimits.h Queue.h IntrusivePtr.h \ CircularQueue.h List.h NonCopyable.h Phoenix.h CoreMutex.h Factory.h \ SharingContext.h Time.h Date.h DateTime.h TimeSpan.h Callback.h Signal.h \ + SignalN1.h SignalN2.h SignalN3.h SignalN4.h \ CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h StringList.h \ Trace.h PropertyMap.h Export.h Buffer.h pclasses-config.h -all: all_callbacks - -clean: all_callbacks_clean - +CLEANFILES = CallbackN1.h CallbackN2.h CallbackN3.h CallbackN4.h SignalN1.h SignalN2.h SignalN3.h SignalN4.h Index: Signal.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Signal.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Signal.h 21 Jan 2005 14:51:10 -0000 1.4 +++ Signal.h 29 Jun 2005 20:52:29 -0000 1.5 @@ -131,145 +131,11 @@ } }; -/* -------------------- Signal1 ---------------- */ - -//! Base class for Signal1 -template <typename RetType, typename ArgType1> -class SignalBase1 { - public: - typedef std::list< - Callback1<RetType, ArgType1>* - > CallbackList; - - SignalBase1() - { } - - virtual ~SignalBase1() - { unbind_slots(_slots); } - - template <class CallbackType> - void bind(CallbackType slot) - { bind_slot(_slots, slot); } - - template <class CallbackType> - void unbind(CallbackType slot) - { unbind_slot(_slots, slot); } - - virtual RetType fire(ArgType1) const = 0; - - protected: - CallbackList _slots; -}; - -//! Signal with one argument -template <typename RetType, typename ArgType1> -class Signal1: public SignalBase1<RetType, ArgType1> { - typedef SignalBase1<RetType, ArgType1> BaseType; - - public: - RetType fire(ArgType1 arg1) const - { - RetType ret = RetType(); - typename BaseType::CallbackList::const_iterator i = this->_slots.begin(); - while(i != this->_slots.end()) - { - ret = (*i)->exec(arg1); - if(ret) - break; - ++i; - } - - return ret; - } -}; - -//! Signal with one arguments (void specialisation) -template <typename ArgType1> -class Signal1<void, ArgType1>: public SignalBase1<void, ArgType1> { - typedef SignalBase1<void, ArgType1> BaseType; - - public: - void fire(ArgType1 arg1) const - { - typename BaseType::CallbackList::const_iterator i = this->_slots.begin(); - while(i != this->_slots.end()) - { - (*i)->exec(arg1); - ++i; - } - } -}; - - -/* -------------------- Signal2 ---------------- */ - -//! Base class for Signal2 -template <typename RetType, typename ArgType1, typename ArgType2> -class SignalBase2 { - public: - typedef std::list< - Callback2<RetType, ArgType1, ArgType2>* - > CallbackList; - - SignalBase2() - { } - - virtual ~SignalBase2() - { unbind_slots(_slots); } - - template <class CallbackType> - void bind(CallbackType slot) - { bind_slot(_slots, slot); } - - template <class CallbackType> - void unbind(CallbackType slot) - { unbind_slot(_slots, slot); } - - virtual RetType fire(ArgType1, ArgType2) const = 0; - - protected: - CallbackList _slots; -}; - -//! Signal with two arguments -template <typename RetType, typename ArgType1, typename ArgType2> -class Signal2: public SignalBase2<RetType, ArgType1, ArgType2> { - typedef SignalBase2<RetType, ArgType1, ArgType2> BaseType; - - public: - RetType fire(ArgType1 arg1, ArgType2 arg2) const - { - RetType ret = RetType(); - typename BaseType::CallbackList::const_iterator i = this->_slots.begin(); - while(i != this->_slots.end()) - { - ret = (*i)->exec(arg1, arg2); - if(ret) - break; - ++i; - } - - return ret; - } -}; - -//! Signal with two arguments (void specialisation) -template <typename ArgType1, typename ArgType2> -class Signal2<void, ArgType1, ArgType2>: public SignalBase2<void, ArgType1, ArgType2> { - typedef SignalBase2<void, ArgType1, ArgType2> BaseType; - public: - void fire(ArgType1 arg1, ArgType2 arg2) const - { - typename BaseType::CallbackList::const_iterator i = this->_slots.begin(); - while(i != this->_slots.end()) - { - (*i)->exec(arg1, arg2); - ++i; - } - } -}; - - } // !namespace P +#include <pclasses/SignalN1.h> +#include <pclasses/SignalN2.h> +#include <pclasses/SignalN3.h> +#include <pclasses/SignalN4.h> + #endif |