// Copyright 1999 Karl Nelson. // // Okay here is a complete primer on basic use of signals. #include // (1) Include the signal system in headers file. #include // (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("< foo; // Lets declare a few signals. Signal1 sig1; // int sig1(int); Signal1 sig2; // int sig2(int); // The return type is allowed to be void. Signal1 sig1v; // void sig(int); Signal1 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); }