30.06.2013 Aufrufe

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

6 #<strong>in</strong>clude ” simple event handler . h”<br />

7<br />

10.2 Das DDD 295<br />

8 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

9 /∗ This c l a s s reads the user <strong>in</strong>put from s t d i n and passes i t on<br />

10 ∗ to the r e g i s t e r e d handler word by word <strong>in</strong> the form o f<br />

11 ∗ WordEvent i n s t a n c e s .<br />

12 ∗/<br />

13<br />

14 class SimpleInputHandl<strong>in</strong>g<br />

15 {<br />

16 protected :<br />

17<br />

18 /∗ The maximum length of accepted <strong>in</strong>put words . I f an <strong>in</strong>put word<br />

19 ∗ i s longer i t w i l l be s p l i t up i n t o two <strong>in</strong>put words .<br />

20 ∗/<br />

21 static const u<strong>in</strong>t32 MAXWORDLENGTH = 256;<br />

22<br />

23 private :<br />

24<br />

25 /∗ This i s a pure s t a t i c method c o l l e c t i o n . Therefore f o r b i d<br />

26 ∗ c o nstruct<strong>in</strong>g an <strong>in</strong>stance .<br />

27 ∗/<br />

28 SimpleInputHandl<strong>in</strong>g ( ) { } ;<br />

29<br />

30 /∗ I f construction i s not p o s s i b l e , a l s o d e s t r u c t i o n does<br />

31 ∗ not make any sense at a l l .<br />

32 ∗/<br />

33 virtual ˜ SimpleInputHandl<strong>in</strong>g ( ) { } ;<br />

34<br />

35 protected :<br />

36<br />

37 /∗ This v a r i a b l e i s used i n t e r n a l l y to stop the dispatcher<br />

38 ∗ loop . I f i t i s s e t the loop w i l l stop a f t e r the next<br />

39 ∗ word that has been obta<strong>in</strong>ed from the user <strong>in</strong>put .<br />

40 ∗/<br />

41 static bool s t o p d i s p a t c h e r l o o p ;<br />

42<br />

43 /∗ This i s the event handler that obta<strong>in</strong>s the n o t i f i c a t i o n s<br />

44 ∗ about the user <strong>in</strong>put words .<br />

45 ∗/<br />

46 static EventHandler ∗ event handler ;<br />

47<br />

48 public :<br />

49<br />

50 /∗ This method i s used to s e t the r e s p o n s i b l e event handler .<br />

51 ∗ I f there i s already a handler s e t , the new one w i l l r e p l a c e<br />

52 ∗ the old one . Please note that the old event handler w i l l<br />

53 ∗ NOT be deleted !<br />

54 ∗ @param handler The event handler that i s r e s p o n s i b l e f o r<br />

55 ∗ events from now on .<br />

56 ∗/<br />

57 static void setEventHandler ( EventHandler ∗ handler )<br />

58 {<br />

59 event handler = handler ;<br />

60 }<br />

61<br />

62 /∗ This method i s c a l l e d to s t a r t the dispatcher loop . I t w i l l<br />

63 ∗ NOT return u n t i l the loop i s stopped because multithread<strong>in</strong>g<br />

64 ∗ i s not implemented here . To stop the loop the method<br />

65 ∗ stopDispatcher has to be c a l l e d . Then t h i s method w i l l return<br />

66 ∗ a f t e r the next word that has been dispatched .<br />

67 ∗ I f no handler i s s e t t h i s method w i l l return immediately ( j u s t<br />

68 ∗ because exceptions are not known yet ) .<br />

69 ∗/<br />

70 static void runDispatcher ( ) ;<br />

71

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!