Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / Expression.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: Expression.h /main/4 1996/08/21 15:50:17 drk $ */
24 #ifndef _Expression_h
25 #define _Expression_h
26
27 /* **************************************************************
28    Defines the tree for evaluating expressions given as feature values
29    in the Style Sheet
30  * ************************************************************** */
31
32
33
34 #include "SymTab.h"
35
36 #ifndef CDE_NEXT
37
38 typedef dlist_array<Symbol> f_items_t;
39 #else
40 #include "dti_cc/cc_povec.h"
41 typedef dlist_array<Symbol> f_items_t;
42 #endif
43
44
45 class FeatureValue;
46 class TermNode;
47
48 // /////////////////////////////////////////////////////////////////////////
49 //      class Expression
50 //
51 //      holds root of expression tree 
52 // /////////////////////////////////////////////////////////////////////////
53
54
55 class Expression
56 {
57 public:
58   Expression(TermNode *root);
59   Expression(const Expression&);
60   virtual ~Expression();
61
62   virtual FeatureValue *evaluate() const;
63   ostream &print(ostream &) const; 
64
65 private:
66   TermNode* f_root;
67 };
68
69 class TermNode
70 {
71 public:
72   virtual ~TermNode();
73   virtual FeatureValue *evaluate() const = 0;
74   virtual ostream &print(ostream &) const = 0;
75   virtual TermNode *clone() const = 0;
76 };
77
78 class VariableNode: public TermNode
79 {
80   // for single name variables eg: "DEFAULT_FONT" 
81 public:
82   VariableNode(const Symbol& name);
83
84   virtual FeatureValue *evaluate() const;
85   ostream &print(ostream &) const;
86
87   virtual TermNode *clone() const;
88
89 private:
90   Symbol f_name;
91
92 };
93
94 class CompositeVariableNode : public TermNode
95 {
96   // for feature path variables (font.size)
97   // eg: font: { size: font.size }
98 public:
99   CompositeVariableNode();
100   CompositeVariableNode(size_t capac); /* if we know how many items to expect */
101   ~CompositeVariableNode();
102
103   virtual FeatureValue *evaluate() const ;
104   ostream &print(ostream &) const;
105
106   virtual TermNode *clone() const;
107
108   void prependItem(const Symbol& item);
109   void appendItem(const Symbol& item);
110
111   const Symbol* convertableToVariable();
112
113 private:
114   //dlist_array<Symbol> f_items;
115   f_items_t f_items;
116 };
117
118
119 class BinaryOperatorNode: public TermNode
120 {
121 public:
122   enum operatorType { PLUS, MINUS, TIMES, DIVIDE };
123
124   BinaryOperatorNode(operatorType, TermNode* left, TermNode* right);
125   ~BinaryOperatorNode();
126
127   virtual TermNode *clone() const;
128
129   virtual FeatureValue *evaluate() const;
130   ostream &print(ostream &) const;
131
132
133 private:
134   operatorType  f_operator ;
135   TermNode     *f_left;
136   TermNode     *f_right;
137
138 };
139
140 class SgmlAttributeNode: public TermNode
141 {
142 public:
143   SgmlAttributeNode(const Symbol& name);
144   SgmlAttributeNode();
145
146   virtual FeatureValue  *evaluate() const ;
147   ostream &print(ostream &) const;
148
149   virtual TermNode *clone() const;
150
151
152 private:
153   Symbol      f_name;
154 };
155
156 class ConstantNode: public TermNode
157 {
158 public:
159   ConstantNode(FeatureValue*);
160   ~ConstantNode();
161   virtual FeatureValue *evaluate() const;
162   ostream &print(ostream &) const;
163
164   virtual TermNode *clone() const;
165
166 private:
167   FeatureValue *f_value;
168
169 };
170
171 ostream &operator <<(ostream &, const Expression &);
172 ostream &operator <<(ostream &, const TermNode &);
173
174
175 #endif /* _Expression_h */
176 /* DO NOT ADD ANY LINES AFTER THIS #endif */