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.

292 10. Memory – e<strong>in</strong> kle<strong>in</strong>es Beispiel<br />

66<br />

67 /∗ Writes the number to the context . This method can only work<br />

68 ∗ with a text context .<br />

69 ∗ @param context The output context to write to .<br />

70 ∗/<br />

71 virtual void writeDisplayRep ( OutputContext &context )<br />

72 {<br />

73 dynamic cast(context ) . write ( t e x t ) ;<br />

74 }<br />

75<br />

76 } ;<br />

77<br />

78 #endif // s i m p l e t e x t d i s p l a y a b l e h<br />

10.2.18 Event<br />

Da die Entscheidung beim Reagieren auf den User-Input zugunsten e<strong>in</strong>es<br />

sauberen Event Modells gefallen ist, brauchen wir e<strong>in</strong>mal e<strong>in</strong>e Basisklasse<br />

Event. Diese benötigt eigentlich ke<strong>in</strong>e besondere, tiefergehende Erklärung:<br />

1 // simple event . h − simple c l a s s f o r events<br />

2<br />

3 #ifndef s i m p l e e v e n t h<br />

4 #def<strong>in</strong>e s i m p l e e v e n t h<br />

5<br />

6 #<strong>in</strong>clude ” u s e r t y p e s . h”<br />

7<br />

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

9 /∗ A very simple base c l a s s f o r events . All events have to be<br />

10 ∗ derived from i t and f o r each event type a correspond<strong>in</strong>g<br />

11 ∗ constant has to be placed here . This base does noth<strong>in</strong>g but<br />

12 ∗ s t o r e the type of the event so that i t can be asked f o r i t .<br />

13 ∗ All f u n c t i o n a l i t y f o r s p e c i a l events has to be implemented<br />

14 ∗ <strong>in</strong> the appropriate derived c l a s s e s .<br />

15 ∗/<br />

16<br />

17 class Event<br />

18 {<br />

19 protected :<br />

20<br />

21 /∗ The type of the event . Must be one o f the constants below<br />

22 ∗/<br />

23 <strong>in</strong>t32 event type ;<br />

24<br />

25 public :<br />

26<br />

27 /∗ Constants f o r p o s s i b l e event types . I f a new type i s<br />

28 ∗ <strong>in</strong>troduced an accord<strong>in</strong>g constant has to be placed here .<br />

29 ∗/<br />

30 static const <strong>in</strong>t32 WORDEVENT = 0x1 ;<br />

31<br />

32 /∗ Standard constructor<br />

33 ∗ Has to s t o r e the type i n t e r n a l l y . No checks f o r v a l i d types<br />

34 ∗ are performed because events are u s u a l l y generated extremely<br />

35 ∗ often and t h e r e f o r e performance i s an i s s u e .<br />

36 ∗ @param event type The type of the event . Has to be one o f<br />

37 ∗ the constants above<br />

38 ∗/<br />

39 explicit Event ( <strong>in</strong>t event type )<br />

40 {<br />

41 event type = event type ;

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!