guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
gadd.hpp
1 //
2 // Adding operators.
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_Add_hpp
9 #define Guit_Add_hpp
10 #include <gadget.hpp>
11 namespace guit {
12 
14 class GItemSpec {
15 public:
16  GItemSpec(const char* spec) : spec_(spec) {}
17  GItemSpec(const GString& spec) : spec_(spec) {}
18  GString spec_;
19  mutable std::vector<gptr<GProp>> props_;
20 };
21 
23 class GadgetHolder : public GProp {
24 public:
25  GadgetHolder(Gadget& g) : gadget_(g) {}
26  static GPropType& Type();
27  GPropType& type() const override {return Type();}
28  gptr<Gadget> gadget_;
29 };
30 
58 GItemSpec const& operator<<(GItemSpec const& item, GString const& str);
59 GItemSpec const& operator<<(GItemSpec const& item, GProp& prop);
60 GItemSpec const& operator<<(GItemSpec const& item, gptr<GProp> prop);
61 
62 GItemSpec const& operator<<(GItemSpec const& item, GFunction const& fun);
63 GItemSpec const& operator<<(GItemSpec const& item, GEventFunction const& fun);
64 
65 GItemSpec const& operator<<(GItemSpec const& item, GMenu& menu);
66 GItemSpec const& operator<<(GItemSpec const& item, gptr<GMenu> menu);
67 
68 GItemSpec const& operator<<(GItemSpec const& item, GWindow& win);
69 GItemSpec const& operator<<(GItemSpec const& item, gptr<GWindow> win);
70 
71 template <class T, class = typename T::IsGadget>
72 inline T& operator<<(T& gadget, const char* str) {
73  if (str) gadget.add(str);
74  return gadget;
75 }
76 
77 template <class T, class = typename T::IsGadget>
78 inline T& operator<<(T& gadget, GString const& str) {
79  gadget.add(str);
80  return gadget;
81 }
82 
83 template <class T, class = typename T::IsGadget>
84 inline T& operator<<(T& gadget, GStrings const& str) {
85  gadget.add(str);
86  return gadget;
87 }
88 
89 template <class T, class = typename T::IsGadget>
90 inline T& operator<<(T& gadget, GItemSpec const& item) {
91  gadget.addItem(item);
92  return gadget;
93 }
94 
95 template <class T, class Child, class = typename T::IsGadget, class = typename Child::IsGadgetChild>
96 inline T& operator<<(T& gadget, Child& child) {
97  gadget.add(child);
98  return gadget;
99 }
100 
101 template <class T, class Child, class = typename T::IsGadget, class = typename Child::IsGadgetChild>
102 inline T& operator<<(T& gadget, Child* child) {
103  gadget.add(child);
104  return gadget;
105 }
106 
107 template <class T, class Child, class = typename T::IsGadget>
108 inline T& operator<<(T& gadget, gptr<Child> child) {
109  gadget.add(child.get());
110  return gadget;
111 }
112 
113 template <class T, class = typename T::IsGadgetOrVarProp>
114 inline T& operator<<(T& parent, GFunction const& fun) {
115  parent.addFun(fun);
116  return parent;
117 }
118 
119 template <class T, class = typename T::IsGadgetOrVarProp>
120 inline T& operator<<(T& parent, GEventFunction const& fun) {
121  parent.addFun(fun);
122  return parent;
123 }
124 
125 template <class T, class = typename T::IsGadgetOrVarProp>
126 inline T& operator<<(T& parent, GCaller& fun) {
127  parent.addFun(fun);
128  return parent;
129 }
130 
131 template <class T, class Child, class = typename T::IsGadget>
132 inline T& operator<<(T& gadget, Child&(creator)(GString const&)) {
133  gadget.add((creator)(""));
134  return gadget;
135 }
136 
137 template <class T, class = typename T::IsGadget>
138 inline T& operator<<(T& (creator)(GString const&), GString const& str) {
139  return (creator)("") << str;
140 }
141 
142 template <class T, class = typename T::IsGadget>
143 inline T& operator<<(T& (creator)(GString const&), GItemSpec const& item) {
144  return (creator)("") << item;
145 }
146 
147 template <class T, class Child, class = typename T::IsGadget, class = typename Child::IsGadgetChild>
148 inline T& operator<<(T& (creator)(GString const&), Child& child) {
149  return (creator)("") << child;
150 }
151 
152 template <class T, class Child, class = typename T::IsGadget>
153 inline T& operator<<(T& (creator)(GString const&), gptr<Child> child) {
154  return (creator)("") << child;
155 }
156 
157 template <class T, class = typename T::IsGadget>
158 inline T& operator<<(T& (creator)(GString const&), GFunction const& fun) {
159  return (creator)("") << fun;
160 }
161 
162 template <class T, class = typename T::IsGadget>
163 inline T& operator<<(T& (creator)(GString const&), GEventFunction const& fun) {
164  return (creator)("") << fun;
165 }
167 
168 }
169 #endif