]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/generic/callback.cpp
refactored plugin api; refactored callback library; added signals library
[xonotic/netradiant.git] / libs / generic / callback.cpp
index 6152b9dcd8ea4dc32621f0b71151247736ba30aa..2344830aecfc2679f2fcd0ece86442e02dc81bb4 100644 (file)
@@ -107,3 +107,179 @@ namespace ExampleReferenceCaller
 }
 
 #endif
+
+namespace
+{
+  class A1
+  {
+  };
+  class A2
+  {
+  };
+  class A3
+  {
+  };
+  class A4
+  {
+  };
+
+  class Test
+  {
+  public:
+    void test0()
+    {
+    }
+    typedef Member<Test, void, &Test::test0> Test0;
+    typedef MemberCaller<Test, &Test::test0> Test0Caller;
+    void test0const() const
+    {
+    }
+    typedef ConstMember<Test, void, &Test::test0const> Test0Const;
+    typedef ConstMemberCaller<Test, &Test::test0const> Test0ConstCaller;
+    void test1(A1)
+    {
+    }
+    typedef Member1<Test, A1, void, &Test::test1> Test1;
+    typedef MemberCaller1<Test, A1, &Test::test1> Test1Caller;
+    void test1const(A1) const
+    {
+    }
+    typedef ConstMember1<Test, A1, void, &Test::test1const> Test1Const;
+    typedef ConstMemberCaller1<Test, A1, &Test::test1const> Test1ConstCaller;
+    void test2(A1, A2)
+    {
+    }
+    typedef Member2<Test, A1, A2, void, &Test::test2> Test2;
+    void test2const(A1, A2) const
+    {
+    }
+    typedef ConstMember2<Test, A1, A2, void, &Test::test2const> Test2Const;
+    void test3(A1, A2, A3)
+    {
+    }
+    typedef Member3<Test, A1, A2, A3, void, &Test::test3> Test3;
+    void test3const(A1, A2, A3) const
+    {
+    }
+    typedef ConstMember3<Test, A1, A2, A3, void, &Test::test3const> Test3Const;
+  };
+
+  void test0free()
+  {
+  }
+  typedef FreeCaller<&test0free> Test0FreeCaller;
+  void test1free(A1)
+  {
+  }
+  typedef FreeCaller1<A1, &test1free> Test1FreeCaller;
+  void test2free(A1, A2)
+  {
+  }
+  typedef Function2<A1, A2, void, &test2free> Test2Free;
+  void test3free(A1, A2, A3)
+  {
+  }
+  typedef Function3<A1, A2, A3, void, &test3free> Test3Free;
+
+
+  void test0(Test& test)
+  {
+  }
+  typedef ReferenceCaller<Test, &test0> Test0Caller;
+
+  void test0const(const Test& test)
+  {
+  }
+  typedef ConstReferenceCaller<Test, &test0const> Test0ConstCaller;
+
+  void test0p(Test* test)
+  {
+  }
+  typedef PointerCaller<Test, &test0p> Test0PCaller;
+
+  void test0constp(const Test* test)
+  {
+  }
+  typedef ConstPointerCaller<Test, &test0constp> Test0ConstPCaller;
+
+  void test1(Test& test, A1)
+  {
+  }
+  typedef ReferenceCaller1<Test, A1, &test1> Test1Caller;
+
+  void test1const(const Test& test, A1)
+  {
+  }
+  typedef ConstReferenceCaller1<Test, A1, &test1const> Test1ConstCaller;
+
+  void test1p(Test* test, A1)
+  {
+  }
+  typedef PointerCaller1<Test, A1, &test1p> Test1PCaller;
+
+  void test1constp(const Test* test, A1)
+  {
+  }
+  typedef ConstPointerCaller1<Test, A1, &test1constp> Test1ConstPCaller;
+
+  void test2(Test& test, A1, A2)
+  {
+  }
+  typedef Function3<Test&, A1, A2, void, &test2> Test2;
+
+  void test3(Test& test, A1, A2, A3)
+  {
+  }
+  typedef Function4<Test&, A1, A2, A3, void, &test3> Test3;
+
+  void instantiate()
+  {
+    Test test;
+    const Test& testconst = test;
+    {
+      Callback a = Test0FreeCaller();
+      Callback b = Test::Test0Caller(test);
+      b = makeCallback0(Test::Test0(), test);
+      Callback c = Test::Test0ConstCaller(testconst);
+      c = makeCallback0(Test::Test0Const(), test);
+      Callback d = Test0Caller(test);
+      Callback e = Test0ConstCaller(testconst);
+      Callback f = Test0PCaller(&test);
+      Callback g = Test0ConstPCaller(&testconst);
+      a();
+      bool u = a != b;
+    }
+    {
+      typedef Callback1<A1> TestCallback1;
+      TestCallback1 a = Test1FreeCaller();
+      TestCallback1 b = Test::Test1Caller(test);
+      b = makeCallback1(Test::Test1(), test);
+      TestCallback1 c = Test::Test1ConstCaller(testconst);
+      c = makeCallback1(Test::Test1Const(), test);
+      TestCallback1 d = Test1Caller(test);
+      TestCallback1 e = Test1ConstCaller(testconst);
+      TestCallback1 f = Test1PCaller(&test);
+      TestCallback1 g = Test1ConstPCaller(&testconst);
+      a(A1());
+      bool u = a != b;
+    }
+    {
+      typedef Callback2<A1, A2> TestCallback2;
+      TestCallback2 a = makeStatelessCallback2(Test2Free());
+      TestCallback2 b = makeCallback2(Test2(), test);
+      TestCallback2 c = makeCallback2(Test::Test2(), test);
+      TestCallback2 d = makeCallback2(Test::Test2Const(), test);
+      a(A1(), A2());
+      bool u = a != b;
+    }
+    {
+      typedef Callback3<A1, A2, A3> TestCallback3;
+      TestCallback3 a = makeStatelessCallback3(Test3Free());
+      TestCallback3 b = makeCallback3(Test3(), test);
+      TestCallback3 c = makeCallback3(Test::Test3(), test);
+      TestCallback3 d = makeCallback3(Test::Test3Const(), test);
+      a(A1(), A2(), A3());
+      bool u = a != b;
+    }
+  }
+}