From e7b043b1ac0d30e32f7e03af4f78027f50f4a1c9 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 31 Aug 2015 10:32:26 +0000 Subject: [PATCH] C++11 support docs git-svn-id: svn://ultimatepp.org/upp/trunk@8881 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Callback.h | 151 +++++++++++++++++++++++- uppsrc/Core/Callback0.h | 140 ---------------------- uppsrc/Core/src.tpp/Callbacks$en-us.tpp | 33 ++++-- uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp | 7 +- 4 files changed, 179 insertions(+), 152 deletions(-) diff --git a/uppsrc/Core/Callback.h b/uppsrc/Core/Callback.h index 16a274af5..82d318e9c 100644 --- a/uppsrc/Core/Callback.h +++ b/uppsrc/Core/Callback.h @@ -54,9 +54,156 @@ public: CallbackArgTarget() { result = Null; } }; + +inline Callback Proxy(Callback& cb) +{ + return callback(&cb, &Callback::Execute); +} + +template +inline Callback1 Proxy(Callback1& cb) +{ + return callback(&cb, &Callback1::Execute); +} + +template +inline Callback2 Proxy(Callback2& cb) +{ + return callback(&cb, &Callback2::Execute); +} + +template +inline Callback3 Proxy(Callback3& cb) +{ + return callback(&cb, &Callback3::Execute); +} + +template +inline Callback4 Proxy(Callback4& cb) +{ + return callback(&cb, &Callback4::Execute); +} + +inline Gate Proxy(Gate& cb) +{ + return callback(&cb, &Gate::Execute); +} + +template +inline Gate1 Proxy(Gate1& cb) +{ + return callback(&cb, &Gate1::Execute); +} + +template +inline Gate2 Proxy(Gate2& cb) +{ + return callback(&cb, &Gate2::Execute); +} + +template +inline Gate3 Proxy(Gate3& cb) +{ + return callback(&cb, &Gate3::Execute); +} + +template +inline Gate4 Proxy(Gate4& cb) +{ + return callback(&cb, &Gate4::Execute); +} + + +Callback& operator<<(Callback& a, Callback b); + +template +Callback1& operator<<(Callback1& a, Callback1 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +template +Callback2& operator<<(Callback2& a, Callback2 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +template +Callback3& operator<<(Callback3& a, Callback3 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +template +Callback4& operator<<(Callback4& a, Callback4 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +Gate& operator<<(Gate& a, Gate b); + +template +Gate1& operator<<(Gate1& a, Gate1 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +template +Gate2& operator<<(Gate2& a, Gate2 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +template +Gate3& operator<<(Gate3& a, Gate3 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + +template +Gate4& operator<<(Gate4& a, Gate4 b) +{ + if(a) + a = callback(a, b); + else + a = b; + return a; +} + #ifdef CPP_11 -inline -Callback& operator<<(Callback& a, std::function fn) { return a << Callback(lambda(fn)); }; +template +Callback& operator<<(Callback& a, L b) +{ + return a << Callback(lambda(b)); +} template Callback1& operator<<(Callback1& a, L b) diff --git a/uppsrc/Core/Callback0.h b/uppsrc/Core/Callback0.h index 49bd86300..388a6d07e 100644 --- a/uppsrc/Core/Callback0.h +++ b/uppsrc/Core/Callback0.h @@ -57,13 +57,7 @@ struct CallbackForkAction : public CallbackAction { : cb1(cb1), cb2(cb2) {} }; -inline Callback Proxy(Callback& cb) -{ - return callback(&cb, &Callback::Execute); -} - Callback callback(Callback cb1, Callback cb2); -Callback& operator<<(Callback& a, Callback b); //0 args to Callback1 @@ -127,28 +121,12 @@ struct Callback1ForkAction : public Callback1Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Callback1 Proxy(Callback1& cb) -{ - return callback(&cb, &Callback1::Execute); -} - template Callback1 callback(Callback1 cb1, Callback1 cb2) { return Callback1(new Callback1ForkAction (cb1, cb2)); } -template -Callback1& operator<<(Callback1& a, Callback1 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - //0 args to Callback2 template @@ -211,28 +189,12 @@ struct Callback2ForkAction : public Callback2Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Callback2 Proxy(Callback2& cb) -{ - return callback(&cb, &Callback2::Execute); -} - template Callback2 callback(Callback2 cb1, Callback2 cb2) { return Callback2(new Callback2ForkAction (cb1, cb2)); } -template -Callback2& operator<<(Callback2& a, Callback2 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - //0 args to Callback3 template @@ -295,28 +257,12 @@ struct Callback3ForkAction : public Callback3Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Callback3 Proxy(Callback3& cb) -{ - return callback(&cb, &Callback3::Execute); -} - template Callback3 callback(Callback3 cb1, Callback3 cb2) { return Callback3(new Callback3ForkAction (cb1, cb2)); } -template -Callback3& operator<<(Callback3& a, Callback3 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - //0 args to Callback4 template @@ -379,28 +325,12 @@ struct Callback4ForkAction : public Callback4Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Callback4 Proxy(Callback4& cb) -{ - return callback(&cb, &Callback4::Execute); -} - template Callback4 callback(Callback4 cb1, Callback4 cb2) { return Callback4(new Callback4ForkAction (cb1, cb2)); } -template -Callback4& operator<<(Callback4& a, Callback4 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - // ----------------------------------------------------------- //0 args to Gate @@ -463,13 +393,7 @@ struct GateForkAction : public GateAction { : cb1(cb1), cb2(cb2) {} }; -inline Gate Proxy(Gate& cb) -{ - return callback(&cb, &Gate::Execute); -} - Gate callback(Gate cb1, Gate cb2); -Gate& operator<<(Gate& a, Gate b); //0 args to Gate1 @@ -533,28 +457,12 @@ struct Gate1ForkAction : public Gate1Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Gate1 Proxy(Gate1& cb) -{ - return callback(&cb, &Gate1::Execute); -} - template Gate1 callback(Gate1 cb1, Gate1 cb2) { return Gate1(new Gate1ForkAction (cb1, cb2)); } -template -Gate1& operator<<(Gate1& a, Gate1 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - //0 args to Gate2 template @@ -617,28 +525,12 @@ struct Gate2ForkAction : public Gate2Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Gate2 Proxy(Gate2& cb) -{ - return callback(&cb, &Gate2::Execute); -} - template Gate2 callback(Gate2 cb1, Gate2 cb2) { return Gate2(new Gate2ForkAction (cb1, cb2)); } -template -Gate2& operator<<(Gate2& a, Gate2 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - //0 args to Gate3 template @@ -701,28 +593,12 @@ struct Gate3ForkAction : public Gate3Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Gate3 Proxy(Gate3& cb) -{ - return callback(&cb, &Gate3::Execute); -} - template Gate3 callback(Gate3 cb1, Gate3 cb2) { return Gate3(new Gate3ForkAction (cb1, cb2)); } -template -Gate3& operator<<(Gate3& a, Gate3 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} - //0 args to Gate4 template @@ -785,24 +661,8 @@ struct Gate4ForkAction : public Gate4Action { : cb1(cb1), cb2(cb2) {} }; -template -inline Gate4 Proxy(Gate4& cb) -{ - return callback(&cb, &Gate4::Execute); -} - template Gate4 callback(Gate4 cb1, Gate4 cb2) { return Gate4(new Gate4ForkAction (cb1, cb2)); } - -template -Gate4& operator<<(Gate4& a, Gate4 b) -{ - if(a) - a = callback(a, b); - else - a = b; - return a; -} diff --git a/uppsrc/Core/src.tpp/Callbacks$en-us.tpp b/uppsrc/Core/src.tpp/Callbacks$en-us.tpp index 1e7694b0c..88faa301f 100644 --- a/uppsrc/Core/src.tpp/Callbacks$en-us.tpp +++ b/uppsrc/Core/src.tpp/Callbacks$en-us.tpp @@ -16,7 +16,7 @@ pointers. Each Callback represents some kind of action (usually calling a certain function or a certain object method) that can be invoked at any time.&] [s9; If you are happy enough to be able to use C`+`+11, you can also -assign C`+`+ lambda to Callback.&] +assign C`+`+ lambda to Callback using operator << (see bellow).&] [s9; There are several basic callback types, depending on number of parameters passed and return value. In order to keep description of callbacks short, all these types are described in a single @@ -86,19 +86,22 @@ Callback takes over its ownership.&] [s0;:Callback1`:`:Callback1`(`):%- [%%*/@(128.0.255) CallbackType]()&] [s2; Creates an empty callback.&] [s3; &] -[s4;%- &] -[s5;:Callback1`:`:operator`=`(function``):%- [_^Callback1^ Callback1][@(0.0.255) `& -]_[* operator`=](std`::function<[@(0.0.255) void]_([%%*/@(128.0.255) arguments])>_[*@3 lam -bda])&] -[s6;%- Only in C`+`+ 11&] -[s2; Assigns C`+`+11 lambda to callback.&] -[s3; &] [s4; &] [s0;:Callback1`:`:Callback1`(const Callback1`&`):%- [%%*/@(128.0.255) CallbackType](con st_[%%*/@(128.0.255) CallbackType]`&_[*@3 c])&] [s2; Copy constructor. &] [s7; [%-*C@3 c]-|Source callback.&] [s3; &] +[s4;%- &] +[s5;:Upp`:`:Callback`:`:Callback`(Upp`:`:AnyLambda``):%- [@(0.0.255) template]_<[@(0.0.255) c +lass]_[*@4 T]>_[%%*/@(128.0.255) CallbackType]([_^Upp`:`:AnyLambda^ AnyLambda]<[*@4 T]>_[*@3 l +])&] +[s2; Constructor from C`+`+11 lambda. Note that AnyLambda intermediate +type is necessarry as std`::function appears to have `"catch all`" +templated constructor, which creates overloading problems. Use +`'lambda`' helper function to convert lambda to AnyLambda (or +use operator<<).&] +[s3; &] [s4; &] [s0;:`:`:Callback1`:`:`~Callback1`(`):%- `~[%%*/@(128.0.255) CallbackType]()&] [s2; Destructor.&] @@ -168,7 +171,7 @@ returns true.&] [s0;%- &] [s0;%- &] [s0;%- &] -[ {{10000@(113.42.0) [s0; [*@7;4 Common functions creating callbacks]]}}&] +[ {{10000@(113.42.0) [s0; [*@7;4 Common Callback/Gate functions]]}}&] [s3; &] [s0;:`:`:callback`(OBJECT`*`,void`(METHOD`:`:`*`)`(P1 p1`)`): template_&] @@ -261,6 +264,14 @@ that calls both the first and the second callback.&] [s7; [%-*C@3 b]-|Second callback.&] [s7; [*/ Return value]-|Reference to the first callback.&] [s3; &] +[s4;%- &] +[s0;:operator`<`<`(Callback1``&`,Callback1``): `[ template_<[*/@(128.0.255) p +arameters]> `]&] +[s0;%- [%%*/@(128.0.255) CallbackType][%% <][%%*/@(128.0.255) arguments][%% >]`&_[* operator<<]( +[%%*/@(128.0.255) CallbackType][%% <][%%*/@(128.0.255) arguments][%% > +]`&_[*@3 a], [%%*/@(128.0.255) C`+`+11Lambda]_[*@3 b])&] +[s2; Variant of merging callbacks that can be used for C`+`+11 lambdas.&] +[s3; &] [s0; &] [ {{10000@(113.42.0) [s0; [*@7;4 Special functions creating callbacks]]}}&] [s3; &] @@ -544,4 +555,8 @@ output value.&] [s7; [%-*C@3 value]-|Value.&] [s7; [*/ Return value]-|Callback.&] [s3; &] +[s0;%- &] +[ {{10000@(113.42.0) [s0; [*@7;4 Proxy]]}}&] +[s0; &] +[s0; Callback proxy can be used to create ca&] [s0; ]] \ No newline at end of file diff --git a/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp b/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp index ca5cb04c4..f562cd725 100644 --- a/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp +++ b/uppsrc/CtrlCore/src.tpp/Ctrl$en-us.tpp @@ -2233,11 +2233,16 @@ can be assigned to several Ctrls in one statement.&] [s4;%- &] [s5;:Ctrl`:`:operator`<`<`(Callback`):%- [_^`:`:Callback^ Callback][@(0.0.255) `&]_[* opera tor<<]([_^`:`:Callback^ Callback]_[*@3 action])&] -[s2;b17;a17; Same as WhenAction << action;&] +[s5;:Upp`:`:Ctrl`:`:operator`<`<`(std`:`:function``):%- [_^Upp`:`:Callback^ C +allback][@(0.0.255) `&]_[* operator<<]([_^std`:`:function^ std`::function]<[@(0.0.255) voi +d]_()>_[*@3 action])&] +[s2;b17;a17; Same as WhenAction << action, second variant suitable +for C`+`+11 lambdas.&] [s7;i1120;a17; [%-*C@3 action]-|Callback that is to be added to callbacks that are invoked when user changes value of Ctrl.&] [s7;i1120;a17; [*/ Return value]-|Reference to WhenAction.&] [s3;%- &] +[s3; &] [s4;%- &] [s5;:Ctrl`:`:SetTimeCallback`(int`,Callback`,int`):%- [@(0.0.255) void]_[* SetTimeCallbac k]([@(0.0.255) int]_[*@3 delay`_ms], [_^`:`:Callback^ Callback]_[*@3 cb],