paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: paragui/src/libsigc++/examples Makefile.am,NONE,1.1.2


From: Alexander Pipelka <address@hidden>
Subject: [paragui-cvs] CVS: paragui/src/libsigc++/examples Makefile.am,NONE,1.1.2.1nine.h.m4,NONE,1.1.2.1signals.cc,NONE,1.1.2.1
Date: Mon, 03 Feb 2003 19:08:18 -0500

Update of /cvsroot/paragui/paragui/src/libsigc++/examples
In directory subversions:/tmp/cvs-serv19686/src/libsigc++/examples

Added Files:
      Tag: devel-opengl
        Makefile.am hello_world.cc nine.h.m4 signals.cc 
Log Message:
added libsigc++ 1.2.3 (building statically linked versions, Win32)
physfs autoconf / automake fixes



--- NEW FILE ---
EXTRA_DIST = nine.h.m4

# Override DEFS and DEFAULT_INCLUDES to suppress "-I. -I$(srcdir)".
DEFS = @DEFS@
DEFAULT_INCLUDES =
INCLUDES = -I$(top_builddir) -I$(top_srcdir) -I$(top_builddir)/sigc++/config
LDADD = $(top_builddir)/sigc++/libsigc-1.2.la

noinst_PROGRAMS = signals hello_world

signals_SOURCES = signals.cc
hello_world_SOURCES = hello_world.cc


--- NEW FILE ---
// Copyright 1999 Karl Nelson.

#include <iostream>
#include <string>
#include <sigc++/sigc++.h>

#ifdef SIGC_CXX_NAMESPACES
using namespace std;
using namespace SigC;
#endif

void print(const string &str) 
  {cout << str;}

main()
  {
   Signal1<void,const string &> printer;

   printer.connect(slot(print));

   printer("hello world\n");
  }

--- NEW FILE ---
// Okay, so you want the signal system to expand to accept a 
// number of arguments not in the distribution.  You could hack the 
// library header files to support it, but then you would have to 
// distribute these with your program.  Further, that copy would fall 
// out of date, and probably wouldn't compile later.  Or you can request
// that we add one more argument to distribution.  This increasing the size
// of everyones library.  This would quickly get out of hand, So not a 
// good idea.
//
// Fortunately, you can just use the current macros provided and ask 
// them to build a header file for any number of arguments you require.  
// 
// Here is how to do it: (using Signal9 as an example)
//


// (1) Include the master template macros.
include(template.macros.m4)


// (2) Use minclude to take the macros from the standard distrubution.
//  minclude dumps all of the header files normal output.
//  (order doesn't matter)
minclude(slot.h.m4)
minclude(basic_signal.h.m4)
minclude(func_slot.h.m4)
minclude(object_slot.h.m4)


// (3) Place the usual C declarations, comments and such 
//   (Be warned:  m4 can interpret things as m4 macros if not 
//    careful and will eat braces.  Therefore, keep it to a minumum.)
#ifndef _NINE_H_
#define _NINE_H_


// (4) Call the macros with the number of arguments you require.
//   (order matters)

// (4a) Because this is a new signal type, an slot must be build
//   first.
SLOT(ARGS(P,9))

// (4b) Now we can make the signal.  
BASIC_SIGNAL(ARGS(P,9))

// (4c) Then define the slot types we wish to use.
//   (you don't need to make all of the slots, just the ones you plan to use)
FUNCTION_SLOT(ARGS(P,9))
OBJECT_SLOT(ARGS(P,9))

// (if you just need a new slot, say a Data slot with 3 callbacks for an
//  already defined signal type, skip steps 4a and 4b)
#endif


//
// (5) Run m4 against the macro file and redirect to your new header file
//   m4 -I/usr/local/include/sigc++/macros nine.h.m4 > nine.h
//
// (6) Include this new header file in your program.
//
// (7) Distribute only the m4 file, so that changes in the library are
//   reflected in your header file on the users system.
//



--- NEW FILE ---
// Copyright 1999 Karl Nelson.
// 
// Okay here is a complete primer on basic use of signals.

#include <iostream>
// (1) Include the signal system in headers file.
#include <sigc++/sigc++.h>


// (2) If your compiler supports name spaces, you should use namespace SigC
//  It is not necessary to include the entire space.  However, if you 
//  include all you should do so in each source file.   
#ifdef SIGC_CXX_NAMESPACES
using namespace std;
using namespace SigC;
#endif

// Some procedures to connect to. 
int foo1(int i)   {cout<<"f("<<i<<");"<<endl;        return 1;}
int foo2(int i)   {cout<<"sig2::f("<<i<<");"<<endl;  return 1;}
void foo1v(int i) {cout<<"fv("<<i<<");"<<endl;}
void foo2v(int i) {cout<<"sig2::fv("<<i<<");"<<endl;}

// (3) Objects which are to be connected must be derived from SigC::Object.
struct A:public Object
  {
   int foo(int i)   {cout<<"A::f("<<i<<");"<<endl;   return 1;}
   void foov(int i) {cout<<"A::fv("<<i<<");"<<endl;}
   A() {}
  };


main()
  {
   A a;

   // (4) Signals can be declared anywhere, including as class members
   // Their size is about that of 2 pointers.
   // Signals contain their callback signature as template parameters.
   // The number following it is the number of parameters, and the
   // first argument is the return type.
   //  
   // So to declare a signal called like int foo(int) would be 
   //    Signal1< int, int> foo;
  
   // Lets declare a few signals.
   Signal1<int,int> sig1;    // int sig1(int);
   Signal1<int,int> sig2;    // int sig2(int);

   // The return type is allowed to be void.
   Signal1<void,int> sig1v;  // void sig(int);
   Signal1<void,int> sig2v;  // void sig2(int);

   // (5) After the signals are declared you can establish
   // connections between them and functions and methods.
   cout << ">> Connect to signals "<< endl;

   // Connect to function foo.
   sig1.connect(slot(foo1));

   // Connect to method foo of object a.
   sig1.connect(slot(a,&A::foo));

   // Connect to signal 1 to signal 2.  Thus all things in signal2
   // are also called.
   sig1.connect(sig2.slot());

   // We can do the same for the void signals.
   sig1v.connect(slot(foo1v));
   sig1v.connect(slot(a,&A::foov));
   sig1v.connect(sig2v.slot());

   sig2.connect(slot(foo2));
   sig2v.connect(slot(foo2v));

   // (6) After connection the signals can be "emitted".
   // This calls all the callbacks stored within the signal.
   // (Emits are generally called reverse of the order connected,
   // however this is implementation specific.)
   cout << ">> Emit signals "<< endl;

   // Explicitly calling the emits.
   sig1.emit(1);
   sig1v.emit(2);

   // Or alternatively they can be called as a function object
   // with operator()
   sig1(1);
   sig1v(2);
  }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]