Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:11.4
libsigc++12
examples.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File examples.diff of Package libsigc++12
--- examples/hello_world.cc +++ examples/hello_world.cc @@ -4,19 +4,19 @@ #include <string> #include <sigc++/sigc++.h> -#ifdef SIGC_CXX_NAMESPACES -using namespace std; -using namespace SigC; +#ifndef SIGC_CXX_NAMESPACES +# define SigC:: +# define std:: #endif -void print(const string &str) - {cout << str;} +void print(const std::string &str) + {std::cout << str;} -main() - { - Signal1<void,const string &> printer; +int main(int, char**) +{ + SigC::Signal1<void,const std::string &> printer; - printer.connect(slot(print)); + printer.connect(slot(print)); - printer("hello world\n"); - } + printer("hello world\n"); +} --- examples/signals.cc +++ examples/signals.cc @@ -10,81 +10,106 @@ // (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; +#ifndef SIGC_CXX_NAMESPACES +# define std:: +# define 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;} +int foo1(int i) +{ std::cout<<"f("<<i<<");"<<std::endl; + return 1; +} + +int foo2(int i) +{ + std::cout<<"sig2::f("<<i<<");"<<std::endl; + return 1; +} + +void foo1v(int i) +{ + std::cout<<"fv("<<i<<");"<<std::endl; +} + +void foo2v(int i) +{ + std::cout<<"sig2::fv("<<i<<");"<<std::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; +struct A:public SigC::Object +{ + int foo(int i) + { + std::cout<<"A::f("<<i<<");"<<std::endl; + return 1; + } + + void foov(int i) + { + std::cout<<"A::fv("<<i<<");"<<std::endl; + } + + A() {} +}; + + +int main(int, char **) +{ + 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); - } + // Lets declare a few signals. + SigC::Signal1<int,int> sig1; // int sig1(int); + SigC::Signal1<int,int> sig2; // int sig2(int); + + // The return type is allowed to be void. + SigC::Signal1<void,int> sig1v; // void sig(int); + SigC::Signal1<void,int> sig2v; // void sig2(int); + + // (5) After the signals are declared you can establish + // connections between them and functions and methods. + std::cout << ">> Connect to signals "<< std::endl; + + // Connect to function foo. + sig1.connect(SigC::slot(foo1)); + + // Connect to method foo of object a. + sig1.connect(SigC::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(SigC::slot(foo1v)); + sig1v.connect(SigC::slot(a,&A::foov)); + sig1v.connect(sig2v.slot()); + + sig2.connect(SigC::slot(foo2)); + sig2v.connect(SigC::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.) + std::cout << ">> Emit signals "<< std::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); +}
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor