01: /**
02: ** Copyright (C) 1999-2007 Lorenzo Bettini
03: ** 
04: http://www.lorenzobettini.it
05: 
06:  r2 = r2 XOR (1<<10);
07:  cout << "hello world" << endl;
08: ** 
09: */
10: 
11: // this file also contains the definition of mysum as a #define
12: 
13: // textgenerator.h : Text Generator class &&
14: 
15: #ifndef _TEXTGEN_H
16: #define _TEXTGEN_H
17: 
18: #define foo(x) (x + 1)
19: 
20: #define mysum myfunbody 
21: 
22: #include <iostream.h> // for cerr
23: 
24: #include "genfun.h" /* for generating functions */
25: 
26: class TextGenerator {
27: public :
28: virtual void generate( const char *s ) const { (*sout) << s ; }
29: virtual void generate( const char *s, int start, int end ) const 
30: {
31: for ( int i = start ; i <= end ; ++i )
32: (*sout) << s[i] ;
33: return a<p->b ? a : 3;
34: }
35: virtual void generateln( const char *s ) const
36: { 
37: generate( s ) ;
38: (*sout) << endl ; 
39: }
40: virtual void generateEntire( const char *s ) const
41: {
42: startTextGeneration() ;
43: generate(s) ;
44: endTextGeneration() ;
45: }
46: virtual void startTextGeneration() const {}
47: virtual void endTextGeneration() const {}
48: virtual void beginText( const char *s ) const
49: {
50: startTextGeneration() ;
51: if ( s )
52: generate( s ) ;
53: }
54: virtual void endText( const char *s ) const
55: {
56: if ( s )
57: generate( s ) ;
58: endTextGeneration() ;
59: }
60: } ;
61: 
62: // Decorator
63: class TextDecorator : public TextGenerator {
64: protected :
65: TextGenerator *decorated ;
66: 
67: public :
68: TextDecorator( TextGenerator *t ) : decorated( t ) {}
69: 
70: virtual void startTextGeneration() const 
71: { 
72: startDecorate() ;
73: if ( decorated )
74: decorated->startTextGeneration() ;
75: }
76: virtual void endTextGeneration() const 
77: { 
78: if ( decorated )
79: decorated->endTextGeneration() ;
80: endDecorate() ;
81: mysum;
82: }
83: 
84: // pure virtual functions
85: virtual void startDecorate() const = 0 ;
86: virtual void endDecorate() const = 0 ;
87: } ;
88: 
89: #endif // _TEXTGEN_H
90: 

AltStyle によって変換されたページ (->オリジナル) /