Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / PathQualifier.C
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: PathQualifier.cc /main/4 1996/06/11 17:07:46 cde-hal $
24 #include "PathQualifier.h"
25 #include "Element.h"
26 #include "Attribute.h"
27 #include "Debug.h"
28
29
30 PQExpr::~PQExpr()
31 {
32   // empty 
33 }
34
35 PQAttributeSelector::~PQAttributeSelector()
36 {
37   // empty 
38 }
39
40 PQLogExpr::~PQLogExpr()
41 {
42   delete f_left ;
43   delete f_right ;
44 }
45
46 PQNot::PQNot(PQExpr *expr)
47 : f_expr(expr)
48 {
49 }
50
51 PQNot::~PQNot()
52 {
53   delete f_expr;
54 }
55
56 PQBoolean
57 PQNot::evaluate(const Element &element)
58 {
59   return (f_expr->evaluate(element) == PQTrue) ? PQFalse : PQTrue ;
60 }
61
62 PQPosition::PQPosition(PQEqOp optype, int position)
63 : f_optype(optype),
64   f_position(position)
65 {
66 }
67
68 PQBoolean
69 PQPosition::evaluate(const Element &element)
70 {
71    switch ( f_optype ) {
72      case PQEqual: 
73        if ( f_position == (int) element.sibling_number() ||
74             ( f_position==-1 && element.last_child() )
75           )
76           return PQTrue;
77        else 
78           return PQFalse;
79        break;
80
81      default: 
82        if ( f_position==-1 ) {
83           if ( element.last_child() == 0 )
84             return PQTrue;
85           else
86             return PQFalse;
87        } else
88           if ( f_position != (int) element.sibling_number() )
89              return PQTrue;
90           else
91              return PQFalse;
92        break;
93    }
94 }
95
96 PQSibling::PQSibling(PQEqOp optype, int sib)
97 : f_optype(optype),
98   f_sibling(sib)
99 {
100 }
101
102 PQBoolean
103 PQSibling::evaluate(const Element &element)
104 {
105    switch ( f_optype ) {
106      case PQEqual: 
107        if ( f_sibling == (int) element.relative_sibling_number() ||
108             ( f_sibling ==-1 && element.relatively_last_child() )
109           )
110           return PQTrue;
111        else 
112           return PQFalse;
113        break;
114
115      default: 
116        if ( f_sibling ==-1 ) {
117           if ( element.relatively_last_child() == 0 )
118             return PQTrue;
119           else
120             return PQFalse;
121        } else
122           if ( f_sibling != (int) element.relative_sibling_number() )
123              return PQTrue;
124           else
125              return PQFalse;
126        break;
127    }
128 }
129
130 PQAttributeSelector::PQAttributeSelector(const Symbol &attrname,
131                                          PQEqOp op,
132                                          const CC_String &string) 
133 : f_optype(op),
134   f_attribute(attrname),
135   f_string(string)
136 {
137 debug(cerr, op);
138 }
139
140 PQBoolean
141 PQAttributeSelector::evaluate(const Element &element)
142 {
143   PQBoolean return_value = PQFalse ;
144   
145   // see if attribute exists first 
146   const Attribute *attr = element.get_attribute(f_attribute);
147
148   if (attr)
149     {
150       // comparison value of 0 means strings are equal
151       int comparison = f_string.compareTo(attr->value());
152
153       if (((f_optype == PQEqual) && (comparison == 0)) ||
154           ((f_optype == PQNotEqual) && (comparison != 0)))
155         {
156           return_value = PQTrue ;
157         }
158     }
159   else
160     {
161       // not attribute, but if operator is not equal, we should return true
162       if (f_optype == PQNotEqual)
163         return_value = PQTrue ;
164     }
165   return return_value ;
166 }
167
168 PQLogExpr::PQLogExpr(PQExpr *left, PQLogOp op, PQExpr *right)
169 : f_optype(op),
170   f_left(left),
171   f_right(right)
172 {
173 }
174
175
176 PQBoolean
177 PQLogExpr::evaluate(const Element &element)
178 {
179   PQBoolean left_value = f_left->evaluate(element);
180   
181   if ((left_value == PQTrue) && (f_optype == PQor))
182     return PQTrue ;
183
184   if ((left_value == PQFalse) && (f_optype == PQand))
185     return PQFalse ;
186
187   return f_right->evaluate(element);
188 }
189