Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / HardCopy / HardCopyFP.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: HardCopyFP.h /main/3 1996/06/11 17:04:22 cde-hal $ */
24
25 #ifndef _fp_h
26 #define _fp_h 1
27
28 #include <iostream.h>
29 #include "FPExceptions.h"
30 #include "StyleSheet/Feature.h"
31 #include "StyleSheet/FeatureValue.h"
32 #include "StyleSheet/Element.h"
33 #include "StyleSheet/Const.h"
34 #include "StyleSheet/Debug.h"
35
36 enum BLOCK_MODE { NON_BLOCK, BLOCK };
37 extern enum BLOCK_MODE g_block_mode;
38
39 class featureProcessor : public Destructable
40 {
41
42 protected:
43    const char* f_name;
44
45    virtual const char* stringToCharPtr(const FeatureValue*) = 0;
46    virtual unsigned int  dimensionToFloat(float& Y, 
47                         FeatureValueDimension::Unit& UnitOfY,
48                         const FeatureValue*,
49                         FeatureValueDimension::Unit) = 0;
50    virtual const char* dimensionToCharPtr(const FeatureValue*,
51                        FeatureValueDimension::Unit) = 0;
52
53 // turn to Hard Copy engine specific literal
54    virtual const char* convertToLiteral(const char* str) = 0;
55
56 public:
57    featureProcessor(featureProcessor& x): f_name(x.f_name) {};
58    featureProcessor(const char* name): f_name(name) {};
59    virtual ~featureProcessor() {};
60
61    virtual featureProcessor* clone() = 0;
62
63    virtual void handleBegElement(const Element &element, const FeatureSet&, const FeatureSet&, const FeatureSet&, const FeatureSet& initialFeatureSet, ostream&) = 0;
64    virtual void handleEndElement(ostream&) = 0;
65    virtual void handleData(const char *data, unsigned int size, ostream&)=0;
66
67    const char* name() { return f_name; };
68
69 // evaluate the variable (in x.y.z form) to a feature value.
70    virtual FeatureValue* evaluate(const char* variableName) = 0;
71    virtual unsigned int accept(const char* nm, const Expression*) = 0;
72
73    virtual void preEvaluate(const Element&) = 0;
74    virtual void postEvaluate(const Element&) = 0;
75
76    virtual void clear() = 0;
77
78 ////////////////////////////////////////
79 // functions for getting feature values.
80 //
81 // Sample usage:
82 //   int x;
83 //   if ( getFeatureValue(x, FeatureSet.deep_lookup(FONT, FONT_SIZE)) ) {
84 //     //use x here
85 //   }
86 ////////////////////////////////////////
87
88 //
89 // default value (NONE) means using whatever unit is available
90 // Otherwise, a conversion is performed
91 //
92    unsigned int    getDimensionValue(float& y, 
93                    const Feature*, 
94                    FeatureValueDimension::Unit = FeatureValueDimension::NONE);
95
96    const char     *getDimensionValue(const Feature*, 
97                    FeatureValueDimension::Unit = FeatureValueDimension::NONE);
98
99    const char     *getFeatureValue(const Feature*);
100    unsigned int    getFeatureValue(int&, const Feature*);
101    unsigned int    getFeatureValue(float&, const Feature*);
102    FeatureValueArray* getFeatureValueArray(const Feature*);
103
104    const FeatureSet *getFeatureSetValue(const Feature*);
105 };
106
107 typedef featureProcessor* featureProcessorPtr;
108
109 class loutFeatureProcessor : public featureProcessor
110 {
111 protected:
112    unsigned int f_change;
113
114 protected:
115    char* empty_string();
116    char* prepend(const char*, const char*);
117
118 // turn to Hard Copy engine specific literal
119    const char* convertToLiteral(const char* str);
120    
121 public:
122    loutFeatureProcessor(loutFeatureProcessor& x) : 
123     f_change(x.f_change), featureProcessor(x) {};
124
125    loutFeatureProcessor(const char* name) : 
126      featureProcessor(name), f_change(false) {};
127    ~loutFeatureProcessor() {};
128
129    virtual void handleEndElement(ostream& out) {
130       if ( f_change == true )
131          out << "}";
132    };
133    virtual void handleData(const char *data, unsigned int size, ostream&);
134
135    const char* stringToCharPtr(const FeatureValue*);
136    unsigned int dimensionToFloat(float&, 
137                 FeatureValueDimension::Unit& unitOfY,
138                 const FeatureValue*,
139                 FeatureValueDimension::Unit);
140    const char* dimensionToCharPtr(const FeatureValue*,
141                 FeatureValueDimension::Unit);
142
143    virtual FeatureValue* evaluate(const char* variableName) ;
144    virtual unsigned int accept(const char* nm, const Expression*) ;
145
146    virtual void preEvaluate(const Element&) ;
147    virtual void postEvaluate(const Element&) ;
148
149    virtual void clear() ;
150 };
151
152 #endif