backup
authorMichael Andres <ma@suse.de>
Mon, 28 Jul 2008 09:26:44 +0000 (09:26 +0000)
committerMichael Andres <ma@suse.de>
Mon, 28 Jul 2008 09:26:44 +0000 (09:26 +0000)
devel/devel.ma/MaTest.cc
devel/devel.ma/testdrafts/SigTrackableFail.cc [new file with mode: 0644]

index 5d743e3..a463ed3 100644 (file)
@@ -17,16 +17,16 @@ namespace boost
     return str << "Connected slots: " << obj.num_slots();
   }
 
- namespace signals
- {
-  std::ostream & operator<<( std::ostream & str, const connection & obj )
+  namespace signals
   {
-    return str << "Connection: "
-        << ( obj.connected() ? '*' : '_' )
-        << ( obj.blocked()   ? 'B' : '_' )
-        ;
+    std::ostream & operator<<( std::ostream & str, const connection & obj )
+    {
+      return str << "Connection: "
+          << ( obj.connected() ? '*' : '_' )
+          << ( obj.blocked()   ? 'B' : '_' )
+          ;
+    }
   }
- }
 }
 
 using namespace zypp;
@@ -56,7 +56,9 @@ struct M
   void ping() const
   {
     static unsigned i = 0;
-    _sigA( ++i );
+    ++i;
+    MIL << i << " -> " << _sigA << endl;
+    _sigA( i );
   }
 
   typedef signal<void(unsigned)> SigA;
@@ -68,14 +70,16 @@ struct M
 
 struct X : public trackable
 {
-  X() {++s;}
-  X( const X & ) {++s;}
-  ~X() {--s;}
+  X() {_s=++s;}
+  X( const X & ) {_s=++s;}
+  X& operator=( const X & ) { return *this; }
+  ~X() {_s=-_s;}
   static int s;
+  int _s;
 
   void pong( unsigned i ) const
   {
-    DBG << s << ' ' << i << endl;
+    DBG << _s << ' ' << i << endl;
   }
 };
 
@@ -91,6 +95,7 @@ int main( int argc, const char * argv[] )
   --argc; ++argv; // skip arg 0
 
   M m;
+  m.ping();
   X xx;
   m.siga().connect( boost::bind( &X::pong, &xx, _1 ) );
   m.ping();
@@ -99,6 +104,11 @@ int main( int argc, const char * argv[] )
     X x;
     m.siga().connect( boost::bind( &X::pong, &x, _1 ) );
     m.ping();
+
+    X y;
+    m.siga().connect( boost::bind( &X::pong, &y, _1 ) );
+    m.ping();
+
   }
 
   m.ping();
diff --git a/devel/devel.ma/testdrafts/SigTrackableFail.cc b/devel/devel.ma/testdrafts/SigTrackableFail.cc
new file mode 100644 (file)
index 0000000..a463ed3
--- /dev/null
@@ -0,0 +1,121 @@
+#include <iostream>
+
+#include <boost/signal.hpp>
+#include <boost/bind.hpp>
+
+#include <zypp/base/LogTools.h>
+#include <zypp/base/Easy.h>
+
+using std::endl;
+using std::cout;
+
+namespace boost
+{
+  template<class Tp>
+      std::ostream & operator<<( std::ostream & str, const signal<Tp> & obj )
+  {
+    return str << "Connected slots: " << obj.num_slots();
+  }
+
+  namespace signals
+  {
+    std::ostream & operator<<( std::ostream & str, const connection & obj )
+    {
+      return str << "Connection: "
+          << ( obj.connected() ? '*' : '_' )
+          << ( obj.blocked()   ? 'B' : '_' )
+          ;
+    }
+  }
+}
+
+using namespace zypp;
+
+using boost::signal;
+using boost::signals::connection;
+using boost::signals::trackable;
+
+struct HelloWorld
+{
+  HelloWorld() {++i;}
+  HelloWorld(const HelloWorld &) {++i;}
+  ~HelloWorld() { --i;}
+
+  void operator()(unsigned) const
+  {
+    USR << "Hello, World! " << i << std::endl;
+  }
+
+  static int i;
+};
+
+int HelloWorld::i = 0;
+
+struct M
+{
+  void ping() const
+  {
+    static unsigned i = 0;
+    ++i;
+    MIL << i << " -> " << _sigA << endl;
+    _sigA( i );
+  }
+
+  typedef signal<void(unsigned)> SigA;
+
+  SigA & siga() const { return _sigA; }
+
+  mutable SigA _sigA;
+};
+
+struct X : public trackable
+{
+  X() {_s=++s;}
+  X( const X & ) {_s=++s;}
+  X& operator=( const X & ) { return *this; }
+  ~X() {_s=-_s;}
+  static int s;
+  int _s;
+
+  void pong( unsigned i ) const
+  {
+    DBG << _s << ' ' << i << endl;
+  }
+};
+
+int X::s;
+
+/******************************************************************
+**
+**      FUNCTION NAME : main
+**      FUNCTION TYPE : int
+*/
+int main( int argc, const char * argv[] )
+{
+  --argc; ++argv; // skip arg 0
+
+  M m;
+  m.ping();
+  X xx;
+  m.siga().connect( boost::bind( &X::pong, &xx, _1 ) );
+  m.ping();
+
+  {
+    X x;
+    m.siga().connect( boost::bind( &X::pong, &x, _1 ) );
+    m.ping();
+
+    X y;
+    m.siga().connect( boost::bind( &X::pong, &y, _1 ) );
+    m.ping();
+
+  }
+
+  m.ping();
+
+  ///////////////////////////////////////////
+
+  INT << "---STOP" << endl;
+  return 0;
+}
+