00001 00002 /* 00003 | Author: Michael Schmidt; 00004 | Gunnar Jehl 00005 | 00006 | ************************* SOFTWARE LICENSE AGREEMENT *********************** 00007 | This source code is published under the BSD License. 00008 | 00009 | See file 'LICENSE.txt' that comes with this distribution or 00010 | http://dbis.informatik.uni-freiburg.de/index.php?project=GCX/license.php 00011 | for the full license agreement. 00012 | 00013 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00014 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00016 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00017 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00018 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00019 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00020 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00021 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00022 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00023 | POSSIBILITY OF SUCH DAMAGE. 00024 | **************************************************************************** 00025 */ 00026 00035 #include "pathstepexpression.h" 00036 #include "pathsteptagexpression.h" 00037 #include "pathstepstarexpression.h" 00038 #include "pathstepnodeexpression.h" 00039 #include "pathsteptextexpression.h" 00040 00041 PathStepExpression::PathStepExpression(EXP_TYPE _type, AXIS_TYPE _axis, 00042 PathStepAttribute * 00043 _attribute):Expression(_type), 00044 axis(_axis), 00045 attribute(_attribute) { 00046 } 00047 00048 PathStepExpression::~PathStepExpression() { 00049 delete attribute; 00050 } 00051 00052 NODETEST_TYPE PathStepExpression::getNodeTestType() { 00053 switch (type) { 00054 case et_pathsteptag: 00055 return ntt_tag; 00056 case et_pathstepstar: 00057 return ntt_star; 00058 case et_pathstepnode: 00059 return ntt_node; 00060 case et_pathsteptext: 00061 return ntt_text; 00062 default: // should never happen 00063 return ntt_tag; 00064 } 00065 } 00066 00067 unsigned PathStepExpression::getStepWeight(bool is_last_step) { 00068 unsigned weight = 0; 00069 00070 switch (axis) { 00071 case at_child: 00072 weight = WEIGHT_AXIS_CHILD; 00073 break; 00074 case at_descendant: 00075 weight = WEIGHT_AXIS_DESCENDANT; 00076 break; 00077 case at_dos: 00078 weight = WEIGHT_AXIS_DOS; 00079 break; 00080 } 00081 if (is_last_step) { 00082 switch (type) { 00083 case et_pathsteptag: 00084 weight = weight * WEIGHT_NODETEST_TAG; 00085 break; 00086 case et_pathstepstar: 00087 weight = weight * WEIGHT_NODETEST_STAR; 00088 break; 00089 case et_pathstepnode: 00090 weight = weight * WEIGHT_NODETEST_NODE; 00091 break; 00092 case et_pathsteptext: 00093 weight = weight * WEIGHT_NODETEST_TEXT; 00094 break; 00095 default: // should never happen 00096 break; 00097 } 00098 } else { 00099 weight = weight * WEIGHT_INNER_NODETEST; 00100 } 00101 00102 return weight; 00103 } 00104 00105 bool PathStepExpression::isSyntacticallyEqualTo(PathStepExpression * ps) { 00106 if (ps) { 00107 if (axis != ps->getAxisType()) { 00108 return false; 00109 } else if (getNodeTestType() != ps->getNodeTestType()) { 00110 return false; 00111 } else if (ps->isTagNodeTest()) { 00112 return isMatchingTag(((PathStepTagExpression *) ps)->getNodeTest()); 00113 } 00114 return true; 00115 } 00116 return false; 00117 }