guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gcond.hpp
1 //
2 // Conditional expressions: Callbacks and conditional Props and Active Expressions.
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 #ifndef GuitCond_hpp
8 #define GuitCond_hpp
9 #include <gprop.hpp>
10 #include <gptr.hpp>
11 namespace guit {
12 
134 class GCond : public GProp {
135 public:
136  GCond(GTrigger& t) : trigger_(t) {}
137  ~GCond();
138 
139  bool isEquivalent(const GProp&) const override {return false;}
140 
141  static GPropType& Type();
142  GPropType& type() const override {return Type();}
143 
146  GCond* clone(bool copy_value) const override {return nullptr;}
147  GCond* toCond() override {return this;}
148  GString stringValue() const override;
149  GTrigger& trigger() const {return trigger_;}
150  void activate(GEvent&, bool state);
151  virtual void activate2(GEvent&, bool state) {};
152  void fire(GEvent&) override {}
153  void addNext(GCond*);
154  GCond* next() {return next_;}
155  bool onAdd(Gadget*) override;
156  void onRemove(Gadget*) override;
157 
158  GTrigger& trigger_;
159  gptr<GCond> next_;
160  bool isnext_{};
162 };
163 
164 
166 class GGuard : public GCond {
167 public:
170  GGuard& operator[](GExprBool const& expr);
171 
174  GGuard(GTrigger& t, GBoolExpr* guard);
175  GString stringValue() const override {return "<Guard>";}
176  void activate2(GEvent&, bool state) override;
177  void fire(GEvent&) override;
178  gptr<GBoolExpr> guard_;
180 };
181 
183 GGuard& Guard(GExprBool const& expr);
184 
185 
187 class GOtherwise : public GGuard {
188 public:
191  GOtherwise& operator[](GExprBool const& expr);
192 
195  GOtherwise(GTrigger& t, GBoolExpr* guard);
196  GString stringValue() const override {return "<Otherwise>";}
197  void activate2(GEvent&, bool state) override;
198  void fire(GEvent&) override;
200 };
201 
204 GOtherwise& Otherwise();
205 GOtherwise& Otherwise(GExprBool const& expr);
207 
208 
211 GCond& operator/(GTrigger& trigger, GFunction const& fun);
212 GCond& operator/(GTrigger& trigger, GEventFunction const& fun);
213 GCond& operator/(GTrigger& trigger, GCaller&);
214 
215 GCond& operator/(GBoolExpr& expr, GFunction const& fun);
216 GCond& operator/(GBoolExpr& expr, GEventFunction const& fun);
217 GCond& operator/(GBoolExpr& expr, GCaller&);
218 
219 GCond& operator/(GCond&, GFunction const& fun);
220 GCond& operator/(GCond&, GEventFunction const& fun);
221 GCond& operator/(GCond&, GCaller& fun);
223 
226 GCond& operator/(GTrigger& trigger, GString const& str);
227 GCond& operator/(GTrigger& trigger, GProp& prop);
228 GCond& operator/(GTrigger& trigger, GProp* prop);
229 GCond& operator/(GTrigger& trigger, Gadget&);
230 GCond& operator/(GTrigger& trigger, Gadget*);
231 
232 GCond& operator/(GBoolExpr& expr, GString const& str);
233 GCond& operator/(GBoolExpr& expr, GProp& prop);
234 GCond& operator/(GBoolExpr& expr, GProp* prop);
235 GCond& operator/(GBoolExpr& expr, Gadget&);
236 GCond& operator/(GBoolExpr& expr, Gadget*);
237 
238 GCond& operator/(GCond&, GString const& str);
239 GCond& operator/(GCond&, GProp& prop);
240 GCond& operator/(GCond&, GProp* prop);
242 
243 
245 class GCondCall : public GCond {
246 public:
247  GCondCall(GTrigger&, GCaller&);
248  ~GCondCall();
249  GString stringValue() const override;
250 
253  void activate2(GEvent&, bool state) override;
254  void fire(GEvent&) override;
255  void threadCB();
256  GCaller& caller_;
258 };
259 
260 
262 class GCondProp : public GCond {
263 public:
264  GCondProp(GTrigger&, GProp&);
265  GCondProp(GTrigger&, Gadget&);
266  GCondProp(GTrigger&, GString const&);
267  bool isCondProp() const override {return true;}
268  GProp* prop();
269  GString stringValue() const override;
270 
273  void fire(GEvent&) override;
274  void activate2(GEvent&, bool state) override;
275  bool isEquivalent(const GProp& other) const override;
276  bool onAdd(Gadget*) override;
277  void apply(Gadget*, GRender&, Specif) override;
278  bool active_;
279  gptr<GObject> child_;
281 };
282 
283 
284 }
285 #endif