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.

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

5<br />

6 #<strong>in</strong>clude ” s i m p l e d i s p l a y a b l e . h”<br />

7 #<strong>in</strong>clude ” s i m p l e t e x t o u t p u t c o n t e x t . h”<br />

8<br />

9 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

10 /∗ A simple d i s p l a y a b l e f o r signed i n t e g e r s o f 6 4 Bits maximum length .<br />

11 ∗ I t implements the Displayable i n t e r f a c e and i s constructed with an<br />

12 ∗ appropriate number . When the c a l l b a c k to generate output i s c a l l e d ,<br />

13 ∗ the i n t e g e r i s written .<br />

14 ∗/<br />

15 class IntDisplayable : public Displayable<br />

16 {<br />

17 protected :<br />

18<br />

19 /∗ The i n t e g e r that s h a l l be displayed as passed on <strong>in</strong> the constructor .<br />

20 ∗/<br />

21 <strong>in</strong>t64 num ;<br />

22<br />

23 private :<br />

24<br />

25 /∗ Copy construction i s forbidden<br />

26 ∗/<br />

27 IntDisplayable ( const IntDisplayable & s r c ) {}<br />

28<br />

29 public :<br />

30<br />

31 /∗ Standard constructor<br />

32 ∗ I t has to c a l l the constructor f o r the base c l a s s and s t o r e the<br />

33 ∗ given i n t e g e r<br />

34 ∗/<br />

35 explicit IntDisplayable ( <strong>in</strong>t64 num ) :<br />

36 Displayable ( ) , num (num) {}<br />

37<br />

38 /∗ Destructor<br />

39 ∗ Just to meet the convention<br />

40 ∗/<br />

41 virtual ˜ IntDisplayable ( ) { }<br />

42<br />

43 /∗ Noth<strong>in</strong>g s p e c i a l has to be done upon r e g i s t r a t i o n<br />

44 ∗ @param handler The handler that t h i s d i s p l a y a b l e was<br />

45 ∗ r e g i s t e r e d with .<br />

46 ∗/<br />

47 virtual void d i s p l a y a b l e R e g i s t e r e d (<br />

48 SimpleOutputHandl<strong>in</strong>g &handler ) {}<br />

49<br />

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

51 ∗ with a text context .<br />

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

53 ∗/<br />

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

55 {<br />

56 dynamic cast(context ) . write (num ) ;<br />

57 }<br />

58<br />

59 } ;<br />

60<br />

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

10.2.17 TextDisplayable<br />

Analog zur Darstellung von Ganzzahlen mittels e<strong>in</strong>es besonderen Displayables<br />

gibt es auch e<strong>in</strong>e entsprechende Klasse TextDisplayable, die sich für<br />

Str<strong>in</strong>gs verantwortlich fühlt:

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!