2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: Expression.h /main/4 1996/08/21 15:50:17 drk $ */
27 /* **************************************************************
28 Defines the tree for evaluating expressions given as feature values
30 * ************************************************************** */
38 typedef dlist_array<Symbol> f_items_t;
40 #include "dti_cc/cc_povec.h"
41 typedef dlist_array<Symbol> f_items_t;
48 // /////////////////////////////////////////////////////////////////////////
51 // holds root of expression tree
52 // /////////////////////////////////////////////////////////////////////////
58 Expression(TermNode *root);
59 Expression(const Expression&);
60 virtual ~Expression();
62 virtual FeatureValue *evaluate() const;
63 ostream &print(ostream &) const;
73 virtual FeatureValue *evaluate() const = 0;
74 virtual ostream &print(ostream &) const = 0;
75 virtual TermNode *clone() const = 0;
78 class VariableNode: public TermNode
80 // for single name variables eg: "DEFAULT_FONT"
82 VariableNode(const Symbol& name);
84 virtual FeatureValue *evaluate() const;
85 ostream &print(ostream &) const;
87 virtual TermNode *clone() const;
94 class CompositeVariableNode : public TermNode
96 // for feature path variables (font.size)
97 // eg: font: { size: font.size }
99 CompositeVariableNode();
100 CompositeVariableNode(size_t capac); /* if we know how many items to expect */
101 ~CompositeVariableNode();
103 virtual FeatureValue *evaluate() const ;
104 ostream &print(ostream &) const;
106 virtual TermNode *clone() const;
108 void prependItem(const Symbol& item);
109 void appendItem(const Symbol& item);
111 const Symbol* convertableToVariable();
114 //dlist_array<Symbol> f_items;
119 class BinaryOperatorNode: public TermNode
122 enum operatorType { PLUS, MINUS, TIMES, DIVIDE };
124 BinaryOperatorNode(operatorType, TermNode* left, TermNode* right);
125 ~BinaryOperatorNode();
127 virtual TermNode *clone() const;
129 virtual FeatureValue *evaluate() const;
130 ostream &print(ostream &) const;
134 operatorType f_operator ;
140 class SgmlAttributeNode: public TermNode
143 SgmlAttributeNode(const Symbol& name);
146 virtual FeatureValue *evaluate() const ;
147 ostream &print(ostream &) const;
149 virtual TermNode *clone() const;
156 class ConstantNode: public TermNode
159 ConstantNode(FeatureValue*);
161 virtual FeatureValue *evaluate() const;
162 ostream &print(ostream &) const;
164 virtual TermNode *clone() const;
167 FeatureValue *f_value;
171 ostream &operator <<(ostream &, const Expression &);
172 ostream &operator <<(ostream &, const TermNode &);
175 #endif /* _Expression_h */
176 /* DO NOT ADD ANY LINES AFTER THIS #endif */