[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paragui-cvs] CVS: paragui/src/libsigc++/sigc++/macros Makefile.am,NONE
From: |
Alexander Pipelka <address@hidden> |
Subject: |
[paragui-cvs] CVS: paragui/src/libsigc++/sigc++/macros Makefile.am,NONE,1.1.2.1 README,NONE,1.1.2.1 bind.h.m4,NONE,1.1.2.1 bind_return.h.m4,NONE,1.1.2.1 class_slot.h.m4,NONE,1.1.2.1 hide.h.m4,NONE,1.1.2.1 method_slot.h.m4,NONE,1.1.2.1 object_slot.h.m4,NONE,1.1.2.1 retype.h.m4,NONE,1.1.2.1 retype_return.h.m4,NONE,1.1.2.1 signal.h.m4,NONE,1.1.2.1 slot.h.m4,NONE,1.1.2.1 template.macros.m4,NONE,1.1.2.1 |
Date: |
Mon, 03 Feb 2003 19:08:19 -0500 |
Update of /cvsroot/paragui/paragui/src/libsigc++/sigc++/macros
In directory subversions:/tmp/cvs-serv19686/src/libsigc++/sigc++/macros
Added Files:
Tag: devel-opengl
Makefile.am README bind.h.m4 bind_return.h.m4 class_slot.h.m4
hide.h.m4 method_slot.h.m4 object_slot.h.m4 retype.h.m4
retype_return.h.m4 signal.h.m4 slot.h.m4 template.macros.m4
Log Message:
added libsigc++ 1.2.3 (building statically linked versions, Win32)
physfs autoconf / automake fixes
--- NEW FILE ---
templates = bind_return.h.m4 \
method_slot.h.m4 \
object_slot.h.m4 retype_return.h.m4 slot.h.m4 \
bind.h.m4 class_slot.h.m4 hide.h.m4 retype.h.m4 \
signal.h.m4 template.macros.m4
EXTRA_DIST = README $(templates)
m4includedir = $(includedir)/sigc++-1.2/sigc++/macros
m4include_HEADERS = $(templates)
--- NEW FILE ---
This directory contains files associated with building large numbers
of templates needed to represent different numbers of parameters.
The file signal.macros.m4 defines all necessary macros for construction
of templates with variable arguments.
These files will be placed in $(INCLUDE_DIR)/sigc++/macros for
reuse.
Requires:
Gnu M4 (others m4 may work)
Macros of particular interest:
IF(arg1,arg2[,arg3]) - if arg1 non-zero length print arg2, else arg3
LIST(arg0,cond0 [,arg1,cond1]) - generates comma seperated list with
conditions for each argument
ARG_CLASS([P1,P2, ... ]) - generates string "class P1,class P2"
ARG_BOTH([P1,P2, ... ]) - generates string "P1 p1,P2 p2"
ARG_TYPE([P1,P2, ... ]) - generates string "P1,P2"
ARG_NAME([P1,P2, ... ]) - generates string "p1,p2"
[name]NUM(arg) - prints name#, where # is items in arg
ARGS(P,n) - generates string [P1,P2,...Pn]
example:
To generalize this...
template<class P1,class P2> // needs to be inline for zero arguments
void Foo::func2(int (*f)(P1,P2),P1 p1,P2 p2)
{func(p1,p2);
}
Use this...
include(template.macros.m4)
define([FOO_FUNC],
[
IF([$1],template<ARG_CLASS($1)>,inline)
void Foo::[func]NUM($1)(LIST(int (*f)(ARG_TYPE($1)),1,ARG_BOTH($1),[$1]))
{func(ARG_NAME($1));
}
])
FOO_FUNC(ARGS(P,0))
FOO_FUNC(ARGS(P,1))
FOO_FUNC(ARGS(P,2))
(to prove it m4 this README file. Honest!)
--- NEW FILE ---
// -*- c++ -*-
dnl bind.h.m4 - adaptor to fix arguments to a value
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
dnl
dnl Implementation notes:
dnl In order to avoid creating type records and vtables for
dnl the various bind type slots, I have factored out the dtor
dnl of the data items. It creates a data node containing
dnl both the adaptor and the extra data which needs to be added.
dnl Then when the adaptor is destroyed it, it calls the dtor
dnl procedure which takes out the extra data.
dnl
dnl It is possible this technique is non-portable though given
dnl the necessary interactions with C code it seems unlikely
dnl to break all but the most exotic of C++ compilers.
dnl (watch Karl eat hat)
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
#include <sigc++/adaptor.h>
/** @defgroup bind
*
* SigC::bind() alters a SigC::Slot by fixing arguments to certain values.
*
* Argument fixing starts from the last argument.
* Up to two arguments can be bound at a time.
*
* Simple sample usage:
* @code
* void f(int, int);
* SigC:Slot2<void, int, int> s1 = SigC::slot(f);
*
* SigC::Slot1<void, int> s2 = SigC::bind(s1,1);
* s2(2); // call f with arguments 2,1
* @endcode
*
* Multibinding usage:
*
* @code
* void f(int,int);
* SigC::Slot2<void, int, int> s1 = SigC::slot(f);
*
* SigC::Slot0<void> s2 = SigC::bind(s1, 1, 2);
* s2(); // call f with arguments 1, 2
* @endcode
*
* Type specified usage:
*
* @code
* class A {};
* class B : public A {};
* B* b;
* SigC::Slot0<void, A*> s1;
*
* SigC::Slot0<void> s2 = SIgC::bind(s1, b); // B* converted to A*
* @endcode
*
*
* SigC::bind_return() alters a Slot by fixing the return value to certain
values
*
* Return value fixing ignores any slot return value. The slot is
* destroyed in the process and a new one is created, so references
* to the slot will no longer be valid.
*
* Typecasting may be necessary to match arguments between the
* slot and the bound return value. Types must be an exact match.
* To ensure the proper type, the type can be explicitly specified
* on template instantation.
*
* Simple sample usage:
* @code
* void f(int, int);
* SigC::Slot1<int, int, int> s1 = SigC::bind_return(slot(&f), 1);
* std::cout << "s2: " << s1(2, 1) << std::endl;
* @endcode
*
* Type specified usage:
* @code
* class A {};
* class B : public A {};
* B* b;
* SigC::Slot1<void> s1;
*
* SigC::Slot0<A*> s2 = SigC::bind_return<A*>(s1, b); // B* must be told to
match A*
* @endcode
*
*/
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
define([FORMAT_ARG_CBINIT],[LOWER([$1])_(LOWER([$1]))])dnl
define([FORMAT_ARG_CBNAME],[node.LOWER([$1])_])dnl
define([FORMAT_ARG_CBDTOR],[node.LOWER([$1])_.~[$1]();])dnl
define([FORMAT_ARG_CBBIND],[[$1] LOWER([$1])_;])dnl
dnl
define([ARG_CBINIT],[PROT(ARG_LOOP([FORMAT_ARG_CBINIT],[[,]],$*))])dnl
define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])dnl
define([ARG_CBDTOR],[PROT(ARG_LOOP([FORMAT_ARG_CBDTOR],[[
]],$*))])dnl
define([ARG_CBBIND],[PROT(ARG_LOOP([FORMAT_ARG_CBBIND],[[
]],$*))])dnl
dnl
/**************************************************************/
// These are internal classes used to represent function varients of slots
// (internal)
struct AdaptorBindSlotNode : public AdaptorSlotNode
{
FuncPtr dtor_;
AdaptorBindSlotNode(FuncPtr proxy, const Node& s, FuncPtr dtor);
virtual ~AdaptorBindSlotNode();
};
dnl
dnl ADAPTOR_BIND_DATA([C0..CM])
dnl
define([ADAPTOR_BIND_DATA],[dnl
template <ARG_CLASS($1)>
struct [AdaptorBindData]NUM($1)_
{
typedef [AdaptorBindData]NUM($1)_ Self;
AdaptorBindSlotNode adaptor;
ARG_CBBIND($1)
AdaptorBindData[]NUM($1)_(FuncPtr p, const Node& s ,FuncPtr d,
ARG_BOTH($1))
: adaptor(p, s, d), ARG_CBINIT($1)
{}
static void dtor(void* data)
{
Self& node = *reinterpret_cast<Self*>(data);
ARG_CBDTOR($1)
}
};
])
dnl
dnl ADAPTOR_BIND_SLOT([P1..PN],[C0..CM],[A0..AM])
dnl
define([ADAPTOR_BIND_SLOT],[dnl
template <LIST(class R,ARG_CLASS($1),ARG_CLASS($2))>
struct [AdaptorBindSlot]NUM($1)[_]NUM($2)_
{
typedef typename Trait<R>::type RType;
typedef typename __SLOT__(R,$1,$2)::Proxy Proxy;
static RType proxy(LIST(ARG_REF($1),void *data))
{
typedef [AdaptorBindData]NUM($2)_<ARG_TYPE($2)> Data;
Data& node=*reinterpret_cast<Data*>(data);
SlotNode* slot=static_cast<SlotNode*>(node.adaptor.slot_.impl());
return ((Proxy)(slot->proxy_))
(LIST(ARG_NAME($1),ARG_CBNAME($2)),slot);
}
};
/// @ingroup bind
template <LIST(ARG_CLASS($3),class R,ARG_CLASS($1),ARG_CLASS($2))>
__SLOT__(R,$1)
bind(const __SLOT__(R,$1,$2)& s,
ARG_BOTH($3))
{
typedef [AdaptorBindData]NUM($2)[_]<ARG_TYPE($2)> Data;
typedef
[AdaptorBindSlot]NUM($1)[_]NUM($2)_<LIST(R,ARG_TYPE($1),ARG_TYPE($2))> Adaptor;
return reinterpret_cast<SlotNode*>(
new Data((FuncPtr)(&Adaptor::proxy),s,
(FuncPtr)(&Data::dtor),ARG_NAME($3)));
}
])
ADAPTOR_BIND_DATA(ARGS(C,1))
ADAPTOR_BIND_DATA(ARGS(C,2))
ADAPTOR_BIND_SLOT(ARGS(P,0),ARGS(C,1),ARGS(A,1))
ADAPTOR_BIND_SLOT(ARGS(P,1),ARGS(C,1),ARGS(A,1))
ADAPTOR_BIND_SLOT(ARGS(P,2),ARGS(C,1),ARGS(A,1))
ADAPTOR_BIND_SLOT(ARGS(P,3),ARGS(C,1),ARGS(A,1))
ADAPTOR_BIND_SLOT(ARGS(P,4),ARGS(C,1),ARGS(A,1))
ADAPTOR_BIND_SLOT(ARGS(P,0),ARGS(C,2),ARGS(A,2))
ADAPTOR_BIND_SLOT(ARGS(P,1),ARGS(C,2),ARGS(A,2))
ADAPTOR_BIND_SLOT(ARGS(P,2),ARGS(C,2),ARGS(A,2))
ADAPTOR_BIND_SLOT(ARGS(P,3),ARGS(C,2),ARGS(A,2))
#ifdef SIGC_CXX_NAMESPACES
} // namespace
#endif
#endif // __header__
--- NEW FILE ---
// -*- c++ -*-
dnl bind_return.h.m4 - adaptor for fixing the return value of a slot.
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
#include <sigc++/bind.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
define([__ARB_SLOT__],[[AdaptorBindReturnSlot]eval(NUM($*)-2)_<LIST($*)>])dnl
dnl
dnl ADAPTOR_BIND_RETURN_SLOT([P1..PN])
dnl
define([ADAPTOR_BIND_RETURN_SLOT],[dnl
/****************************************************************
***** Adaptor Return Bind Slot NUM($1) arguments
****************************************************************/
template <LIST(class R1,class R2,ARG_CLASS($1))>
struct [AdaptorBindReturnSlot]NUM($1)_
{
typedef AdaptorBindData1_<R1> Data;
typedef typename __SLOT__(R2,$1)::Proxy Proxy;
static R1 proxy(LIST(ARG_REF($1),void *data))
{
Data& node = *reinterpret_cast<Data*>(data);
SlotNode* slot = static_cast<SlotNode*>(node.adaptor.slot_.impl());
((Proxy)(slot->proxy_))
(LIST(ARG_NAME($1),slot));
return node.c1_;
}
};
/// @ingroup bind
template <LIST(class R1, class R2,ARG_CLASS($1))>
__SLOT__(R1,$1)
bind_return(const __SLOT__(R2,$1) &s,R1 ret)
{
typedef AdaptorBindData1_<R1> Data;
typedef __ARB_SLOT__(R1,R2,$1) Adaptor;
return reinterpret_cast<SlotNode*>(
new Data((FuncPtr)(&Adaptor::proxy),s,
(FuncPtr)(&Data::dtor),ret));
}
])
ADAPTOR_BIND_RETURN_SLOT(ARGS(P,0))
ADAPTOR_BIND_RETURN_SLOT(ARGS(P,1))
ADAPTOR_BIND_RETURN_SLOT(ARGS(P,2))
ADAPTOR_BIND_RETURN_SLOT(ARGS(P,3))
ADAPTOR_BIND_RETURN_SLOT(ARGS(P,4))
ADAPTOR_BIND_RETURN_SLOT(ARGS(P,5))
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif // __header__
--- NEW FILE ---
// -*- c++ -*-
dnl class_slot.h.m4 - constructs slots for non-complient classes
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef SIGC_CLASS_SLOT
#define SIGC_CLASS_SLOT
#include <sigc++/slot.h>
/*
SigC::slot_class() (class)
-----------------------
slot_class() can be applied to a class method to form a Slot with a
profile equivalent to the method. At the same time an instance
of that class must be specified. This is an unsafe interface.
This does NOT require that the class be derived from SigC::Object.
However, the object should be static with regards to the signal system.
(allocated within the global scope.) If it is not and a connected
slot is call it will result in a segfault. If the object must
be destroyed before the connected slots, all connections must
be disconnected by hand.
Sample usage:
struct A
{
void foo(int, int);
} a;
Slot2<void,int,int> s = slot_class(a, &A::foo);
*/
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
/**************************************************************/
// These are internal classes used to represent function varients of slots
// (internal)
struct ClassSlotNode : public SlotNode
{
typedef void (SlotNode::*Method)(void);
void *object_;
Method method_;
template <class T1, class T2>
ClassSlotNode(FuncPtr proxy,T1* obj,T2 method)
: SlotNode(proxy), object_(obj),
method_(reinterpret_cast<Method>(method))
{}
virtual ~ClassSlotNode();
};
dnl
dnl CLASS_SLOT(ARGS)
dnl
define([CLASS_SLOT],[dnl
template <LIST(class R,ARG_CLASS($1),class Obj)>
struct ClassSlot[]NUM($1)_
{
typedef typename Trait<R>::type RType;
static RType proxy(LIST(ARG_REF($1),void *s))
{
typedef RType (Obj::*Method)(ARG_TYPE($1));
ClassSlotNode* os = (ClassSlotNode*)(s);
return ((Obj*)(os->object_)
->*(reinterpret_cast<Method>(os->method_)))(ARG_NAME($1));
}
};
template <LIST(class R,ARG_CLASS($1),class Obj)>
Slot[]NUM($1)<LIST(R,ARG_TYPE($1))>
slot_class(Obj& obj,R (Obj::*method)(ARG_TYPE($1)))
{
typedef ClassSlot[]NUM($1)_<LIST(R,ARG_TYPE($1),Obj)> SType;
return new ClassSlotNode((FuncPtr)(&SType::proxy),&obj,method);
}
template <LIST(class R, ARG_CLASS($1), class Obj)>
Slot[]NUM($1)<LIST(R, ARG_TYPE($1))>
slot_class(Obj& obj, R (Obj::*method)(ARG_TYPE($1)) const)
{
typedef ClassSlot[]NUM($1)_<LIST(R,ARG_TYPE($1), Obj)> SType;
return new ClassSlotNode((FuncPtr)(&SType::proxy), &obj, method);
}
])
// These do not derive from ClassSlot, they merely are extended
// ctor wrappers. They introduce how to deal with the proxy.
CLASS_SLOT(ARGS(P,0))
CLASS_SLOT(ARGS(P,1))
CLASS_SLOT(ARGS(P,2))
CLASS_SLOT(ARGS(P,3))
CLASS_SLOT(ARGS(P,4))
CLASS_SLOT(ARGS(P,5))
CLASS_SLOT(ARGS(P,6))
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif /* SIGC_CLASS_SLOT */
--- NEW FILE ---
// -*- c++ -*-
dnl hide.h.m4 - hide one or two of the signal's arguments
dnl
// Copyright 2000, Martin Schulze <address@hidden>
// Copyright 2001, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
/** @defgroup hide
* SigC::hide() alters a Slot in that it adds one or two parameters
* whose values are ignored on invocation of the Slot.
* Thus you can discard one or more of the arguments of a Signal.
* You have to specify the type of the parameters to ignore as
* template arguments as in
* @code
* SigC::Slot1<void, int> slot1;
* SigC::Slot0<void> slot2 = SigC::hide<int>(slot1);
* @endcode
*
* SigC::hide_return() alters the Slot by
* dropping its return value, thus converting it to a void Slot.
*
* Simple sample usage:
*
* @code
* int f(int);
* SigC::Slot1<void, int> s = SigC::hide_return( slot(&f) );
* @endcode
*/
#include <sigc++/adaptor.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
dnl
dnl ADAPTOR_HIDE(R,[P1..PN],[H1..HM])
dnl
define([ADAPTOR_HIDE],[dnl
template <LIST(class R,ARG_CLASS($1),ARG_CLASS($2))>
struct [AdaptorHide]NUM($1)[_]NUM($2)_
{
typedef typename Trait<R>::type RType;
static RType proxy(LIST(ARG_REF($1),ARG_REFTYPE($2),[void *data]))
{
AdaptorSlotNode& node = *(AdaptorSlotNode*)(data);
SlotNode* slot=static_cast<SlotNode*>(node.slot_.impl());
return ((typename
__SLOT__(R,$1)::Proxy)(slot->proxy_))(LIST(ARG_NAME($1),slot));
}
};
/// @ingroup hide
template <LIST(ARG_CLASS($2), class R, ARG_CLASS($1))>
__SLOT__(R,[$1],[$2])
hide(const __SLOT__(R,$1)& s)
{
return new AdaptorSlotNode(
(FuncPtr)(&[AdaptorHide]NUM($1)[_]NUM($2)_<LIST(R,ARG_TYPE($1),ARG_TYPE($2))>::proxy),
s );
}
])dnl ADAPTOR_HIDE
ADAPTOR_HIDE(ARGS(P,0),ARGS(H,1))
ADAPTOR_HIDE(ARGS(P,0),ARGS(H,2))
ADAPTOR_HIDE(ARGS(P,1),ARGS(H,1))
ADAPTOR_HIDE(ARGS(P,1),ARGS(H,2))
ADAPTOR_HIDE(ARGS(P,2),ARGS(H,1))
ADAPTOR_HIDE(ARGS(P,2),ARGS(H,2))
ADAPTOR_HIDE(ARGS(P,3),ARGS(H,1))
ADAPTOR_HIDE(ARGS(P,3),ARGS(H,2))
ADAPTOR_HIDE(ARGS(P,4),ARGS(H,1))
#ifdef SIGC_CXX_NAMESPACES
} // namespace SigC
#endif
#endif // __header__
--- NEW FILE ---
// -*- c++ -*-
dnl object_slot.h.m4 - adaptor for changing argument types
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef SIGC_METHOD_SLOT
#define SIGC_METHOD_SLOT
#include <sigc++/slot.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
/**************************************************************/
// These are internal classes used to represent function varients of slots
class Object;
// (internal)
struct MethodSlotNode : public SlotNode
{
typedef void* (Object::*Method)(void*);
Method method_;
template <class T2>
MethodSlotNode(FuncPtr proxy,T2 method)
: SlotNode(proxy)
{ init(reinterpret_cast<MethodSlotNode::Method>(method)); }
void init(Method method);
virtual ~MethodSlotNode();
};
struct ConstMethodSlotNode : public SlotNode
{
typedef void* (Object::*Method)(void*) const;
Method method_;
template <class T2>
ConstMethodSlotNode(FuncPtr proxy,T2 method)
: SlotNode(proxy)
{ init(reinterpret_cast<ConstMethodSlotNode::Method>(method)); }
void init(Method method);
virtual ~ConstMethodSlotNode();
};
dnl
dnl METHOD_SLOT(ARGS)
dnl
define([METHOD_SLOT],[dnl
template <LIST(class R,class Obj,ARG_CLASS($1))>
struct MethodSlot[]NUM($1)_
{
typedef typename Trait<R>::type RType;
static RType proxy(LIST(Obj& obj, ARG_REF($1),void * s))
{
typedef RType (Obj::*Method)(ARG_TYPE($1));
MethodSlotNode* os = (MethodSlotNode*)s;
return ((Obj*)(&obj)
->*(reinterpret_cast<Method>(os->method_)))(ARG_NAME($1));
}
};
template <LIST(class R,class Obj,ARG_CLASS($1))>
struct ConstMethodSlot[]NUM($1)_
{
typedef typename Trait<R>::type RType;
static RType proxy(LIST(Obj& obj, ARG_REF($1),void * s))
{
typedef RType (Obj::*Method)(ARG_TYPE($1)) const;
ConstMethodSlotNode* os = (ConstMethodSlotNode*)s;
return ((Obj*)(&obj)
->*(reinterpret_cast<Method>(os->method_)))(ARG_NAME($1));
}
};
template <LIST(class R,class Obj,ARG_CLASS($1))>
__SLOT__(R,Obj&,$1)
slot(R (Obj::*method)(ARG_TYPE($1)))
{
typedef MethodSlot[]NUM($1)_<LIST(R,Obj,ARG_TYPE($1))> SType;
return new MethodSlotNode((FuncPtr)(&SType::proxy),
method);
}
template <LIST(class R,class Obj,ARG_CLASS($1))>
__SLOT__(R,const Obj&,$1)
slot(R (Obj::*method)(ARG_TYPE($1)) const)
{
typedef ConstMethodSlot[]NUM($1)_<LIST(R,Obj,ARG_TYPE($1))> SType;
return new ConstMethodSlotNode((FuncPtr)(&SType::proxy),
method);
}
])
// These do not derive from MethodSlot, they merely are extended
// ctor wrappers. They introduce how to deal with the proxy.
METHOD_SLOT(ARGS(P,0))
METHOD_SLOT(ARGS(P,1))
METHOD_SLOT(ARGS(P,2))
METHOD_SLOT(ARGS(P,3))
METHOD_SLOT(ARGS(P,4))
METHOD_SLOT(ARGS(P,5))
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif // SIGC_SLOT
--- NEW FILE ---
// -*- c++ -*-
dnl object_slot.h.m4 - adaptor for changing argument types
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef SIGC_OBJECT_SLOT
#define SIGC_OBJECT_SLOT
#include <sigc++/slot.h>
#include <sigc++/object.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
/**************************************************************/
// These are internal classes used to represent function varients of slots
// (internal)
struct ObjectSlotNode : public SlotNode
{
typedef void (Object::*Method)(void);
Control_ *control_;
void *object_;
Method method_;
Link link_;
// Can be a dependency
virtual Link* link();
virtual void notify(bool from_child);
template <class T,class T2>
ObjectSlotNode(FuncPtr proxy,T* control,void *object,T2 method)
: SlotNode(proxy)
{ init(control,object,reinterpret_cast<ObjectSlotNode::Method>(method)); }
void init(Object* control, void* object, Method method);
virtual ~ObjectSlotNode();
};
dnl
dnl OBJECT_SLOT(ARGS)
dnl
define([OBJECT_SLOT],[dnl
template <LIST(class R,ARG_CLASS($1),class Obj)>
struct ObjectSlot[]NUM($1)_
{
typedef typename Trait<R>::type RType;
static RType proxy(LIST(ARG_REF($1),void * s))
{
typedef RType (Obj::*Method)(ARG_TYPE($1));
ObjectSlotNode* os = (ObjectSlotNode*)s;
return ((Obj*)(os->object_)
->*(reinterpret_cast<Method>(os->method_)))(ARG_NAME($1));
}
};
template <LIST(class R,ARG_CLASS($1),class O1,class O2)>
__SLOT__(R,$1)
slot(O1& obj,R (O2::*method)(ARG_TYPE($1)))
{
typedef ObjectSlot[]NUM($1)_<LIST(R,ARG_TYPE($1),O2)> SType;
O2& obj_of_method = obj;
return new ObjectSlotNode((FuncPtr)(&SType::proxy),
&obj,
&obj_of_method,
method);
}
template <LIST(class R,ARG_CLASS($1),class O1,class O2)>
__SLOT__(R,$1)
slot(O1& obj,R (O2::*method)(ARG_TYPE($1)) const)
{
typedef ObjectSlot[]NUM($1)_<LIST(R,ARG_TYPE($1),O2)> SType;
O2& obj_of_method = obj;
return new ObjectSlotNode((FuncPtr)(&SType::proxy),
&obj,
&obj_of_method,
method);
}
])
// These do not derive from ObjectSlot, they merely are extended
// ctor wrappers. They introduce how to deal with the proxy.
OBJECT_SLOT(ARGS(P,0))
OBJECT_SLOT(ARGS(P,1))
OBJECT_SLOT(ARGS(P,2))
OBJECT_SLOT(ARGS(P,3))
OBJECT_SLOT(ARGS(P,4))
OBJECT_SLOT(ARGS(P,5))
OBJECT_SLOT(ARGS(P,6))
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif /* SIGC_OBJECT_SLOT */
--- NEW FILE ---
// -*- c++ -*-
dnl retype.h.m4 - adaptor for changing argument types
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
#include <sigc++/adaptor.h>
/** @defgroup retype
* retype() alters a Slot to change arguments and return type.
*
* Only allowed conversions or conversions to void can properly
* be implemented. The types of the return and all arguments must always
* be specified as a template parameters.
*
* Simple sample usage:
*
* @code
* float f(float,float);
*
* SigC::Slot1<int, int, int> s1 = SigC::retype<int, int, int>(slot(&f));
* @endcode
*
*
* SigC::retype_return() alters a Slot by changing the return type.
*
* Only allowed conversions or conversions to void can properly
* be implemented. The type must always be specified as a
* template parameter.
*
* Simple sample usage:
*
* @code
* int f(int);
*
* SigC::Slot1<void, int> s1 = SigC::retype_return<void>(slot(&f));
* SigC::Slot1<float, int> s2 = SigC::retype_return<float>(slot(&f));
* @endcode
*
* SigC::hide_return() is an easy-to-use variant that converts the Slot by
* dropping its return value, thus converting it to a void slot.
*
* Simple Sample usage:
*
* @code
* int f(int);
* SigC::Slot1<void, int> s = SigC::hide_return( slot(&f) );
* @endcode
*/
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
define([__RETYPE_SLOT__],[[AdaptorRetypeSlot]eval(NUM($*)/2-1)_<LIST($*)>])dnl
dnl
dnl ADAPTOR_RETYPE_SLOT([P1..PN],[Q1..Q2],R)
dnl
define([ADAPTOR_RETYPE_SLOT],[dnl
template <LIST(ifelse($3,void,,class R1), ARG_CLASS($1),class R2,ARG_CLASS($2))>
struct [AdaptorRetypeSlot]NUM($1)_ ifelse($3, void,[<LIST(void,ARG_TYPE($1),
R2,ARG_TYPE($2))>])
{
typedef typename __SLOT__(R2,$2)::Proxy Proxy;
ifelse($3,void,[dnl
static void proxy(LIST(ARG_REF($1), void *data))
],[dnl
typedef typename Trait<R1>::type RType;
static RType proxy(LIST(ARG_REF($1), void *data))
])dnl
{
AdaptorSlotNode& node = *static_cast<AdaptorSlotNode*>(data);
SlotNode* slot=static_cast<SlotNode*>(node.slot_.impl());
ifelse($3,void,[dnl
((Proxy)(slot->proxy_))(LIST(ARG_NAME($1), slot));
],[dnl
return RType(((Proxy)(slot->proxy_))
(LIST(ARG_NAME($1),slot)));
])dnl
}
};
ifelse($3,void,,[dnl
/// @ingroup retype
template <LIST(class R1,ARG_CLASS($1),class R2,ARG_CLASS($2))>
__SLOT__(R1,$1)
retype(const __SLOT__(R2,$2) &s)
{
return new
AdaptorSlotNode((FuncPtr)(&__RETYPE_SLOT__(R1,$1,R2,$2)::proxy),s);
}
])
])
ADAPTOR_RETYPE_SLOT(ARGS(P,0),ARGS(C,0))
ADAPTOR_RETYPE_SLOT(ARGS(P,1),ARGS(C,1))
ADAPTOR_RETYPE_SLOT(ARGS(P,2),ARGS(C,2))
ADAPTOR_RETYPE_SLOT(ARGS(P,3),ARGS(C,3))
ADAPTOR_RETYPE_SLOT(ARGS(P,4),ARGS(C,4))
ADAPTOR_RETYPE_SLOT(ARGS(P,5),ARGS(C,5))
ADAPTOR_RETYPE_SLOT(ARGS(P,6),ARGS(C,6))
#ifndef SIGC_CXX_VOID_CAST_RETURN
ADAPTOR_RETYPE_SLOT(ARGS(P,0),ARGS(C,0),void)
ADAPTOR_RETYPE_SLOT(ARGS(P,1),ARGS(C,1),void)
ADAPTOR_RETYPE_SLOT(ARGS(P,2),ARGS(C,2),void)
ADAPTOR_RETYPE_SLOT(ARGS(P,3),ARGS(C,3),void)
ADAPTOR_RETYPE_SLOT(ARGS(P,4),ARGS(C,4),void)
ADAPTOR_RETYPE_SLOT(ARGS(P,5),ARGS(C,5),void)
ADAPTOR_RETYPE_SLOT(ARGS(P,6),ARGS(C,6),void)
#endif
#ifdef SIGC_CXX_NAMESPACES
} // namespace
#endif
#endif // __header__
--- NEW FILE ---
// -*- c++ -*-
dnl retype_return.h.m4 - adaptor for changing return type
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
#include <sigc++/adaptor.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
define([__ART_SLOT__],[[AdaptorRetypeReturnSlot]eval(NUM($*)-2)_<LIST($*)>])dnl
dnl
dnl ADAPTOR_RETYPE_RETURN_SLOT([P1..PN],R)
dnl
define([ADAPTOR_RETYPE_RETURN_SLOT],[dnl
/****************************************************************
***** Adaptor Return Type Slot, NUM($1) arguments
****************************************************************/
template <LIST(ifelse($2,void,,class R2),class R1,ARG_CLASS($1))>
struct [AdaptorRetypeReturnSlot]NUM($1)_
ifelse($2,void,[<LIST(void,R1,ARG_TYPE($1))>])
{
typedef typename __SLOT__(R1,$1)::Proxy Proxy;
ifelse($2,void,[dnl
static void proxy(LIST(ARG_REF($1),void *data))
],[dnl
typedef typename Trait<R2>::type RType;
static RType proxy(LIST(ARG_REF($1),void *data))
])dnl
{
AdaptorSlotNode& node=*static_cast<AdaptorSlotNode*>(data);
SlotNode* slot=static_cast<SlotNode*>(node.slot_.impl());
ifelse($2,void,[dnl
((Proxy)(slot->proxy_))
(LIST(ARG_NAME($1),slot));
],[dnl
return RType(((Proxy)(slot->proxy_))
(LIST(ARG_NAME($1),slot)));
])dnl
}
};
ifelse($2,void,,[dnl
/// @ingroup retype
template <LIST(class R2, class R,ARG_CLASS($1))>
__SLOT__(R2,$1)
retype_return(const __SLOT__(R,$1) &s)
{
return new AdaptorSlotNode((FuncPtr)(&__ART_SLOT__(R2,R,$1)::proxy),s);
}
/// @ingroup hide
template <LIST(class R, ARG_CLASS($1))>
__SLOT__(void,$1)
hide_return(const __SLOT__(R,$1) &s)
{
return retype_return<void>(s);
}
])dnl
])
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,0))
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,1))
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,2))
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,3))
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,4))
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,5))
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,6))
#ifndef SIGC_CXX_VOID_CAST_RETURN
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,0),void)
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,1),void)
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,2),void)
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,3),void)
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,4),void)
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,5),void)
ADAPTOR_RETYPE_RETURN_SLOT(ARGS(P,6),void)
#endif
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif // __header__
--- NEW FILE ---
// -*- c++ -*-
dnl signal.h.m4 - signal class for sigc++
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
#include <sigc++/slot.h>
#include <sigc++/connection.h>
#include <sigc++/marshal.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
/** @defgroup Signals
* Use connect() with SigC::slot to connect a method or function with a Signal.
*
* @code
* signal_clicked.connect( SigC::slot(*this, &MyWindow::on_clicked) );
* @endcode
*
* When the signal is emitted your method will be called.
*
* connect() returns a Connection, which you can later use to disconnect your
method.
*
* When Signals are copied they share the underlying information,
* so you can have a protected/private SigC::Signal member and a public
accessor method.
*/
class SignalConnectionNode;
class SignalExec_;
class SignalNode : public SlotNode
{
public:
int exec_count_; // atomic
SignalConnectionNode *begin_,*end_;
SignalNode();
~SignalNode();
// must be inline to avoid emission slowdowns.
void exec_reference()
{
reference();
exec_count_ += 1;
}
// must be inline to avoid emission slowdowns.
void exec_unreference()
{
exec_count_ -= 1;
if (defered_ && !exec_count_)
cleanup();
unreference();
}
SlotNode* create_slot(FuncPtr proxy); // nothrow
ConnectionNode* push_front(const SlotBase& s);
ConnectionNode* push_back(const SlotBase& s);
virtual void remove(SignalConnectionNode* c);
bool empty();
void clear();
void cleanup(); // nothrow
};
class SignalBase
{
friend class SignalConnectionNode;
private:
SignalBase& operator= (const SignalBase&); // no copy
protected:
typedef SignalExec_ Exec;
mutable SignalNode *impl_;
SlotNode* create_slot(FuncPtr c) const
{ return impl()->create_slot(c); }
ConnectionNode* push_front(const SlotBase& s)
{ return impl()->push_front(s); }
ConnectionNode* push_back(const SlotBase& s)
{ return impl()->push_back(s); }
SignalBase();
SignalBase(const SignalBase& s);
SignalBase(SignalNode* s);
~SignalBase();
public:
bool empty() const
{ return !impl_ || impl()->empty(); }
void clear()
{
if(impl_)
impl()->clear();
}
SignalNode* impl() const;
};
class SignalConnectionNode : public ConnectionNode
{
public:
virtual void notify(bool from_child);
virtual ~SignalConnectionNode();
SignalConnectionNode(SlotNode*);
SignalNode *parent_;
SignalConnectionNode *next_,*prev_;
SlotNode* dest() { return (SlotNode*)(slot().impl()); }
};
// Exeception-safe class for tracking signals.
class SignalExec_
{
public:
SignalNode* signal_;
SignalExec_(SignalNode* signal) :signal_(signal)
{ signal_->exec_reference(); }
~SignalExec_()
{ signal_->exec_unreference(); }
};
/********************************************************/
define([__SIGNAL__],[[Signal]eval(NUM($*)-2)<LIST($*)>])dnl
dnl
dnl SIGNAL([P1..PN], R)
dnl
define([SIGNAL],[dnl
define([_R_],ifelse($2,void, void, R))
ifelse($2,void, [dnl
/// @ingroup Signals
template <LIST(ARG_CLASS($1), class Marsh)>
class __SIGNAL__(void, $1, Marsh) : public SignalBase
],[dnl
/// @ingroup Signals
template <LIST(class R,ARG_CLASS($1),class Marsh=Marshal<R>) >
class Signal[]NUM($1) : public SignalBase
])dnl
{
public:
typedef Slot[]NUM($1)<LIST(_R_, [$1])> InSlotType;
ifelse($2,void, [dnl
typedef InSlotType OutSlotType;
typedef void OutType;
],[dnl
typedef Slot[]NUM($1)<LIST(typename Marsh::OutType, [$1])> OutSlotType;
typedef typename Trait<typename Marsh::OutType>::type OutType;
])dnl
private:
// Used for both emit and proxy.
static OutType emit_(LIST(ARG_REF($1), void* data));
public:
OutSlotType slot() const
{ return create_slot((FuncPtr)(&emit_)); }
operator OutSlotType() const
{ return create_slot((FuncPtr)(&emit_)); }
/// You can call Connection::disconnect() later.
Connection connect(const InSlotType& s)
{ return Connection(push_back(s)); }
/// Call all the connected methods.
OutType emit(ARG_REF($1))
{ ifelse($2,void, ,return) emit_(LIST(ARG_NAME($1), impl_)); }
/// See emit()
OutType operator()(ARG_REF($1))
{ ifelse($2,void, ,return) emit_(LIST(ARG_NAME($1), impl_)); }
Signal[]NUM($1)()
: SignalBase()
{}
Signal[]NUM($1)(const InSlotType& s)
: SignalBase()
{ connect(s); }
~Signal[]NUM($1)() {}
};
// emit
ifelse($2,void, [dnl
template <LIST(ARG_CLASS($1),class Marsh)>
void __SIGNAL__(void, $1, Marsh)::emit_(LIST(ARG_REF($1), void* data))
{
SignalNode* impl = static_cast<SignalNode*>(data);
if (!impl||!impl->begin_)
return;
Exec exec(impl);
SlotNode* s = 0;
for (SignalConnectionNode* i = impl->begin_; i; i = i->next_)
{
if (i->blocked())
continue;
s = i->dest();
((typename __SLOT__(void, $1)::Proxy)(s->proxy_))(LIST(ARG_NAME($1),
s));
}
return;
}
],[dnl
template <LIST(class R, ARG_CLASS($1), class Marsh)>
typename __SIGNAL__(_R_, $1, Marsh)::OutType
__SIGNAL__(_R_, $1, Marsh)::emit_(LIST(ARG_REF($1), void* data))
{
SignalNode* impl = static_cast<SignalNode*>(data);
if (!impl || !impl->begin_)
return Marsh::default_value();
Exec exec(impl);
Marsh rc;
SlotNode* s = 0;
for (SignalConnectionNode* i = impl->begin_; i; i=i->next_)
{
if (i->blocked()) continue;
s = i->dest();
if (rc.marshal(((typename
__SLOT__(R,$1)::Proxy)(s->proxy_))(LIST(ARG_NAME($1), s))))
return rc.value();
}
return rc.value();
}
])dnl
])
SIGNAL(ARGS(P,0))
SIGNAL(ARGS(P,0),void)
SIGNAL(ARGS(P,1))
SIGNAL(ARGS(P,1),void)
SIGNAL(ARGS(P,2))
SIGNAL(ARGS(P,2),void)
SIGNAL(ARGS(P,3))
SIGNAL(ARGS(P,3),void)
SIGNAL(ARGS(P,4))
SIGNAL(ARGS(P,4),void)
SIGNAL(ARGS(P,5))
SIGNAL(ARGS(P,5),void)
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif // __header__
--- NEW FILE ---
// -*- c++ -*-
dnl slot.h.m4 - slot class for sigc++
dnl
// Copyright 2000, Karl Einar Nelson
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
include(template.macros.m4)
#ifndef __header__
#define __header__
/* FIXME where is the docs buddy! */
/** @defgroup Slots
* Slots are type-safe representations of callback methods and functions.
* A Slot can be constructed from any function, regardless of whether it is
* a global function, a member method, static, or virtual.
*
* Use the SigC::slot() template function to get a SigC::Slot, like so:
* @code
* SigC::Slot1<void, int> slot = SigC::slot(someobj, &SomeClass::somemethod);
* @endcode
* or
* @code
* m_Button.signal_clicked().connect( SigC::slot(*this,
&MyWindow::on_button_clicked) );
* @endcode
* The compiler will complain if SomeClass::somemethod has the wrong signature.
*
* You can also pass slots as method parameters where you might normally pass a
function pointer.
*/
#include <sigc++/node.h>
#include <sigc++/trait.h>
#ifdef SIGC_CXX_NAMESPACES
namespace SigC
{
#endif
// this is a dummy type which we will cast to any static function
typedef void (*FuncPtr)(void*);
// (internal) All Slot types derive from this.
class SlotNode: public NodeBase
{
public:
virtual ~SlotNode()=0;
// node must be dynamic
virtual void add_dependency(NodeBase*);
virtual void remove_dependency(NodeBase*);
// message from child that it has died and we should start
// our shut down. If from_child is true, we do not need
// to clean up the child links.
virtual void notify(bool from_child);
SlotNode(FuncPtr proxy);
FuncPtr proxy_;
NodeBase *dep_;
};
/**************************************************************/
// These are internal classes used to represent function varients of slots
// (internal)
struct FuncSlotNode : public SlotNode
{
FuncPtr func_;
FuncSlotNode(FuncPtr proxy,FuncPtr func);
virtual ~FuncSlotNode();
};
define([__FUNC_SLOT__],[[FuncSlot]eval(NUM($*)-1)_<LIST($*)>])dnl
dnl
dnl FUNC_SLOT(ARGS)
dnl
define([FUNC_SLOT],[dnl
template <LIST(class R,ARG_CLASS($1))>
struct FuncSlot[]NUM($1)_
{
typedef typename Trait<R>::type RType;
typedef RType (*Callback)($1);
static RType proxy(LIST(ARG_REF($1),void *s))
{
return ((Callback)(((FuncSlotNode*)s)->func_))(ARG_NAME($1));
}
};
])
// These do not derive from FuncSlot, they merely hold typedefs and
// static functions on how to deal with the proxy.
FUNC_SLOT(ARGS(P,0))
FUNC_SLOT(ARGS(P,1))
FUNC_SLOT(ARGS(P,2))
FUNC_SLOT(ARGS(P,3))
FUNC_SLOT(ARGS(P,4))
FUNC_SLOT(ARGS(P,5))
FUNC_SLOT(ARGS(P,6))
/**************************************************************/
// Slot# is a holder to a SlotNode, its type is held by type of the
// pointer and not the SlotNode itself. This reduces the
// number and size of type objects.
/// (internal) Typeless Slot base class.
class SlotBase : public Node
{
public:
// For backwards compatiblity
bool connected() const { return valid(); }
// (internal)
SlotNode* operator->() { return static_cast<SlotNode*>(node_); }
protected:
// users don't use slots so we will protect the methods
SlotBase() : Node() {}
SlotBase(const SlotBase& s) : Node(s) {}
~SlotBase() {}
SlotBase& operator =(const SlotBase& s)
{ Node::operator=(s); return *this; }
};
dnl
dnl SLOT([P1...PN])
dnl
dnl Notes,
dnl - changed call to valid() to node_->notified to cut emission time in
dnl half
dnl
define([SLOT],[dnl
/// @ingroup Slots
template <LIST(class R,ARG_CLASS($1))>
class Slot[]NUM($1) : public SlotBase
{
public:
typedef typename Trait<R>::type RType;
typedef R (*Callback)(ARG_TYPE($1));
typedef RType (*Proxy)(LIST(ARG_REF($1),void*));
RType operator ()(ARG_REF($1))
{
if (!node_) return RType();
if (node_->notified_)
{ clear(); return RType(); }
return ((Proxy)(static_cast<SlotNode*>(node_)->proxy_))
(LIST(ARG_NAME($1),node_));
}
Slot[]NUM($1)& operator= (const Slot[]NUM($1) &s)
{
SlotBase::operator=(s);
return *this;
}
Slot[]NUM($1)()
: SlotBase() {}
Slot[]NUM($1)(const Slot[]NUM($1)& s)
: SlotBase(s)
{}
Slot[]NUM($1)(SlotNode* node)
: SlotBase()
{ assign(node); }
Slot[]NUM($1)(Callback callback)
: SlotBase()
{
typedef __FUNC_SLOT__(R,$1) Proxy_;
assign(new FuncSlotNode((FuncPtr)&Proxy_::proxy,(FuncPtr)callback));
}
~Slot[]NUM($1)() {}
};
template <LIST(class R,ARG_CLASS($1))>
__SLOT__(R,$1) slot(R (*func)(ARG_TYPE($1)))
{ return func; }
])
// these represent the callable structure of a slot with various types.
// they are fundimentally just wrappers. They have no differences other
// that the types they cast data to.
SLOT(ARGS(P,0))
SLOT(ARGS(P,1))
SLOT(ARGS(P,2))
SLOT(ARGS(P,3))
SLOT(ARGS(P,4))
SLOT(ARGS(P,5))
SLOT(ARGS(P,6))
#ifdef SIGC_CXX_NAMESPACES
}
#endif
#endif // SIGC_SLOT
--- NEW FILE ---
dnl-----------------------------------------------------------------------
dnl
dnl Karls M4 macros for the signal system used by gtk--
dnl
dnl Copyright 1998, Karl Nelson <address@hidden>
dnl Tero Pulkkinen
dnl
dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Library General Public
dnl License as published by the Free Software Foundation; either
dnl version 2 of the License, or (at your option) any later version.
dnl
dnl This library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Library General Public License for more details.
dnl
dnl You should have received a copy of the GNU Library General Public
dnl License along with this library; if not, write to the Free
dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
dnl
dnl-----------------------------------------------------------------------
dnl Recursion prevention. (Don't attempt to understand why this works!)
changequote(, )dnl
changequote([, ])dnl
/* This is a generated file, do not edit. Generated from __file__ */
pushdef([DIVERSION],divnum)dnl
divert(-1)dnl
ifdef([__template_macros__],[],[
define(__template_macros__)
dnl-----------------------------------------------------------------------
dnl
dnl M4 macros for general sanity
dnl
dnl M4 Quotas are hard to work with, so use braces like autoconf
dnl (which are matched by vi, emacs)
changequote(, )
changequote([, ])
dnl
dnl M4 comments conflict with compiler directives
changecom(, )
dnl BRACE(text) => [text]
dnl When we want something to appear with braces
define([BRACE],[[[$*]]])
dnl
dnl PROT(macro)
dnl If a macro generates an output with commas we need to protect it
dnl from being broken down and interpreted
define([PROT],[[$*]])
dnl
dnl LOWER(string)
dnl lowercase a string
define([LOWER],[translit([$*],[ABCDEFGHIJKLMNOPQRSTUVWXYZ],[abcdefghijklmnopqrstuvwxyz])])
dnl
dnl UPPER(string)
dnl uppercase a string
define([UPPER],[translit([$*],[abcdefghijklmnopqrstuvwxyz],[ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
define([UPPER_SAFE],[translit([$*],[abcdefghijklmnopqrstuvwxyz.-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ__])])
dnl
dnl BASENAME(string)
dnl extract the basename of a string
define([BASENAME],[patsubst([$*],[^.*/],[])])
dnl
dnl M4NAME(string)
dnl extract the basename of a string
define([M4NAME],[patsubst(BASENAME([$*]),[\.m4$],[])])
dnl NUM(arg,arg,...)
dnl M4 defines $# very badly (empty list=1). So we need a better one
dnl define([NUM],[ifelse(len([$*]),0,0,[$#])])
define([NUM],[eval(ifelse([$1],,0,1)ifelse($#,0,0,$#,1,,[+NUM(shift($@))]))])
dnl
dnl IF(cond,string1,string2)
dnl places string1 if length (without spaces) of cond is zero,
dnl else string2
define([IF],[ifelse(len(PROT(translit([$1],[ ]))),0,[$3],[$2])])
dnl define([IF],[ifelse(len(PROT(patsubst([$1],[ ]))),0,[$3],[$2])])
dnl
dnl minclude(filename)
dnl This includes only the macros from a file but throws away the output.
dnl Used to take the macros from a file without getting it extra output.
define([minclude],[IF([$1],[dnl
pushdef([CURRENT_DIVERSION],divnum)dnl
divert(-1)
include($1)
divert(CURRENT_DIVERSION)dnl
popdef([CURRENT_DIVERSION])dnl],[[minclude]])])
dnl
dnl makes the current filename into a string approprate for use as
dnl C identified define. (Defaults to this library name)
dnl
dnl example: (filename test.hh.m4)
dnl __header__ => SIGCXX_TEST_H
dnl __header__(MYHEAD) => MYHEAD_TEST_H
dnl
define([__header__],[ifelse($1,,[SIGCXX],UPPER($1))[_]UPPER(patsubst(translit(BASENAME(__file__),[.-],[__]),[_m4],[]))])
define([__header__],[ifelse($1,,[SIGC],UPPER($1))[_]UPPER_SAFE(M4NAME(__file__))])
dnl
dnl Set of M4 macros for variable argument template building
dnl
dnl ARGS(name,number)
dnl Builds a comma seperated protected list of numbered names
dnl Use this as short hand to specify arguement names
dnl
dnl ARGS(arg,3) => ARG1,ARG2,ARG3
define([_ARGS],[ifelse(eval($2<$3),0,[$1$2],[$1$2,_ARGS($1,eval($2+1),$3)])])
define([ARGS],[ifelse(eval($2>0),1,[PROT(_ARGS(UPPER([$1]),1,$2))],[PROT])])
dnl
dnl LIST(string1,string2,...)
dnl These are intended for making extended argument lists
dnl parameters are in pairs, the first is output if the
dnl 2nd is nonzero length, the process is then repeated
dnl with the next set of arguments.
dnl
dnl Macro expansions that expand to result in commas must call
dnl PROT to prevent permature expansion. ARG* macros do
dnl this automatically. (If unsure, add braces until it stops
dnl interpreting inter macros, remove one set of braces, if
dnl still not right use PROT)
dnl
dnl (LIST is probably the most useful macro in the set.)
define([LIST],[ifelse($#,0,,$#,1,[$1],[$1],,[LIST(shift($@))],[__LIST($@)])])
define([__LIST],[ifelse($#,0,,$#,1,[$1],[$1[]ifelse([$2],,,[[,]])__LIST(shift($@))])])
dnl
dnl ARG_LOOP(macro_name,seperator,argument_list)
dnl Very powerful macro for construction of list of variables
dnl formated in specify ways. To use define a macro taking
dnl one variable which is called the format. The second argument
dnl is a seperator which will appear between each argument.
dnl The rest is then interpreted as arguments to form the list.
dnl
dnl Example:
dnl define([FOO],[foo([$1])])
dnl ARG_LOOP([FOO],[[, ]],A,B,C)
dnl
dnl Gives: foo(A), foo(B), foo(C)
dnl
define([_ARG_LOOP],[dnl
ifelse(NUM($*),0,,NUM($*),1,[dnl
indir(LOOP_FORMAT,[$1])],[dnl
indir(LOOP_FORMAT,[$1])[]LOOP_SEPERATOR[]_ARG_LOOP(shift($*))])])
define([ARG_LOOP],[dnl
pushdef([LOOP_FORMAT],[[$1]])dnl
pushdef([LOOP_SEPERATOR],[$2])dnl
_ARG_LOOP(shift(shift($*)))[]dnl
popdef([LOOP_FORMAT])dnl
popdef([LOOP_SEPERATOR])dnl
])
dnl
dnl Define some useful formats for use with ARG_LOOP.
define([FORMAT_ARG_CLASS],[class [$1]])
define([FORMAT_ARG_BOTH],[[$1] LOWER([$1])])
define([FORMAT_ARG_REF],[typename Trait<[$1]>::ref LOWER([$1])])
define([FORMAT_ARG_REFTYPE],[typename Trait<[$1]>::ref])
define([FORMAT_ARG_TYPE],[[$1]])
define([FORMAT_ARG_NAME],[LOWER($1)])
define([FORMAT_ARG_CBNAME],[LOWER($1)_])
define([FORMAT_ARG_CBDECL],[[$1] LOWER([$1])_;])
define([FORMAT_ARG_CBINIT],[LOWER([$1])_(LOWER([$1]))])
dnl
dnl The following functions generate various types of parameter lists
dnl For parameter lists
dnl ARG_CLASS([P1,P2]) -> class P1,class P2
dnl ARG_BOTH([P1,P2]) -> P1 p1,P2 p2
dnl ARG_TYPE([P1,P2]) -> P1,P2
dnl ARG_NAME([P1,P2]) -> p1,p2
dnl For callback lists
dnl ARG_CBNAME([C1,C2]) -> c1_,c2_
dnl ARG_CBINIT([C1,C2]) -> c1_(c1),c2_(c2)
dnl ARG_CBDECL([C1,C2]) -> C1 c1_; C2 c2_;
dnl
define([ARG_CLASS],[PROT(ARG_LOOP([FORMAT_ARG_CLASS],[[,]],$*))])
define([ARG_BOTH],[PROT(ARG_LOOP([FORMAT_ARG_BOTH],[[,]],$*))])
define([ARG_REF],[PROT(ARG_LOOP([FORMAT_ARG_REF],[[,]],$*))])
define([ARG_REFTYPE],[PROT(ARG_LOOP([FORMAT_ARG_REFTYPE],[[,]],$*))])
define([ARG_TYPE],[PROT([$*])])
define([ARG_NAME],[PROT(LOWER($*))])
define([ARG_CBNAME],[PROT(ARG_LOOP([FORMAT_ARG_CBNAME],[[,]],$*))])
define([ARG_CBDECL],[PROT(ARG_LOOP([FORMAT_ARG_CBDECL],[ ],$*))])
define([ARG_CBINIT],[PROT(ARG_LOOP([FORMAT_ARG_CBINIT],[[,]],$*))])
dnl
dnl T_DROP(string)
dnl Removes unnecessary <> with empty templates
dnl (occasionally useful)
define([T_DROP],[ifelse([$1],<>,,[$*])])
dnl
dnl DROP(string,drop)
dnl Removes unnecessary strings if they match drop
dnl (occasionally useful)
define([DROP],[ifelse([$1],[$2],,[$*])])
dnl
dnl LINE(linenum)
dnl places a #line statement if __debug__ set
dnl Use this at top of macro template and following
dnl macros that contain newlines.
dnl
dnl example:
dnl LINE(]__line__[)dnl
define([LINE],[ifdef([__debug__],[#line $1 "]__file__["
])])
dnl-----------------------------------------------------------------------
dnl Libsigc++ macros to simpilify typing of internal macros
define([TYPEDEF_RTYPE],[
ifelse($1,void,[dnl
typedef void $2;dnl
],[dnl
#ifdef SIGC_CXX_PARTIAL_SPEC
typedef $1 $2;
#else
typedef typename Trait<$1>::type $2;
#endif])])
define([__SLOT__],[[Slot]eval(NUM($*)-1)<LIST($*)>])
([QT_FIREWALL],[dnl
// Qt steals a method name.
#ifdef SIGC_QT
#undef emit
#endif
#ifdef emit
#define SIGC_QT
#undef emit
#endif
])
define([END_QT_FIREWALL],[dnl
#ifdef SIGC_QT
#define emit
#endif
])
dnl-----------------------------------------------------------------------
dnl End of recursion protection. Do not put anything below this line.
])
divert(DIVERSION)dnl
popdef([DIVERSION])dnl
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paragui-cvs] CVS: paragui/src/libsigc++/sigc++/macros Makefile.am,NONE,1.1.2.1 README,NONE,1.1.2.1 bind.h.m4,NONE,1.1.2.1 bind_return.h.m4,NONE,1.1.2.1 class_slot.h.m4,NONE,1.1.2.1 hide.h.m4,NONE,1.1.2.1 method_slot.h.m4,NONE,1.1.2.1 object_slot.h.m4,NONE,1.1.2.1 retype.h.m4,NONE,1.1.2.1 retype_return.h.m4,NONE,1.1.2.1 signal.h.m4,NONE,1.1.2.1 slot.h.m4,NONE,1.1.2.1 template.macros.m4,NONE,1.1.2.1,
Alexander Pipelka <address@hidden> <=
- Prev by Date:
[paragui-cvs] CVS: paragui/src/libsigc++/doc/manual Makefile.am,NONE,1.1.2.1 README,NONE,1.1.2.1 libsigc_manual.xml,NONE,1.1.2.1
- Next by Date:
[paragui-cvs] CVS: paragui Makefile.am,1.3.2.2,1.3.2.3
- Previous by thread:
[paragui-cvs] CVS: paragui/src/libsigc++/doc/manual Makefile.am,NONE,1.1.2.1 README,NONE,1.1.2.1 libsigc_manual.xml,NONE,1.1.2.1
- Next by thread:
[paragui-cvs] CVS: paragui Makefile.am,1.3.2.2,1.3.2.3
- Index(es):