aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gensigs.bld53
-rw-r--r--src/tests/signal.cpp44
2 files changed, 55 insertions, 42 deletions
diff --git a/gensigs.bld b/gensigs.bld
index c452356..6cdd5d5 100644
--- a/gensigs.bld
+++ b/gensigs.bld
@@ -18,6 +18,7 @@ function genSigs( outName )
18 "\n" 18 "\n"
19 "#include \"bu/util.h\"\n" 19 "#include \"bu/util.h\"\n"
20 "#include \"bu/exceptionbase.h\"\n" 20 "#include \"bu/exceptionbase.h\"\n"
21 "#include \"bu/list.h\"\n"
21 "\n" 22 "\n"
22 "namespace Bu\n" 23 "namespace Bu\n"
23 "{\n" 24 "{\n"
@@ -28,9 +29,11 @@ function genSigs( outName )
28 for i in range( 0, 10 ) do 29 for i in range( 0, 10 ) do
29 { 30 {
30 templParams = "typename ret"; 31 templParams = "typename ret";
32 templSpecParams = "";
31 funcParams = ""; 33 funcParams = "";
32 funcAnonParams = ""; 34 funcAnonParams = "";
33 templCallParams = "ret"; 35 templCallParams = "ret";
36 templSpecCallParams = "";
34 funcCallParams = ""; 37 funcCallParams = "";
35 if i >= 1 then 38 if i >= 1 then
36 { 39 {
@@ -41,11 +44,14 @@ function genSigs( outName )
41 funcCallParams << ", "; 44 funcCallParams << ", ";
42 funcParams << ", "; 45 funcParams << ", ";
43 funcAnonParams << ", "; 46 funcAnonParams << ", ";
47 templSpecParams << ", ";
44 } 48 }
45 templParams << ", typename p${p}t"; 49 templParams << ", typename p${p}t";
50 templSpecParams << "typename p${p}t";
46 funcParams << "p${p}t p${p}"; 51 funcParams << "p${p}t p${p}";
47 funcAnonParams << "p${p}t"; 52 funcAnonParams << "p${p}t";
48 templCallParams << ", p${p}t"; 53 templCallParams << ", p${p}t";
54 templSpecCallParams << ", p${p}t";
49 funcCallParams << "p${p}"; 55 funcCallParams << "p${p}";
50 } 56 }
51 } 57 }
@@ -156,6 +162,53 @@ function genSigs( outName )
156 " new __Slot${i}F<${templCallParams}>( pFnc )\n" 162 " new __Slot${i}F<${templCallParams}>( pFnc )\n"
157 " );\n" 163 " );\n"
158 " }\n" 164 " }\n"
165 " \n"
166 " template<${templParams}>\n"
167 " class SignalList${i} : public Bu::List<Bu::Signal${i}<${templCallParams}> >\n"
168 " {\n"
169 " typedef Bu::List<Bu::Signal${i}<${templCallParams}> > MyType;\n"
170 " public:\n"
171 " SignalList${i}()\n"
172 " {\n"
173 " }\n"
174 " \n"
175 " using MyType::iterator;\n"
176 " using MyType::const_iterator;\n"
177 " \n"
178 " ret operator()( ${funcParams} )\n"
179 " {\n"
180 " typename MyType::iterator i, n;\n"
181 " for(i = MyType::begin(); i; i=n)\n"
182 " {\n"
183 " n = i;\n"
184 " n++;\n"
185 " if( n )\n"
186 " (*i)( ${funcCallParams} );\n"
187 " else\n"
188 " return (*i)( ${funcCallParams} );\n"
189 " }\n"
190 " throw Bu::ExceptionBase(\"Empty SignalList with non-void return value called.\");\n"
191 " }\n"
192 " };\n"
193 " \n"
194 " template<${templSpecParams}>\n"
195 " class SignalList${i}<void${templSpecCallParams}> : public Bu::List<Bu::Signal${i}<void${templSpecCallParams}> >\n"
196 " {\n"
197 " typedef Bu::List<Bu::Signal${i}<void${templSpecCallParams}> > MyType;\n"
198 " public:\n"
199 " SignalList${i}()\n"
200 " {\n"
201 " }\n"
202 " \n"
203 " using MyType::iterator;\n"
204 " using MyType::const_iterator;\n"
205 " \n"
206 " void operator()( ${funcParams} )\n"
207 " {\n"
208 " for( typename MyType::iterator i = MyType::begin(); i; i++ )\n"
209 " (*i)( ${funcCallParams} );\n"
210 " }\n"
211 " };\n"
159 "#endif // BU_SIGNAL_PARAM_COUNT_${i}\n" 212 "#endif // BU_SIGNAL_PARAM_COUNT_${i}\n"
160 "\n" 213 "\n"
161 ); 214 );
diff --git a/src/tests/signal.cpp b/src/tests/signal.cpp
index 8920461..93519fa 100644
--- a/src/tests/signal.cpp
+++ b/src/tests/signal.cpp
@@ -17,56 +17,16 @@ void PrintFancy( const Bu::String &s )
17 17
18int Square( int a ) 18int Square( int a )
19{ 19{
20 println("Square called");
20 return a*a; 21 return a*a;
21} 22}
22 23
23int Double( int a ) 24int Double( int a )
24{ 25{
26 println("Double called");
25 return a+a; 27 return a+a;
26} 28}
27 29
28template<typename R, typename P>
29class SignalList1 : public Bu::List<Bu::Signal1<R,P> >
30{
31 typedef Bu::List<Bu::Signal1<R,P> > MyType;
32public:
33 SignalList1()
34 {
35 }
36
37 using MyType::iterator;
38 using MyType::const_iterator;
39
40 R operator()( P p1 )
41 {
42 println("===Non-void um...non-specialization===");
43 R tmp;
44 for( typename MyType::iterator i = MyType::begin(); i; i++ )
45 tmp = (*i)( p1 );
46 return tmp;
47 }
48};
49
50template<typename P>
51class SignalList1<void, P> : public Bu::List<Bu::Signal1<void,P> >
52{
53 typedef Bu::List<Bu::Signal1<void,P> > MyType;
54public:
55 SignalList1()
56 {
57 }
58
59 using MyType::iterator;
60 using MyType::const_iterator;
61
62 void operator()( P p1 )
63 {
64 println("===Void specialization===");
65 for( typename MyType::iterator i = MyType::begin(); i; i++ )
66 (*i)( p1 );
67 }
68};
69
70int main() 30int main()
71{ 31{
72 SignalList1<void,const Bu::String &> lPrints; 32 SignalList1<void,const Bu::String &> lPrints;