guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gbind.hpp
1 //
2 // Prop binding
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef Guit_Bind_hpp
9 #define Guit_Bind_hpp
10 #include <gvarprop.hpp>
11 #include <gnotifier.hpp>
12 #include <gwrapper.hpp>
13 namespace guit {
14 
18 inline void gunbind(GVarProp& prop1, GVarProp& prop2) {prop1.unbind(prop2);}
19 
25 inline void gunbind(GVarProp& prop, GVarProp::BindTag tag = 0) {prop.unbind(tag);}
27 
28 
51 template <class R, class RM = typename R::IsVarProp, class S, class SM = typename S::IsVarProp>
52 inline R& gbind(R& prop1, S& prop2, GVarProp::BindTag tag = 0) {
53  prop1.bindImpl(prop2, *new GChangePropNotifier<S,R>(prop2,prop1), tag, false);
54  return prop1;
55 }
56 
57 template <class R, class RM = typename R::IsVarProp, class S, class SM = typename S::IsVarProp>
58 inline R& operator<<=(R& prop1, S& prop2) {return gbind(prop1, prop2);}
59 
60 template <class R, class RM = typename R::IsVarProp, class S>
61 inline R& operator<<=(R& prop1, GPropRef_<S> prop2) {return gbind(prop1, (S&)prop2.prop_);}
63 
64 
76 template <class R, class S, class F, class MATCH = typename R::IsVarProp>
77 inline R& gbind(R& prop, GPropField<S,F> const& field) {
78  using RVal = typename R::ValueType;
79  prop.bindImpl(field.prop_,
80  *new GChangeFieldNotifier<S,F,R,RVal>(field, GPropField<R,RVal>(prop,prop.value_)),
81  0, false);
82  return prop;
83 }
84 
85 template <class R, class F, class S>
86 inline R& gbind(GPropField<R,F> const& field, GVarProp_<S>& prop) {
87  field.prop_.bindImpl(prop, *new GChangeFieldNotifier<GVarProp_<S>,S,R,F>
88  (GPropField<GVarProp_<S>,F>(prop,prop.value_), field), 0, false);
89  return field.prop_;
90 }
91 
92 template <class R, class S, class F, class MATCH = typename R::IsVarProp>
93 inline R& operator<<=(R& prop, GPropField<S,F> const& field) {return gbind(prop,field);}
94 
95 template <class R, class F, class S>
96 inline R& operator<<=(GPropField<R,F> const& field, GVarProp_<S>& prop) {return gbind(field,prop);}
98 
99 
110 template <class R, class RF, class S, class SF>
111 inline R& gbind(GPropField<R,RF> const& field1, GPropField<S,SF> const& field2) {
112  field1.prop_.bindImpl(field2.prop_,
113  *new GChangeFieldNotifier<S,SF,R,RF>(field2,field1),
114  0, false);
115  return field1.prop_;
116 }
117 
118 template <class R, class RF, class S, class SF>
119 inline R& operator<<=(GPropField<R,RF> const& field1, GPropField<S,SF> const& field2) {
120  return gbind(field1, field2);
121 }
123 
124 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
125 
140 template <class R, class RM = typename R::IsVarProp,
141 class S, class SM = typename S::IsVarProp>
142 inline R& gsync(R& prop1, S& prop2, GVarProp::BindTag tag = 0) {
143  prop1.bindImpl(prop2, *new GChangePropNotifier<S,R>(prop2,prop1), tag, false);
144  prop2.bindImpl(prop1, *new GChangePropNotifier<R,S>(prop1,prop2), tag, true);
145  return prop1;
146 }
147 template <class R, class RM = typename R::IsVarProp,
148 class S, class SM = typename S::IsVarProp>
149 inline R& operator^=(R& prop1, S& prop2) {return gsync(prop1, prop2);}
151 
152 
163 template <class R, class S, class F, class MATCH = typename R::IsVarProp>
164 inline R& gsync(R& prop, GPropField<S,F> const& field) {
165  using RVal = typename R::ValueType;
166  gbind<R,S,F>(prop, field);
167  field.prop_.bindImpl(prop, *new GChangeFieldNotifier<R,RVal,S,F>
168  (GPropField<R,RVal>(prop,prop.value_), field), 0, false);
169  return prop;
170 }
171 
172 template <class R, class F, class S>
173 inline R& gsync(GPropField<R,F> const& field, GVarProp_<S>& prop) {
174  gbind(field, prop);
175  prop.bindImpl(field.prop_, *new GChangeFieldNotifier<R,F,GVarProp_<S>,S>
176  (field, GPropField<GVarProp_<S>,S>(prop,prop.value_)), 0, false);
177  return field.prop_;
178 }
179 
180 template <class R, class S, class F, class MATCH = typename R::IsVarProp>
181 inline R& operator^=(R& prop, GPropField<S,F> const& field) {
182  return gsync<R,S,F>(prop, field);
183 }
184 
185 template <class R, class F, class S>
186 inline R& operator^=(GPropField<R,F> const& field, GVarProp_<S>& prop) {
187  return gsync<R,F,S>(field,prop);
188 }
190 
191 
202 template <class R, class RF, class S, class SF>
203 inline R& gsync(GPropField<R,RF> const& field1, GPropField<S,SF> const& field2) {
204  gbind(field1, field2);
205  gbind(field2, field1);
206  return field1.prop_;
207 }
208 
209 template <class R, class RF, class S, class SF>
210 inline R& operator^=(GPropField<R,RF> const& field1, GPropField<S,SF> const& field2) {
211  return gsync(field1, field2);
212 }
214 
215 }
216 #endif