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: PathQualifier.cc /main/4 1996/06/11 17:07:46 cde-hal $
24 #include "PathQualifier.h"
26 #include "Attribute.h"
35 PQAttributeSelector::~PQAttributeSelector()
40 PQLogExpr::~PQLogExpr()
46 PQNot::PQNot(PQExpr *expr)
57 PQNot::evaluate(const Element &element)
59 return (f_expr->evaluate(element) == PQTrue) ? PQFalse : PQTrue ;
62 PQPosition::PQPosition(PQEqOp optype, int position)
69 PQPosition::evaluate(const Element &element)
73 if ( f_position == (int) element.sibling_number() ||
74 ( f_position==-1 && element.last_child() )
82 if ( f_position==-1 ) {
83 if ( element.last_child() == 0 )
88 if ( f_position != (int) element.sibling_number() )
96 PQSibling::PQSibling(PQEqOp optype, int sib)
103 PQSibling::evaluate(const Element &element)
105 switch ( f_optype ) {
107 if ( f_sibling == (int) element.relative_sibling_number() ||
108 ( f_sibling ==-1 && element.relatively_last_child() )
116 if ( f_sibling ==-1 ) {
117 if ( element.relatively_last_child() == 0 )
122 if ( f_sibling != (int) element.relative_sibling_number() )
130 PQAttributeSelector::PQAttributeSelector(const Symbol &attrname,
132 const CC_String &string)
134 f_attribute(attrname),
141 PQAttributeSelector::evaluate(const Element &element)
143 PQBoolean return_value = PQFalse ;
145 // see if attribute exists first
146 const Attribute *attr = element.get_attribute(f_attribute);
150 // comparison value of 0 means strings are equal
151 int comparison = f_string.compareTo(attr->value());
153 if (((f_optype == PQEqual) && (comparison == 0)) ||
154 ((f_optype == PQNotEqual) && (comparison != 0)))
156 return_value = PQTrue ;
161 // not attribute, but if operator is not equal, we should return true
162 if (f_optype == PQNotEqual)
163 return_value = PQTrue ;
165 return return_value ;
168 PQLogExpr::PQLogExpr(PQExpr *left, PQLogOp op, PQExpr *right)
177 PQLogExpr::evaluate(const Element &element)
179 PQBoolean left_value = f_left->evaluate(element);
181 if ((left_value == PQTrue) && (f_optype == PQor))
184 if ((left_value == PQFalse) && (f_optype == PQand))
187 return f_right->evaluate(element);