aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/optparser.cpp39
-rw-r--r--src/optparser.h51
-rw-r--r--src/signals.h592
-rw-r--r--src/tests/optparser.cpp27
-rw-r--r--src/tests/signals.cpp87
-rw-r--r--src/tests/socket.cpp66
6 files changed, 862 insertions, 0 deletions
diff --git a/src/optparser.cpp b/src/optparser.cpp
new file mode 100644
index 0000000..2046792
--- /dev/null
+++ b/src/optparser.cpp
@@ -0,0 +1,39 @@
1#include "bu/optparser.h"
2
3Bu::OptParser::OptParser()
4{
5}
6
7Bu::OptParser::~OptParser()
8{
9}
10
11void Bu::OptParser::addOption( const Option &opt )
12{
13 lOption.append( opt );
14 if( opt.cOpt != '\0' )
15 hsOption.insert( opt.cOpt, &lOption.last() );
16 if( opt.sOpt )
17 hlOption.insert( opt.sOpt, &lOption.last() );
18
19}
20
21Bu::FString Bu::OptParser::format( const Bu::FString &sIn, int iWidth,
22 int iIndent )
23{
24
25}
26
27
28//
29// Code for Bu::OptParser::Option
30//
31
32Bu::OptParser::Option::Option()
33{
34}
35
36Bu::OptParser::Option::~Option()
37{
38}
39
diff --git a/src/optparser.h b/src/optparser.h
new file mode 100644
index 0000000..39f048d
--- /dev/null
+++ b/src/optparser.h
@@ -0,0 +1,51 @@
1#ifndef BU_OPT_PARSER_H
2#define BU_OPT_PARSER_H
3
4#include "bu/fstring.h"
5#include "bu/list.h"
6#include "bu/hash.h"
7
8namespace Bu
9{
10 class OptParser
11 {
12 public:
13 class Option
14 {
15 public:
16 Option();
17 virtual ~Option();
18
19 char cOpt;
20 Bu::FString sOpt;
21 Bu::FString sDesc;
22 };
23
24 public:
25 OptParser();
26 virtual ~OptParser();
27
28 void parse( int argc, char *argv[] );
29
30 void addOption( const Option &opt );
31
32 template<typename c>
33 void callback( c *pObj, int (c::*fnc)( int, char *[] ) )
34 {
35 (pObj->*fnc)( 0, NULL );
36 }
37
38 private:
39 Bu::FString format( const Bu::FString &sIn, int iWidth, int iIndent );
40
41 typedef Bu::List<Option> OptionList;
42 typedef Bu::Hash<char, Option *> ShortOptionHash;
43 typedef Bu::Hash<Bu::FString, Option *> LongOptionHash;
44
45 OptionList lOption;
46 ShortOptionHash hsOption;
47 LongOptionHash hlOption;
48 };
49};
50
51#endif
diff --git a/src/signals.h b/src/signals.h
new file mode 100644
index 0000000..722f928
--- /dev/null
+++ b/src/signals.h
@@ -0,0 +1,592 @@
1#ifndef BU_OBJECT_SIGNALS_H
2#define BU_OBJECT_SIGNALS_H
3
4#include "bu/util.h"
5
6namespace Bu
7{
8 //
9 // 0 Parameters
10 //
11
12 template<typename ret>
13 class _Slot0
14 {
15 public:
16 _Slot0() { }
17 virtual ~_Slot0() { }
18
19 virtual ret operator()()=0;
20
21 virtual _Slot0<ret> *clone() const=0;
22 };
23
24 template<typename cls, typename ret>
25 class __Slot0 : public _Slot0<ret>
26 {
27 public:
28 __Slot0( cls *pCls, ret (cls::*pFnc)() ) :
29 pCls( pCls ), pFnc( pFnc ) { }
30 virtual ~__Slot0() { }
31
32 virtual ret operator()()
33 {
34 return (pCls->*pFnc)();
35 }
36
37 virtual _Slot0<ret> *clone() const
38 {
39 return new __Slot0<cls, ret>( pCls, pFnc );
40 }
41
42 private:
43 cls *pCls;
44 ret (cls::*pFnc)();
45 };
46
47 template<typename ret>
48 class __Slot0F : public _Slot0<ret>
49 {
50 public:
51 __Slot0F( ret (*pFnc)() ) :
52 pFnc( pFnc ) { }
53 virtual ~__Slot0F() { }
54
55 virtual ret operator()()
56 {
57 return (*pFnc)();
58 }
59
60 virtual _Slot0<ret> *clone() const
61 {
62 return new __Slot0F<ret>( pFnc );
63 }
64
65 private:
66 ret (*pFnc)();
67 };
68
69 template<typename ret>
70 class Signal0
71 {
72 public:
73 Signal0() : pCb( NULL ) { }
74 Signal0( _Slot0<ret> *pCb ) : pCb( pCb ) { }
75 Signal0( const Signal0<ret> &rSrc ) :
76 pCb( rSrc.pCb->clone() ) { }
77
78 virtual ~Signal0() { delete pCb; pCb = NULL; }
79
80 ret operator()()
81 {
82 return (*pCb)();
83 }
84
85 private:
86 _Slot0<ret> *pCb;
87 };
88
89 template<typename cls, typename ret>
90 Signal0<ret> slot( cls *pCls, ret (cls::*pFnc)() )
91 {
92 return Signal0<ret>(
93 new __Slot0<cls, ret>( pCls, pFnc )
94 );
95 }
96
97 template<typename ret>
98 Signal0<ret> slot( ret (*pFnc)() )
99 {
100 return Signal0<ret>(
101 new __Slot0F<ret>( pFnc )
102 );
103 }
104
105 //
106 // 1 Parameter
107 //
108
109 template<typename ret, typename p1t>
110 class _Slot1
111 {
112 public:
113 _Slot1() { }
114 virtual ~_Slot1() { }
115
116 virtual ret operator()( p1t p1 )=0;
117
118 virtual _Slot1<ret, p1t> *clone() const=0;
119 };
120
121 template<typename cls, typename ret, typename p1t>
122 class __Slot1 : public _Slot1<ret, p1t>
123 {
124 public:
125 __Slot1( cls *pCls, ret (cls::*pFnc)( p1t ) ) :
126 pCls( pCls ), pFnc( pFnc ) { }
127 virtual ~__Slot1() { }
128
129 virtual ret operator()( p1t p1 )
130 {
131 return (pCls->*pFnc)( p1 );
132 }
133
134 virtual _Slot1<ret, p1t> *clone() const
135 {
136 return new __Slot1<cls, ret, p1t>( pCls, pFnc );
137 }
138
139 private:
140 cls *pCls;
141 ret (cls::*pFnc)( p1t );
142 };
143
144 template<typename ret, typename p1t>
145 class __Slot1F : public _Slot1<ret, p1t>
146 {
147 public:
148 __Slot1F( ret (*pFnc)( p1t ) ) :
149 pFnc( pFnc ) { }
150 virtual ~__Slot1F() { }
151
152 virtual ret operator()( p1t p1 )
153 {
154 return (*pFnc)( p1 );
155 }
156
157 virtual _Slot1<ret, p1t> *clone() const
158 {
159 return new __Slot1F<ret, p1t>( pFnc );
160 }
161
162 private:
163 ret (*pFnc)( p1t p1 );
164 };
165
166 template<typename ret, typename p1t>
167 class Signal1
168 {
169 public:
170 Signal1() : pCb( NULL ) { }
171 Signal1( _Slot1<ret, p1t> *pCb ) : pCb( pCb ) { }
172 Signal1( const Signal1<ret, p1t> &rSrc ) :
173 pCb( rSrc.pCb->clone() ) { }
174
175 virtual ~Signal1() { delete pCb; pCb = NULL; }
176
177 ret operator()( p1t p1 )
178 {
179 return (*pCb)( p1 );
180 }
181
182 private:
183 _Slot1<ret, p1t> *pCb;
184 };
185
186 template<typename cls, typename ret, typename p1t>
187 Signal1<ret, p1t> slot( cls *pCls, ret (cls::*pFnc)( p1t ) )
188 {
189 return Signal1<ret, p1t>(
190 new __Slot1<cls, ret, p1t>( pCls, pFnc )
191 );
192 }
193
194 template<typename ret, typename p1t>
195 Signal1<ret, p1t> slot( ret (*pFnc)( p1t ) )
196 {
197 return Signal1<ret, p1t>(
198 new __Slot1F<ret, p1t>( pFnc )
199 );
200 }
201
202 //
203 // 2 Parameters
204 //
205
206 template<typename ret, typename p1t, typename p2t>
207 class _Slot2
208 {
209 public:
210 _Slot2() { }
211 virtual ~_Slot2() { }
212
213 virtual ret operator()( p1t p1, p2t p2 )=0;
214
215 virtual _Slot2<ret, p1t, p2t> *clone() const=0;
216 };
217
218 template<typename cls, typename ret, typename p1t, typename p2t>
219 class __Slot2 : public _Slot2<ret, p1t, p2t>
220 {
221 public:
222 __Slot2( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) ) :
223 pCls( pCls ), pFnc( pFnc ) { }
224 virtual ~__Slot2() { }
225
226 virtual ret operator()( p1t p1, p2t p2 )
227 {
228 return (pCls->*pFnc)( p1, p2 );
229 }
230
231 virtual _Slot2<ret, p1t, p2t> *clone() const
232 {
233 return new __Slot2<cls, ret, p1t, p2t>( pCls, pFnc );
234 }
235
236 private:
237 cls *pCls;
238 ret (cls::*pFnc)( p1t, p2t );
239 };
240
241 template<typename ret, typename p1t, typename p2t>
242 class __Slot2F : public _Slot2<ret, p1t, p2t>
243 {
244 public:
245 __Slot2F( ret (*pFnc)( p1t, p2t ) ) :
246 pFnc( pFnc ) { }
247 virtual ~__Slot2F() { }
248
249 virtual ret operator()( p1t p1, p2t p2 )
250 {
251 return (*pFnc)( p1, p2 );
252 }
253
254 virtual _Slot2<ret, p1t, p2t> *clone() const
255 {
256 return new __Slot2F<ret, p1t, p2t>( pFnc );
257 }
258
259 private:
260 ret (*pFnc)( p1t, p2t );
261 };
262
263 template<typename ret, typename p1t, typename p2t>
264 class Signal2
265 {
266 public:
267 Signal2() : pCb( NULL ) { }
268 Signal2( _Slot2<ret, p1t, p2t> *pCb ) : pCb( pCb ) { }
269 Signal2( const Signal2<ret, p1t, p2t> &rSrc ) :
270 pCb( rSrc.pCb->clone() ) { }
271
272 virtual ~Signal2() { delete pCb; pCb = NULL; }
273
274 ret operator()( p1t p1, p2t p2 )
275 {
276 return (*pCb)( p1, p2 );
277 }
278
279 private:
280 _Slot2<ret, p1t, p2t> *pCb;
281 };
282
283 template<typename cls, typename ret, typename p1t, typename p2t>
284 Signal2<ret, p1t, p2t> slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t ) )
285 {
286 return Signal2<ret, p1t, p2t>(
287 new __Slot2<cls, ret, p1t, p2t>( pCls, pFnc )
288 );
289 }
290
291 template<typename ret, typename p1t, typename p2t>
292 Signal2<ret, p1t, p2t> slot( ret (*pFnc)( p1t, p2t ) )
293 {
294 return Signal2<ret, p1t, p2t>(
295 new __Slot2F<ret, p1t, p2t>( pFnc )
296 );
297 }
298
299 //
300 // 3 Parameters
301 //
302
303 template<typename ret, typename p1t, typename p2t, typename p3t>
304 class _Slot3
305 {
306 public:
307 _Slot3() { }
308 virtual ~_Slot3() { }
309
310 virtual ret operator()( p1t p1, p2t p2, p3t p3 )=0;
311
312 virtual _Slot3<ret, p1t, p2t, p3t> *clone() const=0;
313 };
314
315 template<typename cls, typename ret, typename p1t, typename p2t, typename p3t>
316 class __Slot3 : public _Slot3<ret, p1t, p2t, p3t>
317 {
318 public:
319 __Slot3( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) ) :
320 pCls( pCls ), pFnc( pFnc ) { }
321 virtual ~__Slot3() { }
322
323 virtual ret operator()( p1t p1, p2t p2, p3t p3 )
324 {
325 return (pCls->*pFnc)( p1, p2, p3 );
326 }
327
328 virtual _Slot3<ret, p1t, p2t, p3t> *clone() const
329 {
330 return new __Slot3<cls, ret, p1t, p2t, p3t>( pCls, pFnc );
331 }
332
333 private:
334 cls *pCls;
335 ret (cls::*pFnc)( p1t, p2t, p3t );
336 };
337
338 template<typename ret, typename p1t, typename p2t, typename p3t>
339 class __Slot3F : public _Slot3<ret, p1t, p2t, p3t>
340 {
341 public:
342 __Slot3F( ret (*pFnc)( p1t, p2t, p3t ) ) :
343 pFnc( pFnc ) { }
344 virtual ~__Slot3F() { }
345
346 virtual ret operator()( p1t p1, p2t p2, p3t p3 )
347 {
348 return (*pFnc)( p1, p2, p3 );
349 }
350
351 virtual _Slot3<ret, p1t, p2t, p3t> *clone() const
352 {
353 return new __Slot3F<ret, p1t, p2t, p3t>( pFnc );
354 }
355
356 private:
357 ret (*pFnc)( p1t, p2t, p3t );
358 };
359
360 template<typename ret, typename p1t, typename p2t, typename p3t>
361 class Signal3
362 {
363 public:
364 Signal3() : pCb( NULL ) { }
365 Signal3( _Slot3<ret, p1t, p2t, p3t> *pCb ) : pCb( pCb ) { }
366 Signal3( const Signal3<ret, p1t, p2t, p3t> &rSrc ) :
367 pCb( rSrc.pCb->clone() ) { }
368
369 virtual ~Signal3() { delete pCb; pCb = NULL; }
370
371 ret operator()( p1t p1, p2t p2, p3t p3 )
372 {
373 return (*pCb)( p1, p2, p3 );
374 }
375
376 private:
377 _Slot3<ret, p1t, p2t, p3t> *pCb;
378 };
379
380 template<typename cls, typename ret, typename p1t, typename p2t, typename p3t>
381 Signal3<ret, p1t, p2t, p3t> slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t ) )
382 {
383 return Signal3<ret, p1t, p2t, p3t>(
384 new __Slot3<cls, ret, p1t, p2t, p3t>( pCls, pFnc )
385 );
386 }
387
388 template<typename ret, typename p1t, typename p2t, typename p3t>
389 Signal3<ret, p1t, p2t, p3t> slot( ret (*pFnc)( p1t, p2t, p3t ) )
390 {
391 return Signal3<ret, p1t, p2t, p3t>(
392 new __Slot3F<ret, p1t, p2t, p3t>( pFnc )
393 );
394 }
395
396 //
397 // 4 Parameters
398 //
399
400 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t>
401 class _Slot4
402 {
403 public:
404 _Slot4() { }
405 virtual ~_Slot4() { }
406
407 virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )=0;
408
409 virtual _Slot4<ret, p1t, p2t, p3t, p4t> *clone() const=0;
410 };
411
412 template<typename cls, typename ret, typename p1t, typename p2t, typename p3t, typename p4t>
413 class __Slot4 : public _Slot4<ret, p1t, p2t, p3t, p4t>
414 {
415 public:
416 __Slot4( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) ) :
417 pCls( pCls ), pFnc( pFnc ) { }
418 virtual ~__Slot4() { }
419
420 virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )
421 {
422 return (pCls->*pFnc)( p1, p2, p3, p4 );
423 }
424
425 virtual _Slot4<ret, p1t, p2t, p3t, p4t> *clone() const
426 {
427 return new __Slot4<cls, ret, p1t, p2t, p3t, p4t>( pCls, pFnc );
428 }
429
430 private:
431 cls *pCls;
432 ret (cls::*pFnc)( p1t, p2t, p3t, p4t );
433 };
434
435 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t>
436 class __Slot4F : public _Slot4<ret, p1t, p2t, p3t, p4t>
437 {
438 public:
439 __Slot4F( ret (*pFnc)( p1t, p2t, p3t, p4t ) ) :
440 pFnc( pFnc ) { }
441 virtual ~__Slot4F() { }
442
443 virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )
444 {
445 return (*pFnc)( p1, p2, p3, p4 );
446 }
447
448 virtual _Slot4<ret, p1t, p2t, p3t, p4t> *clone() const
449 {
450 return new __Slot4F<ret, p1t, p2t, p3t, p4t>( pFnc );
451 }
452
453 private:
454 ret (*pFnc)( p1t, p2t, p3t, p4t );
455 };
456
457 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t>
458 class Signal4
459 {
460 public:
461 Signal4() : pCb( NULL ) { }
462 Signal4( _Slot4<ret, p1t, p2t, p3t, p4t> *pCb ) : pCb( pCb ) { }
463 Signal4( const Signal4<ret, p1t, p2t, p3t, p4t> &rSrc ) :
464 pCb( rSrc.pCb->clone() ) { }
465
466 virtual ~Signal4() { delete pCb; pCb = NULL; }
467
468 ret operator()( p1t p1, p2t p2, p3t p3, p4t p4 )
469 {
470 return (*pCb)( p1, p2, p3, p4 );
471 }
472
473 private:
474 _Slot4<ret, p1t, p2t, p3t, p4t> *pCb;
475 };
476
477 template<typename cls, typename ret, typename p1t, typename p2t, typename p3t, typename p4t>
478 Signal4<ret, p1t, p2t, p3t, p4t> slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t ) )
479 {
480 return Signal4<ret, p1t, p2t, p3t, p4t>(
481 new __Slot4<cls, ret, p1t, p2t, p3t, p4t>( pCls, pFnc )
482 );
483 }
484
485 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t>
486 Signal4<ret, p1t, p2t, p3t, p4t> slot( ret (*pFnc)( p1t, p2t, p3t, p4t ) )
487 {
488 return Signal4<ret, p1t, p2t, p3t, p4t>(
489 new __Slot4F<ret, p1t, p2t, p3t, p4t>( pFnc )
490 );
491 }
492
493 //
494 // 5 Parameters
495 //
496
497 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t, typename p5t>
498 class _Slot5
499 {
500 public:
501 _Slot5() { }
502 virtual ~_Slot5() { }
503
504 virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )=0;
505
506 virtual _Slot5<ret, p1t, p2t, p3t, p4t, p5t> *clone() const=0;
507 };
508
509 template<typename cls, typename ret, typename p1t, typename p2t, typename p3t, typename p4t, typename p5t>
510 class __Slot5 : public _Slot5<ret, p1t, p2t, p3t, p4t, p5t>
511 {
512 public:
513 __Slot5( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) :
514 pCls( pCls ), pFnc( pFnc ) { }
515 virtual ~__Slot5() { }
516
517 virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )
518 {
519 return (pCls->*pFnc)( p1, p2, p3, p4, p5 );
520 }
521
522 virtual _Slot5<ret, p1t, p2t, p3t, p4t, p5t> *clone() const
523 {
524 return new __Slot5<cls, ret, p1t, p2t, p3t, p4t, p5t>( pCls, pFnc );
525 }
526
527 private:
528 cls *pCls;
529 ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t );
530 };
531
532 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t, typename p5t>
533 class __Slot5F : public _Slot5<ret, p1t, p2t, p3t, p4t, p5t>
534 {
535 public:
536 __Slot5F( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) ) :
537 pFnc( pFnc ) { }
538 virtual ~__Slot5F() { }
539
540 virtual ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )
541 {
542 return (*pFnc)( p1, p2, p3, p4, p5 );
543 }
544
545 virtual _Slot5<ret, p1t, p2t, p3t, p4t, p5t> *clone() const
546 {
547 return new __Slot5F<ret, p1t, p2t, p3t, p4t, p5t>( pFnc );
548 }
549
550 private:
551 ret (*pFnc)( p1t, p2t, p3t, p4t, p5t );
552 };
553
554 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t, typename p5t>
555 class Signal5
556 {
557 public:
558 Signal5() : pCb( NULL ) { }
559 Signal5( _Slot5<ret, p1t, p2t, p3t, p4t, p5t> *pCb ) : pCb( pCb ) { }
560 Signal5( const Signal5<ret, p1t, p2t, p3t, p4t, p5t> &rSrc ) :
561 pCb( rSrc.pCb->clone() ) { }
562
563 virtual ~Signal5() { delete pCb; pCb = NULL; }
564
565 ret operator()( p1t p1, p2t p2, p3t p3, p4t p4, p5t p5 )
566 {
567 return (*pCb)( p1, p2, p3, p4, p5 );
568 }
569
570 private:
571 _Slot5<ret, p1t, p2t, p3t, p4t, p5t> *pCb;
572 };
573
574 template<typename cls, typename ret, typename p1t, typename p2t, typename p3t, typename p4t, typename p5t>
575 Signal5<ret, p1t, p2t, p3t, p4t, p5t> slot( cls *pCls, ret (cls::*pFnc)( p1t, p2t, p3t, p4t, p5t ) )
576 {
577 return Signal5<ret, p1t, p2t, p3t, p4t, p5t>(
578 new __Slot5<cls, ret, p1t, p2t, p3t, p4t, p5t>( pCls, pFnc )
579 );
580 }
581
582 template<typename ret, typename p1t, typename p2t, typename p3t, typename p4t, typename p5t>
583 Signal5<ret, p1t, p2t, p3t, p4t, p5t> slot( ret (*pFnc)( p1t, p2t, p3t, p4t, p5t ) )
584 {
585 return Signal5<ret, p1t, p2t, p3t, p4t, p5t>(
586 new __Slot5F<ret, p1t, p2t, p3t, p4t, p5t>( pFnc )
587 );
588 }
589
590};
591
592#endif
diff --git a/src/tests/optparser.cpp b/src/tests/optparser.cpp
new file mode 100644
index 0000000..9168af8
--- /dev/null
+++ b/src/tests/optparser.cpp
@@ -0,0 +1,27 @@
1#include <bu/optparser.h>
2#include <bu/sio.h>
3using namespace Bu;
4
5class Opts : public Bu::OptParser
6{
7public:
8 Opts() :
9 iBob( 542 )
10 {
11 callback( this, &Opts::cb );
12 }
13
14 int cb( int argc, char *argv[] )
15 {
16 sio << "Hey, cb was called, here's a class var: " << iBob << sio.nl;
17 return 5;
18 }
19
20 int iBob;
21};
22
23int main( int argc, char *argv[] )
24{
25 Opts o;
26}
27
diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp
new file mode 100644
index 0000000..b4b1363
--- /dev/null
+++ b/src/tests/signals.cpp
@@ -0,0 +1,87 @@
1#include <bu/signals.h>
2#include <bu/sio.h>
3
4using namespace Bu;
5
6class Thing
7{
8public:
9 Thing() :
10 iState( 82731 )
11 {
12 }
13
14 virtual ~Thing()
15 {
16 }
17
18 void fnc0()
19 {
20 sio << iState << ": void fnc0()" << sio.nl;
21 }
22
23 void fnc1( int a )
24 {
25 sio << iState << ": void fnc1( " << a << " )" << sio.nl;
26 }
27
28 void fnc2( int a, Bu::FString b )
29 {
30 sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl;
31 }
32
33 void fnc3( int a, Bu::FString b, double c )
34 {
35 sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl;
36 }
37
38 void fnc4( int a, Bu::FString b, double c, char d )
39 {
40 sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl;
41 }
42
43 void fnc5( int a, Bu::FString b, double c, char d, long e )
44 {
45 sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl;
46 }
47
48private:
49 int iState;
50};
51
52void pfnc0()
53{
54 sio << "This doesn't have state, it's pfnc0()!" << sio.nl;
55}
56
57void callit( Signal0<void> sig )
58{
59 sig();
60}
61
62int main()
63{
64 Thing t;
65
66 Signal0<void> cb0( slot( &t, &Thing::fnc0 ) );
67 cb0();
68
69 Signal1<void, int> cb1( slot( &t, &Thing::fnc1 ) );
70 cb1( 5 );
71
72 Signal2<void, int, Bu::FString> cb2( slot( &t, &Thing::fnc2 ) );
73 cb2( 5, "Hi there" );
74
75 Signal3<void, int, Bu::FString, double> cb3( slot( &t, &Thing::fnc3 ) );
76 cb3( 5, "Hi there", 12.85 );
77
78 Signal4<void, int, Bu::FString, double, char> cb4( slot( &t, &Thing::fnc4 ) );
79 cb4( 5, "Hi there", 12.85, 'z' );
80
81 Signal5<void, int, Bu::FString, double, char, long> cb5( slot( &t, &Thing::fnc5 ) );
82 cb5( 5, "Hi there", 12.85, 'z', 849 );
83
84// Signal1<int, int> cb1( slot( &t, &Thing::fnc1 ) );
85// sio << "Result: " << cb1( 5 ) << sio.nl;
86}
87
diff --git a/src/tests/socket.cpp b/src/tests/socket.cpp
new file mode 100644
index 0000000..1cf63e4
--- /dev/null
+++ b/src/tests/socket.cpp
@@ -0,0 +1,66 @@
1#include <bu/socket.h>
2#include <bu/sio.h>
3
4#include <sys/time.h>
5#include <time.h>
6
7using namespace Bu;
8
9bool isUp()
10{
11 try
12 {
13 Socket s("xagasoft.com", 9898, 1 );
14
15 char buf[5];
16 buf[s.read(buf, 2, 1, 0)] = '\0';
17
18 if( !strcmp( buf, "hi" ) )
19 return true;
20 else
21 return false;
22 }
23 catch(...)
24 {
25 return false;
26 }
27}
28
29int main()
30{
31 uint32_t uUp = 0;
32 uint32_t uDown = 0;
33 uint32_t uTotal = 0;
34 struct timeval tv;
35
36 for(;;)
37 {
38 gettimeofday( &tv, NULL );
39 time_t goal = ((tv.tv_sec/5)+1)*5;
40 tv.tv_sec = goal-tv.tv_sec;
41 tv.tv_usec = 0-tv.tv_usec;
42 if( tv.tv_usec < 0 )
43 {
44 tv.tv_sec--;
45 tv.tv_usec = 1000000+tv.tv_usec;
46 }
47 select( 0, NULL, NULL, NULL, &tv );
48 gettimeofday( &tv, NULL );
49 if( isUp() )
50 {
51 uUp++;
52 sio << "status: up ";
53 }
54 else
55 {
56 uDown++;
57 sio << "status: down ";
58 }
59 uTotal++;
60
61 sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for "
62 << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl
63 << sio.flush;
64 }
65}
66