30.06.2013 Aufrufe

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

1 // s i m p l e t e x t d i s p l a y a b l e . h − a d i s p l a y a b l e f o r text<br />

2<br />

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

4 #def<strong>in</strong>e s i m p l e t e x t d i s p l a y a b l e h<br />

5<br />

6 #<strong>in</strong>clude < c s t r i n g><br />

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

8 #<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 />

9<br />

10.2 Das DDD 291<br />

10 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

11 /∗ A simple d i s p l a y a b l e f o r text<br />

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

13 ∗ appropriate s t r i n g . When the c a l l b a c k to<br />

14 ∗ obta<strong>in</strong> the d i s p l a y r e p r e s e n t a t i o n i s c a l l e d t h i s s t r i n g i s written .<br />

15 ∗ The s t r i n g may be any s t a t i c a l l y or dynamically a l l o c a t e d char ∗ ,<br />

16 ∗ because i t i s copied .<br />

17 ∗/<br />

18 class TextDisplayable : public Displayable<br />

19 {<br />

20 protected :<br />

21<br />

22 /∗ The s t r i n g s t o r i n g the text to be displayed . I t i s a copy o f the<br />

23 ∗ s t r i n g that i s passed on as a parameter o f the constructor .<br />

24 ∗ Therefore i t has to be deleted <strong>in</strong> the d e s t r u c t o r .<br />

25 ∗/<br />

26 char ∗ t e x t ;<br />

27<br />

28 private :<br />

29<br />

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

31 ∗/<br />

32 TextDisplayable ( const TextDisplayable & s r c ) {}<br />

33<br />

34 public :<br />

35<br />

36 /∗ Standard constructor<br />

37 ∗ I t has to c a l l the constructor f o r the base c l a s s .<br />

38 ∗ The text passed on i s copied to the t e x t member . I f a 0 po<strong>in</strong>ter<br />

39 ∗ i s given as a parameter t e x t i s i n i t i a l i z e d to an empty<br />

40 ∗ s t r i n g ( j u s t because exceptions are not known yet ) .<br />

41 ∗/<br />

42 explicit TextDisplayable ( const char ∗ text ) :<br />

43 Displayable ( ) , t e x t (0)<br />

44 {<br />

45 i f ( text )<br />

46 {<br />

47 t e x t = new char [ s t r l e n ( text ) + 1 ] ;<br />

48 strcpy ( t e x t , text ) ;<br />

49 }<br />

50 }<br />

51<br />

52 /∗ Destructor<br />

53 ∗ Just to meet the convention<br />

54 ∗/<br />

55 virtual ˜ TextDisplayable ( )<br />

56 {<br />

57 delete t e x t ;<br />

58 }<br />

59<br />

60 /∗ 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 />

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

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

63 ∗/<br />

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

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

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!