Merge lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba

Proposed by Ghislain Fourny
Status: Merged
Approved by: Ghislain Fourny
Approved revision: 10746
Merged at revision: 11001
Proposed branch: lp:~zorba-coders/zorba/structural-any-uri-lazy
Merge into: lp:zorba
Diff against target: 1015 lines (+386/-170)
4 files modified
src/store/naive/atomic_items.cpp (+248/-64)
src/store/naive/atomic_items.h (+124/-77)
src/store/naive/item.cpp (+10/-18)
src/store/naive/simple_item_factory.cpp (+4/-11)
To merge this branch: bzr merge lp:~zorba-coders/zorba/structural-any-uri-lazy
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Matthias Brantner Approve
Review via email: mp+104918@code.launchpad.net

This proposal supersedes a proposal from 2012-03-28.

Commit message

Made URI computation lazy in StructuralAnyUri.

Description of the change

Made URI computation lazy in StructuralAnyUri.

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job structural-any-uri-lazy-2012-03-28T18-00-41.433Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Markos Zaharioudakis (markos-za) wrote : Posted in a previous version of this proposal

It seems some of the changes made here will conflict with the chengs made in the tree-id branch. Ghislain can you try to merge the trunk into this branch and resolve the conflicts?

Also, I don't like the fact that a zstring (i.e., theValue) is now just wasted space in each StructuralAnyUriItem. Either make theValue mutable so that it can be reused by StructuralAnyUriItem, or don't make StructuralAnyUriItem a subclass of AnyUriItem anymore (it dosn't inherit much from AnyUriItem anymore).

Revision history for this message
Markos Zaharioudakis (markos-za) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Ghislain Fourny (gislenius) wrote : Posted in a previous version of this proposal

Thanks Markos for your useful comments. The new revision takes them all into account.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Markos Zaharioudakis (markos-za) wrote : Posted in a previous version of this proposal

Now that the StructuralAnyUriItem does not inherit from AnyUriItem anymore, the method getAnyUriTypeCode() should be added (as virual) to the AtomicItem class, with a default implementation throwing an error.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job structural-any-uri-lazy-2012-04-04T13-30-26.473Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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 : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job structural-any-uri-lazy-2012-05-05T03-28-00.002Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

Ghislain, you changed the StructuralAnyUriItem constructor to take a const zstring&, instead of zstring&. I prefer that you revert this change (because the old way is more consistent with the rest of the item factory methods), but if want to keep the "const" it's ok, but then the use of the temp zstring variable in methods inAncestor, isFollowing, etc is no longer needed (in both their StructuralAnyUriItem and AnyUriItem versions). The static_cast of the aOther param in those methods is also not needed any more.

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Needs Fixing
Revision history for this message
Ghislain Fourny (gislenius) wrote :

Hi Markos,

Thanks for your feedback, this is fixed for consistency (though in general, I prefer to have all references const in function parameters).

However, I could not find why the static_cast is not needed - the methods and variables are not part of the zorba::store::Item API?

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

Hi Ghislain,

The point of the non-const param is to call take() inside the constructor, thus saving a (synchronized) ref counting. I have now added this take() call in the StructuralAnyURIItem constructor.

You are right about the static casts. I thought that getAnyUriTypeCode() was a zorba::Item method. I have added a ZORBA_ASSERT() to make sure that the "aOther" param is indeed an atomic item.

Revision history for this message
Markos Zaharioudakis (markos-za) :
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 structural-any-uri-lazy-2012-08-27T15-25-59.316Z 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
1=== modified file 'src/store/naive/atomic_items.cpp'
2--- src/store/naive/atomic_items.cpp 2012-08-16 18:31:02 +0000
3+++ src/store/naive/atomic_items.cpp 2012-08-27 09:01:20 +0000
4@@ -14,6 +14,8 @@
5 * limitations under the License.
6 */
7 #include "stdafx.h"
8+#include "atomic_items.h"
9+
10 #include <limits.h>
11
12 #include <zorba/internal/unique_ptr.h>
13@@ -38,7 +40,6 @@
14 #include "store_defs.h"
15 #include "item_iterator.h"
16 #include "node_items.h"
17-#include "atomic_items.h"
18 #include "ordpath.h"
19 #include "tree_id.h"
20
21@@ -72,6 +73,18 @@
22
23
24 /*******************************************************************************
25+
26+********************************************************************************/
27+AnyUriTypeCode AtomicItem::getAnyUriTypeCode() const
28+{
29+ throw ZORBA_EXCEPTION(
30+ zerr::ZSTR0050_FUNCTION_NOT_IMPLEMENTED_FOR_ITEMTYPE,
31+ ERROR_PARAMS( __FUNCTION__, typeid(*this).name() )
32+ );
33+}
34+
35+
36+/*******************************************************************************
37 For numeric items or the untyped item: convert this item to a long item,
38 if possible, i.e., if the conversion is going to be lossless.
39 ********************************************************************************/
40@@ -897,7 +910,7 @@
41 bool AnyUriItem::isFollowingSibling(const store::Item_t& aOther) const
42 {
43 store::Item_t lThisUri;
44- zstring tempValue=theValue;
45+ zstring tempValue = theValue;
46 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
47 return lThisUri->isFollowingSibling(aOther);
48 }
49@@ -906,7 +919,7 @@
50 bool AnyUriItem::isFollowing(const store::Item_t& aOther) const
51 {
52 store::Item_t lThisUri;
53- zstring tempValue=theValue;
54+ zstring tempValue = theValue;
55 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
56 return lThisUri->isFollowing(aOther);
57 }
58@@ -915,7 +928,7 @@
59 bool AnyUriItem::isDescendant(const store::Item_t& aOther) const
60 {
61 store::Item_t lThisUri;
62- zstring tempValue=theValue;
63+ zstring tempValue = theValue;
64 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
65 return lThisUri->isDescendant(aOther);
66 }
67@@ -924,7 +937,7 @@
68 bool AnyUriItem::isInSubtreeOf(const store::Item_t& aOther) const
69 {
70 store::Item_t lThisUri;
71- zstring tempValue=theValue;
72+ zstring tempValue = theValue;
73 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
74 return lThisUri->isInSubtreeOf(aOther);
75 }
76@@ -933,7 +946,7 @@
77 bool AnyUriItem::isPrecedingSibling(const store::Item_t& aOther) const
78 {
79 store::Item_t lThisUri;
80- zstring tempValue=theValue;
81+ zstring tempValue = theValue;
82 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
83 return lThisUri->isPrecedingSibling(aOther);
84 }
85@@ -942,7 +955,7 @@
86 bool AnyUriItem::isPreceding(const store::Item_t& aOther) const
87 {
88 store::Item_t lThisUri;
89- zstring tempValue=theValue;
90+ zstring tempValue = theValue;
91 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
92 return lThisUri->isPreceding(aOther);
93 }
94@@ -951,7 +964,7 @@
95 bool AnyUriItem::isChild(const store::Item_t& aOther) const
96 {
97 store::Item_t lThisUri;
98- zstring tempValue=theValue;
99+ zstring tempValue = theValue;
100 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
101 return lThisUri->isChild(aOther);
102 }
103@@ -960,7 +973,7 @@
104 bool AnyUriItem::isAttribute(const store::Item_t& aOther) const
105 {
106 store::Item_t lThisUri;
107- zstring tempValue=theValue;
108+ zstring tempValue = theValue;
109 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
110 return lThisUri->isAttribute(aOther);
111 }
112@@ -969,7 +982,7 @@
113 bool AnyUriItem::isParent(const store::Item_t& aOther) const
114 {
115 store::Item_t lThisUri;
116- zstring tempValue=theValue;
117+ zstring tempValue = theValue;
118 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
119 return lThisUri->isParent(aOther);
120 }
121@@ -978,7 +991,7 @@
122 bool AnyUriItem::isPrecedingInDocumentOrder(const store::Item_t& aOther) const
123 {
124 store::Item_t lThisUri;
125- zstring tempValue=theValue;
126+ zstring tempValue = theValue;
127 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
128 return lThisUri->isPrecedingInDocumentOrder(aOther);
129 }
130@@ -987,7 +1000,7 @@
131 bool AnyUriItem::isFollowingInDocumentOrder(const store::Item_t& aOther) const
132 {
133 store::Item_t lThisUri;
134- zstring tempValue=theValue;
135+ zstring tempValue = theValue;
136 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
137 return lThisUri->isFollowingInDocumentOrder(aOther);
138 }
139@@ -996,7 +1009,7 @@
140 store::Item_t AnyUriItem::getLevel() const
141 {
142 store::Item_t lThisUri;
143- zstring tempValue=theValue;
144+ zstring tempValue = theValue;
145 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
146 return lThisUri->getLevel();
147 }
148@@ -1059,7 +1072,7 @@
149 bool AnyUriItem::isSibling(const store::Item_t& aOther) const
150 {
151 store::Item_t lThisUri;
152- zstring tempValue=theValue;
153+ zstring tempValue = theValue;
154 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
155 return lThisUri->isSibling(aOther);
156 }
157@@ -1068,7 +1081,7 @@
158 bool AnyUriItem::inSameTree(const store::Item_t& aOther) const
159 {
160 store::Item_t lThisUri;
161- zstring tempValue=theValue;
162+ zstring tempValue = theValue;
163 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
164 return lThisUri->inSameTree(aOther);
165 }
166@@ -1077,7 +1090,7 @@
167 bool AnyUriItem::inCollection() const
168 {
169 store::Item_t lThisUri;
170- zstring tempValue=theValue;
171+ zstring tempValue = theValue;
172 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
173 return static_cast<StructuralAnyUriItem *>(lThisUri.getp())->inCollection();
174 }
175@@ -1086,7 +1099,7 @@
176 bool AnyUriItem::inSameCollection(const store::Item_t& aOther) const
177 {
178 store::Item_t lThisUri;
179- zstring tempValue=theValue;
180+ zstring tempValue = theValue;
181 GET_FACTORY().createStructuralAnyURI(lThisUri, tempValue);
182 return lThisUri->inSameCollection(aOther);
183 }
184@@ -1097,7 +1110,6 @@
185 ********************************************************************************/
186
187 StructuralAnyUriItem::StructuralAnyUriItem(
188- zstring& encoded,
189 ulong collectionId,
190 const TreeId& treeId,
191 store::StoreConsts::NodeKind nodeKind,
192@@ -1106,17 +1118,20 @@
193 theCollectionId(collectionId),
194 theTreeId(treeId),
195 theNodeKind(nodeKind),
196- theOrdPath(ordPath)
197+ theOrdPath(ordPath),
198+ theEncodedValue("")
199 {
200- theValue.take(encoded);
201 }
202
203
204 StructuralAnyUriItem::StructuralAnyUriItem(zstring& value)
205 {
206- theValue.take(value);
207+ if (value == "")
208+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
209+ ERROR_PARAMS(theEncodedValue));
210
211- std::istringstream input(theValue.str());
212+ theEncodedValue.take(value);
213+ std::istringstream input(theEncodedValue.str());
214
215 ulong prefixlen = (ulong)strlen("zorba:");
216
217@@ -1126,51 +1141,64 @@
218 input >> prefix;
219
220 if (!input.good())
221- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
222+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
223+ ERROR_PARAMS(theEncodedValue));
224
225 if (prefix != "zorba:")
226- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
227+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
228+ ERROR_PARAMS(theEncodedValue));
229
230 input >> theCollectionId;
231
232 if (!input.good())
233- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
234+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
235+ ERROR_PARAMS(theEncodedValue));
236
237 char period;
238 input >> period;
239 if (!input.good())
240- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
241+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
242+ ERROR_PARAMS(theEncodedValue));
243 if (period != '.')
244- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
245+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
246+ ERROR_PARAMS(theEncodedValue));
247
248
249 input >> theTreeId;
250 if (!input.good())
251- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
252+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
253+ ERROR_PARAMS(theEncodedValue));
254
255 input >> period;
256 if (!input.good())
257- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
258+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
259+ ERROR_PARAMS(theEncodedValue));
260 if (period != '.')
261- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
262+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
263+ ERROR_PARAMS(theEncodedValue));
264
265 int lNodeKind;
266 input >> lNodeKind;
267 theNodeKind = static_cast<store::StoreConsts::NodeKind>(lNodeKind);
268 if (!input.good())
269- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
270+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
271+ ERROR_PARAMS(theEncodedValue));
272 if (lNodeKind <= 0 || lNodeKind > 6)
273- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
274+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
275+ ERROR_PARAMS(theEncodedValue));
276
277 input >> period;
278 if (period != '.')
279- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
280+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
281+ ERROR_PARAMS(theEncodedValue));
282 if (!input.good())
283- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
284+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
285+ ERROR_PARAMS(theEncodedValue));
286
287 input >> prefix;
288 if (!input.eof())
289- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
290+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI,
291+ ERROR_PARAMS(theEncodedValue));
292
293 try
294 {
295@@ -1178,9 +1206,135 @@
296 }
297 catch(...)
298 {
299- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
300- }
301- // = OrdPath(reinterpret_cast<const unsigned char*>(prefix.c_str()), prefix.size());
302+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
303+ }
304+}
305+
306+store::Item* StructuralAnyUriItem::getType() const
307+{
308+ return GET_STORE().theSchemaTypeNames[store::XS_ANY_URI];
309+}
310+
311+
312+uint32_t StructuralAnyUriItem::hash(long timezone, const XQPCollator* aCollation) const
313+{
314+ return hashfun::h32(theEncodedValue.data(), (uint32_t)theEncodedValue.size());
315+}
316+
317+
318+void StructuralAnyUriItem::encode() const
319+{
320+ ZORBA_FATAL(theNodeKind,"Unexpected node kind");
321+ std::ostringstream stream;
322+ stream << "zorba:"
323+ << theCollectionId << "."
324+ << theTreeId << "."
325+ << static_cast<int>(theNodeKind) << "."
326+ << theOrdPath.serialize();
327+ zorba::zstring lValue = stream.str();
328+ theEncodedValue.take(lValue);
329+}
330+
331+
332+zstring StructuralAnyUriItem::show() const
333+{
334+ zstring res("xs:anyURI(");
335+ res += getString();
336+ res += ")";
337+ return res;
338+}
339+
340+
341+bool StructuralAnyUriItem::equals(
342+ const store::Item* other,
343+ long timezone,
344+ const XQPCollator* aCollation) const
345+{
346+ const StructuralAnyUriItem* lOther =
347+ dynamic_cast<const StructuralAnyUriItem*>(other);
348+
349+ if (lOther == NULL)
350+ {
351+ throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR,
352+ ERROR_PARAMS(ZED(NoCompareTypes_23),
353+ "xs:structuralAnyURI",
354+ other->getType()->getStringValue()));
355+ }
356+
357+ return (lOther->theCollectionId == theCollectionId &&
358+ lOther->theTreeId == theTreeId &&
359+ lOther->theNodeKind == theNodeKind &&
360+ lOther->theOrdPath == theOrdPath);
361+}
362+
363+
364+long StructuralAnyUriItem::compare(
365+ const Item* other,
366+ long timezone,
367+ const XQPCollator* aCollation) const
368+{
369+ const StructuralAnyUriItem* lOther =
370+ dynamic_cast<const StructuralAnyUriItem*>(other);
371+
372+ if (lOther == NULL)
373+ {
374+ throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR,
375+ ERROR_PARAMS(ZED(NoCompareTypes_23),
376+ "xs:structuralAnyURI",
377+ other->getType()->getStringValue()));
378+ }
379+
380+ if (theCollectionId < lOther->theCollectionId)
381+ {
382+ return -1;
383+ }
384+ if (theCollectionId > lOther->theCollectionId)
385+ {
386+ return 1;
387+ }
388+ if (theTreeId < lOther->theTreeId)
389+ {
390+ return -1;
391+ }
392+ if (theTreeId > lOther->theTreeId)
393+ {
394+ return 1;
395+ }
396+ if (theNodeKind < lOther->theNodeKind)
397+ {
398+ return -1;
399+ }
400+ if (theNodeKind > lOther->theNodeKind)
401+ {
402+ return 1;
403+ }
404+ if (theOrdPath < lOther->theOrdPath)
405+ {
406+ return -1;
407+ }
408+ if (theOrdPath > lOther->theOrdPath)
409+ {
410+ return 1;
411+ }
412+ return 0;
413+}
414+
415+
416+zstring StructuralAnyUriItem::getStringValue() const
417+{
418+ return getString();
419+}
420+
421+
422+void StructuralAnyUriItem::getStringValue2(zstring& val) const
423+{
424+ val = getString();
425+}
426+
427+
428+void StructuralAnyUriItem::appendStringValue(zstring& buf) const
429+{
430+ buf += getString();
431 }
432
433
434@@ -1188,12 +1342,14 @@
435 {
436 // Is the "other" an ancestor of "this"?
437
438- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
439+ ZORBA_ASSERT(aOther->isAtomic());
440+
441+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
442
443 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
444 {
445 store::Item_t lOtherUri;
446- zstring tmp = lOtherUriP->theValue;
447+ zstring tmp = lOtherUriP->getString();
448 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
449 return isAncestor(lOtherUri);
450 }
451@@ -1213,12 +1369,14 @@
452 {
453 // Is the "other" a following sibling of "this"?
454
455- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
456+ ZORBA_ASSERT(aOther->isAtomic());
457+
458+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
459
460 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
461 {
462 store::Item_t lOtherUri;
463- zstring tmp = lOtherUriP->theValue;
464+ zstring tmp = lOtherUriP->getString();
465 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
466 return isFollowingSibling(lOtherUri);
467 }
468@@ -1240,12 +1398,14 @@
469 {
470 // Is the "other" a following node of "this"?
471
472- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
473+ ZORBA_ASSERT(aOther->isAtomic());
474+
475+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
476
477 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
478 {
479 store::Item_t lOtherUri;
480- zstring tmp = lOtherUriP->theValue;
481+ zstring tmp = lOtherUriP->getString();
482 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
483 return isFollowing(lOtherUri);
484 }
485@@ -1265,12 +1425,14 @@
486 {
487 // Is the "other" a descendant of "this"?
488
489- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
490+ ZORBA_ASSERT(aOther->isAtomic());
491+
492+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
493
494 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
495 {
496 store::Item_t lOtherUri;
497- zstring tmp = lOtherUriP->theValue;
498+ zstring tmp = lOtherUriP->getString();
499 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
500 return isDescendant(lOtherUri);
501 }
502@@ -1290,12 +1452,14 @@
503 {
504 // Is the "other" in the subtree rooted at "this"?
505
506- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
507+ ZORBA_ASSERT(aOther->isAtomic());
508+
509+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
510
511 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
512 {
513 store::Item_t lOtherUri;
514- zstring tmp = lOtherUriP->theValue;
515+ zstring tmp = lOtherUriP->getString();
516 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
517 return isInSubtreeOf(lOtherUri);
518 }
519@@ -1314,12 +1478,14 @@
520 {
521 // Is the "other" a preceding sibling of "this"?
522
523- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
524+ ZORBA_ASSERT(aOther->isAtomic());
525+
526+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
527
528 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
529 {
530 store::Item_t lOtherUri;
531- zstring tmp = lOtherUriP->theValue;
532+ zstring tmp = lOtherUriP->getString();
533 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
534 return isPrecedingSibling(lOtherUri);
535 }
536@@ -1340,12 +1506,14 @@
537 {
538 // Is the "other" a preceding node of "this"?
539
540- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
541+ ZORBA_ASSERT(aOther->isAtomic());
542+
543+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
544
545 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
546 {
547 store::Item_t lOtherUri;
548- zstring tmp = lOtherUriP->theValue;
549+ zstring tmp = lOtherUriP->getString();
550 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
551 return isPreceding(lOtherUri);
552 }
553@@ -1364,12 +1532,14 @@
554 {
555 // Is the "other" a child of "this"?
556
557- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
558+ ZORBA_ASSERT(aOther->isAtomic());
559+
560+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
561
562 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
563 {
564 store::Item_t lOtherUri;
565- zstring tmp = lOtherUriP->theValue;
566+ zstring tmp = lOtherUriP->getString();
567 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
568 return isChild(lOtherUri);
569 }
570@@ -1389,12 +1559,14 @@
571 {
572 // Is the "other" an attribute of "this"?
573
574- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
575+ ZORBA_ASSERT(aOther->isAtomic());
576+
577+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
578
579 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
580 {
581 store::Item_t lOtherUri;
582- zstring tmp = lOtherUriP->theValue;
583+ zstring tmp = lOtherUriP->getString();
584 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
585 return isAttribute(lOtherUri);
586 }
587@@ -1414,12 +1586,14 @@
588 {
589 // Is the "other" an parent of "this"?
590
591+ ZORBA_ASSERT(aOther->isAtomic());
592+
593 AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
594
595 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
596 {
597 store::Item_t lOtherUri;
598- zstring tmp = lOtherUriP->theValue;
599+ zstring tmp = lOtherUriP->getString();
600 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
601 return isParent(lOtherUri);
602 }
603@@ -1436,12 +1610,14 @@
604
605 bool StructuralAnyUriItem::isPrecedingInDocumentOrder(const store::Item_t& aOther) const
606 {
607- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
608+ ZORBA_ASSERT(aOther->isAtomic());
609+
610+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
611
612 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
613 {
614 store::Item_t lOtherUri;
615- zstring tmp = lOtherUriP->theValue;
616+ zstring tmp = lOtherUriP->getString();
617 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
618 return isPrecedingInDocumentOrder(lOtherUri);
619 }
620@@ -1461,12 +1637,14 @@
621
622 bool StructuralAnyUriItem::isFollowingInDocumentOrder(const store::Item_t& aOther) const
623 {
624- AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
625+ ZORBA_ASSERT(aOther->isAtomic());
626+
627+ AtomicItem* lOtherUriP = static_cast<AtomicItem *>(aOther.getp());
628
629 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
630 {
631 store::Item_t lOtherUri;
632- zstring tmp = lOtherUriP->theValue;
633+ zstring tmp = lOtherUriP->getString();
634 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
635 return isFollowingInDocumentOrder(lOtherUri);
636 }
637@@ -1530,12 +1708,14 @@
638
639 bool StructuralAnyUriItem::isSibling(const store::Item_t& aOther) const
640 {
641+ ZORBA_ASSERT(aOther->isAtomic());
642+
643 AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
644
645 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
646 {
647 store::Item_t lOtherUri;
648- zstring tmp = lOtherUriP->theValue;
649+ zstring tmp = lOtherUriP->getString();
650 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
651 return isSibling(lOtherUri);
652 }
653@@ -1564,12 +1744,14 @@
654
655 bool StructuralAnyUriItem::inSameTree(const store::Item_t& aOther) const
656 {
657+ ZORBA_ASSERT(aOther->isAtomic());
658+
659 AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
660
661 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
662 {
663 store::Item_t lOtherUri;
664- zstring tmp = lOtherUriP->theValue;
665+ zstring tmp = lOtherUriP->getString();
666 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
667 return inSameTree(lOtherUri);
668 }
669@@ -1590,12 +1772,14 @@
670
671 bool StructuralAnyUriItem::inSameCollection(const store::Item_t& aOther) const
672 {
673+ ZORBA_ASSERT(aOther->isAtomic());
674+
675 AnyUriItem* lOtherUriP = static_cast<AnyUriItem *>(aOther.getp());
676
677 if (lOtherUriP->getAnyUriTypeCode() != STRUCTURAL_INFORMATION_ANY_URI)
678 {
679 store::Item_t lOtherUri;
680- zstring tmp = lOtherUriP->theValue;
681+ zstring tmp = lOtherUriP->getString();
682 GET_FACTORY().createStructuralAnyURI(lOtherUri, tmp);
683 return inSameCollection(lOtherUri);
684 }
685
686=== modified file 'src/store/naive/atomic_items.h'
687--- src/store/naive/atomic_items.h 2012-08-21 14:14:53 +0000
688+++ src/store/naive/atomic_items.h 2012-08-27 09:01:20 +0000
689@@ -82,6 +82,8 @@
690
691 void getTypedValue(store::Item_t& val, store::Iterator_t& iter) const;
692
693+ virtual AnyUriTypeCode getAnyUriTypeCode() const;
694+
695 bool castToLong(store::Item_t& result) const;
696
697 void coerceToDouble(store::Item_t& result, bool force, bool& lossy) const;
698@@ -580,7 +582,6 @@
699 class AnyUriItem : public AtomicItem
700 {
701 friend class BasicItemFactory;
702- friend class StructuralAnyUriItem;
703
704 protected:
705 zstring theValue;
706@@ -704,102 +705,148 @@
707 /*******************************************************************************
708 class StructuralAnyUriItem
709 ********************************************************************************/
710-class StructuralAnyUriItem : public AnyUriItem
711+class StructuralAnyUriItem : public AtomicItem
712 {
713- friend class BasicItemFactory;
714-
715 protected:
716 ulong theCollectionId;
717 TreeId theTreeId;
718 store::StoreConsts::NodeKind theNodeKind;
719 OrdPath theOrdPath;
720+
721+ // The value is computed lazily when needed.
722+ // The empty string is used if it has not been computed yet.
723+ mutable zstring theEncodedValue;
724
725-protected:
726+public:
727 virtual AnyUriTypeCode getAnyUriTypeCode() const
728 {
729 return STRUCTURAL_INFORMATION_ANY_URI;
730 }
731+
732+ store::SchemaTypeCode getTypeCode() const
733+ {
734+ return store::XS_ANY_URI;
735+ }
736+
737+ store::Item* getType() const;
738+
739+ uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const;
740+
741+ bool equals(
742+ const store::Item* item,
743+ long timezone = 0,
744+ const XQPCollator* aCollation = 0) const;
745+
746+ long compare(
747+ const Item* other,
748+ long timezone = 0,
749+ const XQPCollator* aCollation = 0) const;
750+
751+ // A structural URI is never empty.
752+ bool getEBV() const { return true; }
753+
754+ zstring getStringValue() const;
755+
756+ void getStringValue2(zstring& val) const;
757+
758+ void appendStringValue(zstring& buf) const;
759+
760+ const zstring& getString() const
761+ {
762+ if (theEncodedValue == "")
763+ {
764+ encode();
765+ }
766+ return theEncodedValue;
767+ }
768+
769+ zstring show() const;
770+
771+ bool
772+ isAncestor(const store::Item_t&) const;
773+
774+ bool
775+ isFollowingSibling(const store::Item_t&) const;
776+
777+ bool
778+ isFollowing(const store::Item_t&) const;
779+
780+ bool
781+ isInSubtreeOf(const store::Item_t&) const;
782+
783+ bool
784+ isDescendant(const store::Item_t&) const;
785+
786+ bool
787+ isPrecedingSibling(const store::Item_t&) const;
788+
789+ bool
790+ isPreceding(const store::Item_t&) const;
791+
792+ bool
793+ isChild(const store::Item_t&) const;
794+
795+ bool
796+ isAttribute(const store::Item_t&) const;
797+
798+ bool
799+ isParent(const store::Item_t&) const;
800+
801+ bool
802+ isPrecedingInDocumentOrder(const store::Item_t&) const;
803+
804+ bool
805+ isFollowingInDocumentOrder(const store::Item_t&) const;
806+
807+ store::Item_t
808+ getLevel() const;
809+
810+ bool
811+ isAttributeRef() const;
812+
813+ bool
814+ isCommentRef() const;
815+
816+ bool
817+ isDocumentRef() const;
818+
819+ bool
820+ isElementRef() const;
821+
822+ bool
823+ isProcessingInstructionRef() const;
824+
825+ bool
826+ isTextRef() const;
827+
828+ bool
829+ isSibling(const store::Item_t&) const;
830+
831+ bool
832+ inSameTree(const store::Item_t&) const;
833+
834+ bool
835+ inCollection() const;
836+
837+ bool
838+ inSameCollection(const store::Item_t&) const;
839+
840+private:
841+ // Forces computation of the value.
842+ void encode() const;
843+
844+protected:
845+ friend class BasicItemFactory;
846
847 StructuralAnyUriItem(zstring& value);
848
849 StructuralAnyUriItem(
850- zstring& value,
851 ulong collectionId,
852 const TreeId& treeId,
853 store::StoreConsts::NodeKind nodeKind,
854 const OrdPath& ordPath);
855
856- StructuralAnyUriItem() {}
857-
858-public:
859- bool
860- isAncestor(const store::Item_t&) const;
861-
862- bool
863- isFollowingSibling(const store::Item_t&) const;
864-
865- bool
866- isFollowing(const store::Item_t&) const;
867-
868- bool
869- isInSubtreeOf(const store::Item_t&) const;
870-
871- bool
872- isDescendant(const store::Item_t&) const;
873-
874- bool
875- isPrecedingSibling(const store::Item_t&) const;
876-
877- bool
878- isPreceding(const store::Item_t&) const;
879-
880- bool
881- isChild(const store::Item_t&) const;
882-
883- bool
884- isAttribute(const store::Item_t&) const;
885-
886- bool
887- isParent(const store::Item_t&) const;
888-
889- bool
890- isPrecedingInDocumentOrder(const store::Item_t&) const;
891-
892- bool
893- isFollowingInDocumentOrder(const store::Item_t&) const;
894-
895- store::Item_t
896- getLevel() const;
897-
898- bool
899- isAttributeRef() const;
900-
901- bool
902- isCommentRef() const;
903-
904- bool
905- isDocumentRef() const;
906-
907- bool
908- isElementRef() const;
909-
910- bool
911- isProcessingInstructionRef() const;
912-
913- bool
914- isTextRef() const;
915-
916- bool
917- isSibling(const store::Item_t&) const;
918-
919- bool
920- inSameTree(const store::Item_t&) const;
921-
922- bool
923- inCollection() const;
924-
925- bool
926- inSameCollection(const store::Item_t&) const;
927+ StructuralAnyUriItem() : theEncodedValue("") {}
928 };
929
930
931
932=== modified file 'src/store/naive/item.cpp'
933--- src/store/naive/item.cpp 2012-08-16 18:31:02 +0000
934+++ src/store/naive/item.cpp 2012-08-27 09:01:20 +0000
935@@ -352,10 +352,8 @@
936
937 uint32_t Item::hash(long timezone, const XQPCollator* coll) const
938 {
939- throw ZORBA_EXCEPTION(
940- zerr::ZSTR0040_TYPE_ERROR,
941- ERROR_PARAMS( ZED( NoHashItemOfType_2 ), getType()->getStringValue() )
942- );
943+ throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR,
944+ ERROR_PARAMS(ZED(NoHashItemOfType_2), getType()->getStringValue()));
945 };
946
947
948@@ -364,13 +362,10 @@
949 long timezone,
950 const XQPCollator* aCollation) const
951 {
952- throw ZORBA_EXCEPTION(
953- zerr::ZSTR0040_TYPE_ERROR,
954- ERROR_PARAMS(
955- ZED( NoCompareTypes_23 ),
956- getType()->getStringValue(), other->getType()->getStringValue()
957- )
958- );
959+ throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR,
960+ ERROR_PARAMS(ZED(NoCompareTypes_23),
961+ getType()->getStringValue(),
962+ other->getType()->getStringValue()));
963 }
964
965
966@@ -379,13 +374,10 @@
967 long timezone,
968 const XQPCollator* aCollation) const
969 {
970- throw ZORBA_EXCEPTION(
971- zerr::ZSTR0040_TYPE_ERROR,
972- ERROR_PARAMS(
973- ZED( NoCompareTypes_23 ),
974- getType()->getStringValue(), other->getType()->getStringValue()
975- )
976- );
977+ throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR,
978+ ERROR_PARAMS(ZED(NoCompareTypes_23),
979+ getType()->getStringValue(),
980+ other->getType()->getStringValue()));
981 }
982
983
984
985=== modified file 'src/store/naive/simple_item_factory.cpp'
986--- src/store/naive/simple_item_factory.cpp 2012-08-16 18:31:02 +0000
987+++ src/store/naive/simple_item_factory.cpp 2012-08-27 09:01:20 +0000
988@@ -119,7 +119,9 @@
989 }
990
991
992-bool BasicItemFactory::createStructuralAnyURI(store::Item_t& result, zstring& value)
993+bool BasicItemFactory::createStructuralAnyURI(
994+ store::Item_t& result,
995+ zstring& value)
996 {
997 result = new StructuralAnyUriItem(value);
998 return true;
999@@ -134,16 +136,7 @@
1000 const OrdPath& ordPath)
1001 {
1002 ZORBA_FATAL(nodeKind,"Unexpected node kind");
1003- std::ostringstream stream;
1004- stream << "zorba:"
1005- << collectionId << "."
1006- << treeId << "."
1007- << static_cast<int>(nodeKind) << "."
1008- << ordPath.serialize();
1009- zstring uri = stream.str();
1010-
1011- theUriPool->insert(uri);
1012- result = new StructuralAnyUriItem(uri, collectionId, treeId, nodeKind, ordPath);
1013+ result = new StructuralAnyUriItem(collectionId, treeId, nodeKind, ordPath);
1014 return true;
1015 }
1016

Subscribers

People subscribed via source and target branches