Merge lp:~28msec/zorba/get-descendant-node-by-ordpath into lp:zorba

Proposed by Ghislain Fourny
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 10698
Merged at revision: 10719
Proposed branch: lp:~28msec/zorba/get-descendant-node-by-ordpath
Merge into: lp:zorba
Diff against target: 136 lines (+116/-0)
2 files modified
src/store/naive/node_items.cpp (+107/-0)
src/store/naive/node_items.h (+9/-0)
To merge this branch: bzr merge lp:~28msec/zorba/get-descendant-node-by-ordpath
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Matthias Brantner Approve
Review via email: mp+95902@code.launchpad.net

Commit message

Introduced function OrdPathNode::getDescendantNodeByOrdPath (from Sausalito).

Description of the change

Introduced function OrdPathNode::getDescendantNodeByOrdPath (from Sausalito).

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job get-descendant-node-by-ordpath-2012-03-05T14-33-05.571Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 3 Pending.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job get-descendant-node-by-ordpath-2012-03-05T20-26-03.63Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 1 Approve, 2 Pending.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Within the for loop:

for (i = 0; i < numAttrs; i++)

in the case of (pos == OrdPath::DESCENDANT) the function should return false, no?

Also, please use csize (instead of ulong) for storing the size of vectors and for iterating over vectors.

Also, in for loops, do ++i instead of i++. It's a very tiny optimization, but it doesn't cost anything so why let it pass....

Revision history for this message
Ghislain Fourny (gislenius) wrote :

Thanks Markos for these useful comments. The new revision addresses all three of them.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

The numAttrs and numChildren local vars should also be csize instead of ulong, but I approve anyway.

review: Approve
Revision history for this message
Ghislain Fourny (gislenius) wrote :

Hi Markos, thanks, these two were updated as well before triggering the merge.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job get-descendant-node-by-ordpath-2012-03-13T11-52-05.311Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp 2012-03-12 23:43:56 +0000
+++ src/store/naive/node_items.cpp 2012-03-13 10:31:28 +0000
@@ -1052,6 +1052,113 @@
1052 }1052 }
1053}1053}
10541054
1055/*******************************************************************************
1056
1057********************************************************************************/
1058bool
1059OrdPathNode::getDescendantNodeByOrdPath(
1060 const OrdPath& aOrdPath,
1061 store::Item_t& aResult,
1062 bool aAttribute) const
1063{
1064#ifdef TEXT_ORDPATH
1065 if (getOrdPath() == aOrdPath)
1066 {
1067 aResult = this;
1068 return true;
1069 }
1070#else
1071 if (getNodeKind() == store::StoreConsts::textNode)
1072 {
1073 aResult = NULL;
1074 return false;
1075 }
1076 else if (getOrdPath() == aOrdPath)
1077 {
1078 aResult = this;
1079 return true;
1080 }
1081#endif
1082
1083 const XmlNode* parent = static_cast<const XmlNode*>(this);
1084 csize i;
1085
1086 while (1)
1087 {
1088 if (parent->getNodeKind() != store::StoreConsts::documentNode &&
1089 parent->getNodeKind() != store::StoreConsts::elementNode)
1090 {
1091 aResult = NULL;
1092 return false;
1093 }
1094
1095 if (aAttribute && parent->getNodeKind() == store::StoreConsts::elementNode)
1096 {
1097 const ElementNode* elemParent = reinterpret_cast<const ElementNode*>(parent);
1098
1099 csize numAttrs = elemParent->numAttrs();
1100 for (i = 0; i < numAttrs; ++i)
1101 {
1102 AttributeNode* child = elemParent->getAttr(i);
1103
1104 OrdPath::RelativePosition pos = child->getOrdPath().getRelativePosition(aOrdPath);
1105
1106 if (pos == OrdPath::SELF)
1107 {
1108 aResult = child;
1109 return true;
1110 }
1111 else if (pos != OrdPath::FOLLOWING) // Includes DESCENDANT case
1112 {
1113 aResult = NULL;
1114 return false;
1115 }
1116 }
1117 }
1118
1119 const InternalNode* this2 = reinterpret_cast<const InternalNode*>(parent);
1120
1121 csize numChildren = this2->numChildren();
1122 for (i = 0; i < numChildren; ++i)
1123 {
1124#ifdef TEXT_ORDPATH
1125 OrdPathNode* child = static_cast<OrdPathNode*>(this2->getChild(i));
1126#else
1127 XmlNode* c = this2->getChild(i);
1128
1129 if (c->getNodeKind() == store::StoreConsts::textNode)
1130 continue;
1131
1132 OrdPathNode* child = static_cast<OrdPathNode*>(c);
1133#endif
1134
1135 OrdPath::RelativePosition pos = child->getOrdPath().getRelativePosition(aOrdPath);
1136
1137 if (pos == OrdPath::SELF)
1138 {
1139 aResult = child;
1140 return true;
1141 }
1142 else if (pos == OrdPath::DESCENDANT)
1143 {
1144 parent = child;
1145 break;
1146 }
1147 else if (pos != OrdPath::FOLLOWING)
1148 {
1149 aResult = NULL;
1150 return false;
1151 }
1152 }
1153
1154 if (i == numChildren)
1155 {
1156 aResult = NULL;
1157 return false;
1158 }
1159 }
1160}
1161
10551162
1056/*******************************************************************************1163/*******************************************************************************
1057 Return true if "aOther" is an ancestore of "this".1164 Return true if "aOther" is an ancestore of "this".
10581165
=== modified file 'src/store/naive/node_items.h'
--- src/store/naive/node_items.h 2012-03-07 14:22:29 +0000
+++ src/store/naive/node_items.h 2012-03-13 10:31:28 +0000
@@ -664,6 +664,15 @@
664 csize pos,664 csize pos,
665 store::StoreConsts::NodeKind nodeKind);665 store::StoreConsts::NodeKind nodeKind);
666666
667 // Looks for a descendant node with the ordpath aOrdPath and puts it into the
668 // aResult variable. aAttribute specifies whether to look for an attribute or
669 // not.
670 bool
671 getDescendantNodeByOrdPath(
672 const OrdPath& aOrdPath,
673 store::Item_t& aResult,
674 bool aAttribute = false) const;
675
667 virtual bool676 virtual bool
668 isAncestor(const store::Item_t&) const;677 isAncestor(const store::Item_t&) const;
669678

Subscribers

People subscribed via source and target branches