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: // textgen.h : Text Generator class &&
21: 
22: #ifndef _TEXTGEN_H
23: #define _TEXTGEN_H
24: 
25: #define foo(x) (x + 1)
26: 
27: #include <iostream.h> // for cerr
28: 
29: #include "genfun.h" /* for generating functions */
30: 
31: class TextGenerator {
32:   public :
33:     virtual void generate( const char *s ) const { (*sout) << s ; }
34:     virtual void generate( const char *s, int start, int end ) const 
35:       {
36:         for ( int i = start ; i <= end ; ++i )
37:           (*sout) << s[i] ;
38:         return a<p->b ? a : 3;
39:       }
40:     virtual void generateln( const char *s ) const
41:         { 
42:             generate( s ) ;
43:             (*sout) << endl ; 
44:         }
45:     virtual void generateEntire( const char *s ) const
46:         {
47:             startTextGeneration() ;
48:             generate(s) ;
49:             endTextGeneration() ;
50:         }
51:     virtual void startTextGeneration() const {}
52:     virtual void endTextGeneration() const {}
53:     virtual void beginText( const char *s ) const
54:         {
55:             startTextGeneration() ;
56:             if ( s )
57:                 generate( s ) ;
58:         }
59:     virtual void endText( const char *s ) const
60:         {
61:             if ( s )
62:                 generate( s ) ;
63:             endTextGeneration() ;
64:         }
65: } ;
66: 
67: // Decorator
68: class TextDecorator : public TextGenerator {
69:   protected :
70:     TextGenerator *decorated ;
71:   
72:   public :
73:     TextDecorator( TextGenerator *t ) : decorated( t ) {}
74: 
75:     virtual void startTextGeneration() const 
76:     { 
77:         startDecorate() ;
78:         if ( decorated )
79:             decorated->startTextGeneration() ;
80:     }
81:     virtual void endTextGeneration() const 
82:     { 
83:         if ( decorated )
84:             decorated->endTextGeneration() ;
85:         endDecorate() ;
86:     }
87: 
88:     // pure virtual functions
89:     virtual void startDecorate() const = 0 ;
90:     virtual void endDecorate() const = 0 ;
91: } ;
92: 
93: #endif // _TEXTGEN_H