01: /*
02: ** Copyright (C) 1999, 2000, 2001 Lorenzo Bettini
03: **  
04: ** This program is free software; you can redistribute it and/or modify
05: ** it under the terms of the GNU General Public License as published by
06: ** the Free Software Foundation; either version 2 of the License, or
07: ** (at your option) any later version.
08: **  
09: ** This program is distributed in the hope that it will be useful,
10: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12: ** GNU General Public License for more details.
13: **  
14: ** You should have received a copy of the GNU General Public License
15: ** along with this program; if not, write to the Free Software
16: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: **  
18: */
19: 
20: // this file also contains the definition of mysum as a #define
21: 
22: // textgenerator.h : Text Generator class &&
23: 
24: #ifndef _TEXTGEN_H
25: #define _TEXTGEN_H
26: 
27: #define foo(x) (x + 1)
28: 
29: #define mysum myfunbody 
30: 
31: #include <iostream.h> // for cerr
32: 
33: #include "genfun.h" /* for generating functions */
34: 
35: class TextGenerator {
36:   public :
37:     virtual void generate( const char *s ) const { (*sout) << s ; }
38:     virtual void generate( const char *s, int start, int end ) const 
39:       {
40:         for ( int i = start ; i <= end ; ++i )
41:           (*sout) << s[i] ;
42:         return a<p->b ? a : 3;
43:       }
44:     virtual void generateln( const char *s ) const
45:         { 
46:             generate( s ) ;
47:             (*sout) << endl ; 
48:         }
49:     virtual void generateEntire( const char *s ) const
50:         {
51:             startTextGeneration() ;
52:             generate(s) ;
53:             endTextGeneration() ;
54:         }
55:     virtual void startTextGeneration() const {}
56:     virtual void endTextGeneration() const {}
57:     virtual void beginText( const char *s ) const
58:         {
59:             startTextGeneration() ;
60:             if ( s )
61:                 generate( s ) ;
62:         }
63:     virtual void endText( const char *s ) const
64:         {
65:             if ( s )
66:                 generate( s ) ;
67:             endTextGeneration() ;
68:         }
69: } ;
70: 
71: // Decorator
72: class TextDecorator : public TextGenerator {
73:   protected :
74:     TextGenerator *decorated ;
75:   
76:   public :
77:     TextDecorator( TextGenerator *t ) : decorated( t ) {}
78: 
79:     virtual void startTextGeneration() const 
80:     { 
81:         startDecorate() ;
82:         if ( decorated )
83:             decorated->startTextGeneration() ;
84:     }
85:     virtual void endTextGeneration() const 
86:     { 
87:         if ( decorated )
88:             decorated->endTextGeneration() ;
89:         endDecorate() ;
90:         mysum;
91:     }
92: 
93:     // pure virtual functions
94:     virtual void startDecorate() const = 0 ;
95:     virtual void endDecorate() const = 0 ;
96: } ;
97: 
98: #endif // _TEXTGEN_H