Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

test-conn.cc

Go to the documentation of this file.
00001 // test-conn.cc
00002 // g++ -g -Wall -o test-conn test-conn.cc `sigc-config --cflags --libs`
00003 #include <sigc++/sigc++.h>
00004 #include <sigc++/chain.h>
00005 #include <iostream>
00006 
00007 using namespace SigC;
00008 
00009 Signal0<void> global_sig;
00010 
00011 class C : public Object
00012 {
00013     int fInt;
00014 public:
00015     C() : fInt(42) { cerr << "C()\n"; }
00016     ~C() { cerr << "~C()\n"; }
00017     Signal0<void> sig;
00018     int Get() { return fInt; }
00019 };
00020 
00021 class B : public Object
00022 {
00023 public:
00024     B() { cerr << "B()\n"; }
00025     ~B() { cerr << "~B()\n"; }
00026     void beep(C* c) { cerr << "c=" << (void*)c << "\n"; }
00027 };
00028 
00029 class A : public Object
00030 {
00031     Ptr<B> bptr;
00032 public: 
00033     A() { cerr << "A()\n"; }
00034     ~A() { cerr << "~A()\n"; }
00035     void Set(B* b) { bptr = b; }
00036 };
00037 
00038 
00039 class Main  : public Object
00040 {
00041     A* a;
00042     C* c;
00043     Connection connection;
00044     bool save_connect;
00045     bool disconnect;
00046 
00047 public:
00048     Main(bool savecon, bool dodiscon, bool doglobalsig) 
00049         : save_connect(savecon), disconnect(dodiscon) {
00050  
00051         c = new C;
00052         a = new A; 
00053         B* b = manage(new B);
00054         a->Set(b);
00055         if (save_connect)
00056             connection = c->sig.connect(bind(slot(*b,&B::beep),c));
00057         else
00058             c->sig.connect(bind(slot(*b,&B::beep),c));
00059 
00060         if (doglobalsig)
00061             global_sig.connect(slot(*this,&Main::hello));
00062 
00063     }
00064     void hello () { cerr << "Hello!\n"; }
00065     ~Main() {
00066         cerr << "In ~Main\n";
00067         if (save_connect && disconnect) connection.disconnect();
00068         delete a;
00069         delete c;
00070     }        
00071 };
00072 
00073 
00074 int main (int argc, char *argv[])
00075 {
00076     if (argc != 4) {
00077         cerr << "usage: test-conn <saveconnnection> <do-disconnect> <do-global-sig>\n";
00078         cerr << "eg: test-con t t f\n";
00079         return 1;
00080     }
00081 
00082     bool one =   (argv[1][0] == 't');
00083     bool two =   (argv[2][0] == 't');
00084     bool three = (argv[3][0] == 't');
00085 
00086     Main* m = new Main(one,two,three);
00087     delete m;
00088 
00089     cerr << "Making a C\n";
00090     C* c = new C;
00091     cerr << ".. made\n";
00092     c->sig.emit();
00093 
00094     return 0;
00095 } // end of main()

Generated on Thu Nov 1 11:53:20 2007 for loon by  doxygen 1.3.9.1