Merge lp:~zorba-coders/zorba/bug-867059 into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 10516
Merged at revision: 10689
Proposed branch: lp:~zorba-coders/zorba/bug-867059
Merge into: lp:zorba
Diff against target: 3551 lines (+1457/-679)
39 files modified
ChangeLog (+1/-0)
doc/zorba/build.dox (+2/-1)
doc/zorba/build_options.dox (+35/-0)
src/api/itemfactoryimpl.cpp (+6/-6)
src/common/shared_types.h (+10/-4)
src/compiler/rewriter/rules/flwor_rules.cpp (+1/-1)
src/compiler/rewriter/rules/fold_rules.cpp (+1/-1)
src/compiler/translator/translator.cpp (+3/-3)
src/runtime/booleans/BooleanImpl.cpp (+2/-2)
src/runtime/core/flwor_iterator.cpp (+1/-1)
src/runtime/core/gflwor/count_iterator.cpp (+1/-1)
src/runtime/core/gflwor/for_iterator.cpp (+1/-1)
src/runtime/numerics/NumericsImpl.cpp (+2/-1)
src/store/api/item.h (+1/-1)
src/store/api/item_factory.h (+2/-2)
src/store/naive/atomic_items.cpp (+186/-27)
src/store/naive/atomic_items.h (+111/-39)
src/store/naive/item.cpp (+1/-1)
src/store/naive/simple_item_factory.cpp (+6/-6)
src/store/naive/simple_item_factory.h (+2/-2)
src/types/casting.cpp (+257/-46)
src/types/casting.h (+2/-2)
src/types/schema/XercesParseUtils.cpp (+2/-2)
src/util/stl_util.h (+31/-0)
src/util/string_util.cpp (+13/-5)
src/zorbaserialization/zorba_class_serializer.cpp (+12/-3)
src/zorbaserialization/zorba_class_serializer.h (+11/-2)
src/zorbatypes/decimal.cpp (+80/-47)
src/zorbatypes/decimal.h (+68/-48)
src/zorbatypes/floatimpl.cpp (+20/-1)
src/zorbatypes/floatimpl.h (+19/-4)
src/zorbatypes/integer.cpp (+144/-96)
src/zorbatypes/integer.h (+369/-308)
src/zorbatypes/numconversions.cpp (+8/-1)
src/zorbatypes/numconversions.h (+4/-0)
src/zorbatypes/schema_types.h (+5/-1)
src/zorbatypes/zorbatypes_decl.h (+13/-1)
test/rbkt/Queries/CMakeLists.txt (+13/-11)
test/rbkt/Queries/w3c_known_failures.txt (+11/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-867059
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Matthias Brantner Approve
Review via email: mp+83717@code.launchpad.net

This proposal supersedes a proposal from 2011-10-31.

Commit message

Better implementation of ZORBA_WITH_BIG_INTEGER=OFF: now limited to 63 bits (for a 64-bit implementation of a long long). Also added build_options.dox.

Description of the change

Better implementation of ZORBA_WITH_BIG_INTEGER=OFF: now limited to 63 bits (for a 64-bit implementation of a long long). Also added build_options.dox.

To post a comment you must log in.
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

The attempt to merge lp:~zorba-coders/zorba/bug-867059 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:272 (message):
  Validation queue job bug-867059-2011-10-31T23-16-07.098Z is finished. The
  final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

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

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in test/rbkt/Queries/CMakeLists.txt

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 bug-867059-2011-11-29T00-45-15.245Z 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
Matthias Brantner (matthias-brantner) wrote :

The change log should mention that the corresponding bug is fixed with this change.

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

> The change log should mention that the corresponding bug is fixed with this
> change.

It does now.

lp:~zorba-coders/zorba/bug-867059 updated
10515. By Paul J. Lucas

Merge from trunk.

10516. By Paul J. Lucas

Merge from trunk.

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 bug-867059-2012-02-29T16-42-56.599Z 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 'ChangeLog'
2--- ChangeLog 2012-02-27 15:17:53 +0000
3+++ ChangeLog 2012-02-28 18:23:19 +0000
4@@ -11,6 +11,7 @@
5 * Caching of results for recursive functions with atomic parameter and return types.
6 * Added %ann:cache and %ann:no-cache to enable or disable caching of results of functions with atomic parameter and return types.
7 * Fixed bug 917923 (bug in copying outer var values into the eval dynamic context)
8+ * Fixed bug 867509 (Can not handle largest xs:unsignedLong values)
9 * Fixed bug 924063 (sentence is incorrectly incremented when token characters end without sentence terminator)
10 * Optimization: change the implementation of the free-vars annotation and got rid
11 of the annotations map in expressions.
12
13=== modified file 'doc/zorba/build.dox'
14--- doc/zorba/build.dox 2012-01-26 10:08:12 +0000
15+++ doc/zorba/build.dox 2012-02-28 18:23:19 +0000
16@@ -116,7 +116,8 @@
17 To change the build mode (to Debug, Release, RelWithDebInfo or MinSizeRel),
18 you can pass an additional parameter to CMake, e.g.,
19 <tt>cmake -D CMAKE_BUILD_TYPE=Debug [ZORBA]</tt>.
20-- Zorba has other options as well.
21+- Zorba has other build options as well
22+ (see \ref build_options).
23 You can tweak the performance and library footprint
24 by enabling or disabling various features from Zorba.
25
26
27=== added file 'doc/zorba/build_options.dox'
28--- doc/zorba/build_options.dox 1970-01-01 00:00:00 +0000
29+++ doc/zorba/build_options.dox 2012-02-28 18:23:19 +0000
30@@ -0,0 +1,35 @@
31+/** \page build_options Zorba Build Options
32+
33+\section ZORBA_WITH_BIG_INTEGER Big Integer Support (ZORBA_WITH_BIG_INTEGER)
34+
35+The Zorba XQuery processor
36+by default
37+has arbitrary precision
38+for the \c xs:integer type.
39+Compared to a C++ \c int,
40+however,
41+arbitrary precision integers
42+are orders of magnitude slower.
43+If arbitrary precision integers are not needed,
44+they can be disabled
45+by configuring Zorba
46+with the
47+\c ZORBA_WITH_BIG_INTEGER
48+option set to \c OFF.
49+
50+When arbitrary precision integers are disabled,
51+Zorba uses a C++ <code>long long</code>
52+for \c xs:integer,
53+the precision for which
54+is dependent on your C++ implementation.
55+Typically, however,
56+the precision is at least 64 bits.
57+However,
58+in order to maintain the condition
59+that the value space for \c xs:nonNegativeInteger
60+is a subset of that of \c xs:integer,
61+one less bit is allowed
62+for \c xs:nonNegativeInteger.
63+
64+*/
65+/* vim:set et sw=2 ts=2: */
66
67=== modified file 'src/api/itemfactoryimpl.cpp'
68--- src/api/itemfactoryimpl.cpp 2012-02-22 01:31:08 +0000
69+++ src/api/itemfactoryimpl.cpp 2012-02-28 18:23:19 +0000
70@@ -288,7 +288,7 @@
71 ItemFactoryImpl::createInteger(long long aInteger)
72 {
73 store::Item_t lItem;
74- Integer const lInteger(aInteger);
75+ xs_integer const lInteger(aInteger);
76 theItemFactory->createInteger(lItem, lInteger);
77 return &*lItem;
78 }
79@@ -300,7 +300,7 @@
80 zstring const &lString = Unmarshaller::getInternalString( aInteger );
81 store::Item_t lItem;
82 try {
83- Integer const lInteger( lString.c_str() );
84+ xs_integer const lInteger( lString.c_str() );
85 theItemFactory->createInteger(lItem, lInteger);
86 }
87 catch ( std::exception const& ) {
88@@ -497,7 +497,7 @@
89 {
90 store::Item_t lItem;
91 if (aValue < 0) {
92- Integer const lInteger(aValue);
93+ xs_integer const lInteger(aValue);
94 theItemFactory->createNegativeInteger(lItem, lInteger);
95 }
96 return &*lItem;
97@@ -507,7 +507,7 @@
98 Item ItemFactoryImpl::createNonNegativeInteger ( unsigned long long aValue )
99 {
100 store::Item_t lItem;
101- Integer lInteger(aValue);
102+ xs_nonNegativeInteger lInteger(aValue);
103 theItemFactory->createNonNegativeInteger(lItem, lInteger);
104 return &*lItem;
105 }
106@@ -517,7 +517,7 @@
107 {
108 store::Item_t lItem;
109 if (aValue < 0) {
110- Integer const lInteger(aValue);
111+ xs_integer const lInteger(aValue);
112 theItemFactory->createNonPositiveInteger(lItem, lInteger);
113 }
114 return &*lItem;
115@@ -527,7 +527,7 @@
116 Item ItemFactoryImpl::createPositiveInteger ( unsigned long long aValue )
117 {
118 store::Item_t lItem;
119- Integer lInteger(aValue);
120+ xs_nonNegativeInteger lInteger(aValue);
121 theItemFactory->createPositiveInteger(lItem, lInteger);
122 return &*lItem;
123 }
124
125=== modified file 'src/common/shared_types.h'
126--- src/common/shared_types.h 2011-09-12 22:42:28 +0000
127+++ src/common/shared_types.h 2012-02-28 18:23:19 +0000
128@@ -140,12 +140,18 @@
129 typedef rchandle<GMonth> GMonth_t;
130
131 /* numerics */
132-template <class Object> class FloatImpl;
133-class Integer;
134-
135-/* numerics */
136+template<typename FloatType> class FloatImpl;
137 typedef FloatImpl<double> Double;
138 typedef FloatImpl<float> Float;
139+#ifdef ZORBA_WITH_BIG_INTEGER
140+class IntegerImpl;
141+typedef IntegerImpl Integer;
142+typedef IntegerImpl UInteger;
143+#else
144+template<typename IntType> class IntegerImpl;
145+typedef IntegerImpl<long long> Integer;
146+typedef IntegerImpl<unsigned long long> UInteger;
147+#endif /* ZORBA_WITH_BIG_INTEGER */
148
149 /* api */
150 class serializer;
151
152=== modified file 'src/compiler/rewriter/rules/flwor_rules.cpp'
153--- src/compiler/rewriter/rules/flwor_rules.cpp 2012-02-16 12:48:17 +0000
154+++ src/compiler/rewriter/rules/flwor_rules.cpp 2012-02-28 18:23:19 +0000
155@@ -953,7 +953,7 @@
156 (a) op is eq or =, and
157 (b1) posExpr is an integer literal with value >= 1, or
158 (b2) the flwor expr has no sequential clauses and posExpr is an expression
159- whose type is xs:Integer? and which does not reference the for var
160+ whose type is xs:integer? and which does not reference the for var
161 associated with posVar nor any other vars that are defined after that
162 for var.
163
164
165=== modified file 'src/compiler/rewriter/rules/fold_rules.cpp'
166--- src/compiler/rewriter/rules/fold_rules.cpp 2012-02-16 12:48:17 +0000
167+++ src/compiler/rewriter/rules/fold_rules.cpp 2012-02-28 18:23:19 +0000
168@@ -753,7 +753,7 @@
169 {
170 return new const_expr(fo->get_sctx(),
171 fo->get_loc(),
172- Integer(type_cnt));
173+ xs_integer(type_cnt));
174 }
175 else if (fkind == FunctionConsts::FN_EMPTY_1)
176 {
177
178=== modified file 'src/compiler/translator/translator.cpp'
179--- src/compiler/translator/translator.cpp 2012-02-19 19:43:28 +0000
180+++ src/compiler/translator/translator.cpp 2012-02-28 18:23:19 +0000
181@@ -9738,8 +9738,8 @@
182 {
183 case FunctionConsts::FN_HEAD_1:
184 {
185- arguments.push_back(new const_expr(theRootSctx, loc, Integer(1)));
186- arguments.push_back(new const_expr(theRootSctx, loc, Integer(1)));
187+ arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1)));
188+ arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(1)));
189 function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3);
190 fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
191 normalize_fo(foExpr);
192@@ -9748,7 +9748,7 @@
193 }
194 case FunctionConsts::FN_TAIL_1:
195 {
196- arguments.push_back(new const_expr(theRootSctx, loc, Integer(2)));
197+ arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(2)));
198 function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_2);
199 fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
200 normalize_fo(foExpr);
201
202=== modified file 'src/runtime/booleans/BooleanImpl.cpp'
203--- src/runtime/booleans/BooleanImpl.cpp 2012-01-26 19:56:14 +0000
204+++ src/runtime/booleans/BooleanImpl.cpp 2012-02-28 18:23:19 +0000
205@@ -845,7 +845,7 @@
206 {
207 // There are 2 cases when two types are comparable without one being a
208 // subtype of the other: (a) they belong to different branches under of
209- // the type-inheritance subtree rooted at xs:Integer, (b) they belong to
210+ // the type-inheritance subtree rooted at xs:integer, (b) they belong to
211 // different branches under of the type-inheritance subtree rooted at
212 // xs::duration (i.e. one is xs:yearMonthDuration and the other is
213 // xs:dayTimeDuration).
214@@ -935,7 +935,7 @@
215 {
216 // There is 1 case when two types are order-comparable without one being a
217 // subtype of the other: they belong to different branches under of the
218- // type-inheritance subtree rooted at xs:Integer.
219+ // type-inheritance subtree rooted at xs:integer.
220 if (TypeOps::is_subtype(type0, store::XS_INTEGER) &&
221 TypeOps::is_subtype(type1, store::XS_INTEGER))
222 {
223
224=== modified file 'src/runtime/core/flwor_iterator.cpp'
225--- src/runtime/core/flwor_iterator.cpp 2012-02-27 14:46:27 +0000
226+++ src/runtime/core/flwor_iterator.cpp 2012-02-28 18:23:19 +0000
227@@ -1216,7 +1216,7 @@
228 if (!flc.thePosVarRefs.empty())
229 {
230 store::Item_t posItem;
231- GENV_ITEMFACTORY->createInteger(posItem, Integer(bindingState));
232+ GENV_ITEMFACTORY->createInteger(posItem, xs_integer(bindingState));
233
234 std::vector<PlanIter_t>::const_iterator viter = flc.thePosVarRefs.begin();
235 std::vector<PlanIter_t>::const_iterator end = flc.thePosVarRefs.end();
236
237=== modified file 'src/runtime/core/gflwor/count_iterator.cpp'
238--- src/runtime/core/gflwor/count_iterator.cpp 2011-06-14 17:26:33 +0000
239+++ src/runtime/core/gflwor/count_iterator.cpp 2012-02-28 18:23:19 +0000
240@@ -91,7 +91,7 @@
241 {
242 {
243 store::Item_t lCountItem;
244- GENV_ITEMFACTORY->createInteger(lCountItem, Integer(lState->incCount()));
245+ GENV_ITEMFACTORY->createInteger(lCountItem, xs_integer(lState->incCount()));
246 bindVariables(lCountItem, theCountVars, aPlanState);
247 }
248 STACK_PUSH(true, lState);
249
250=== modified file 'src/runtime/core/gflwor/for_iterator.cpp'
251--- src/runtime/core/gflwor/for_iterator.cpp 2011-06-22 14:42:38 +0000
252+++ src/runtime/core/gflwor/for_iterator.cpp 2012-02-28 18:23:19 +0000
253@@ -126,7 +126,7 @@
254 {
255 store::Item_t lPosItem;
256 GENV_ITEMFACTORY->createInteger(lPosItem,
257- Integer(lState->incReturnPosition()));
258+ xs_integer(lState->incReturnPosition()));
259 bindVariables(lPosItem, thePosVarRefs, aPlanState);
260 }
261 STACK_PUSH(true, lState);
262
263=== modified file 'src/runtime/numerics/NumericsImpl.cpp'
264--- src/runtime/numerics/NumericsImpl.cpp 2012-01-30 16:59:01 +0000
265+++ src/runtime/numerics/NumericsImpl.cpp 2012-02-28 18:23:19 +0000
266@@ -442,10 +442,11 @@
267 xs_integer ll0 = i0->getIntegerValue();
268 xs_integer ll1 = i1->getIntegerValue();
269
270- if ( ll1 == Integer::zero() )
271+ if ( ll1.sign() == 0 )
272 {
273 throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
274 }
275+
276 return GENV_ITEMFACTORY->createInteger (result, ll0 / ll1);
277 }
278
279
280=== modified file 'src/store/api/item.h'
281--- src/store/api/item.h 2012-02-22 04:03:16 +0000
282+++ src/store/api/item.h 2012-02-28 18:23:19 +0000
283@@ -311,7 +311,7 @@
284
285 /** Accessor for xs:nonNegativeInteager, xs:positiveInteger
286 */
287- virtual xs_uinteger
288+ virtual xs_nonNegativeInteger
289 getUnsignedIntegerValue() const;
290
291 /** Accessor for xs:long
292
293=== modified file 'src/store/api/item_factory.h'
294--- src/store/api/item_factory.h 2012-02-22 01:31:08 +0000
295+++ src/store/api/item_factory.h 2012-02-28 18:23:19 +0000
296@@ -261,13 +261,13 @@
297 * Specification: [http://www.w3.org/TR/xmlschema-2/#nonNegativeInteger]
298 * @param value
299 */
300- virtual bool createNonNegativeInteger(Item_t& result, const xs_uinteger& value) = 0;
301+ virtual bool createNonNegativeInteger(Item_t& result, const xs_nonNegativeInteger& value) = 0;
302
303 /**
304 * Specification: [http://www.w3.org/TR/xmlschema-2/#positiveInteger]
305 * @param value
306 */
307- virtual bool createPositiveInteger(Item_t& result, const xs_uinteger& value) = 0;
308+ virtual bool createPositiveInteger(Item_t& result, const xs_positiveInteger& value) = 0;
309
310 /**
311 * Specification: [http://www.w3.org/TR/xmlschema-2/#nonPositiveInteger]
312
313=== modified file 'src/store/naive/atomic_items.cpp'
314--- src/store/naive/atomic_items.cpp 2012-02-24 03:57:49 +0000
315+++ src/store/naive/atomic_items.cpp 2012-02-28 18:23:19 +0000
316@@ -137,7 +137,7 @@
317 const IntegerItem* item = static_cast<const IntegerItem*>(item1);
318 try
319 {
320- longValue = to_xs_long(item->theValue);
321+ longValue = item->getLongValue();
322 GET_FACTORY().createLong(result, longValue);
323 }
324 catch (std::range_error const&)
325@@ -207,11 +207,11 @@
326 {
327 const IntegerItem* item = static_cast<const IntegerItem*>(item1);
328
329- doubleValue = item->theValue;
330+ doubleValue = item->getIntegerValue();
331
332 const xs_integer intValue(doubleValue);
333
334- lossy = (intValue != item->theValue);
335+ lossy = (intValue != item->getIntegerValue());
336 break;
337 }
338
339@@ -2350,10 +2350,11 @@
340
341
342 /*******************************************************************************
343- class IntegerItem
344+ class IntegerItemImpl
345 ********************************************************************************/
346
347-long IntegerItem::compare( Item const *other, long, const XQPCollator* ) const {
348+long IntegerItemImpl::compare( Item const *other, long,
349+ const XQPCollator* ) const {
350 try
351 {
352 return theValue.compare( other->getIntegerValue() );
353@@ -2364,8 +2365,8 @@
354 }
355 }
356
357-bool IntegerItem::equals( const store::Item* other, long,
358- const XQPCollator*) const
359+bool IntegerItemImpl::equals( const store::Item* other, long,
360+ const XQPCollator*) const
361 {
362 try
363 {
364@@ -2377,13 +2378,13 @@
365 }
366 }
367
368-xs_decimal IntegerItem::getDecimalValue() const
369+xs_decimal IntegerItemImpl::getDecimalValue() const
370 {
371 return xs_decimal(theValue);
372 }
373
374
375-xs_long IntegerItem::getLongValue() const
376+xs_long IntegerItemImpl::getLongValue() const
377 {
378 try
379 {
380@@ -2397,41 +2398,42 @@
381 }
382
383
384-store::Item* IntegerItem::getType() const
385+store::Item* IntegerItemImpl::getType() const
386 {
387 return GET_STORE().theSchemaTypeNames[store::XS_INTEGER];
388 }
389
390
391-bool IntegerItem::getEBV() const
392+bool IntegerItemImpl::getEBV() const
393 {
394- return ( theValue != xs_integer::zero() );
395+ return !!theValue.sign();
396 }
397
398
399-zstring IntegerItem::getStringValue() const
400+zstring IntegerItemImpl::getStringValue() const
401 {
402 return theValue.toString();
403 }
404
405
406-void IntegerItem::getStringValue2(zstring& val) const
407+void IntegerItemImpl::getStringValue2(zstring& val) const
408 {
409 val = theValue.toString();
410 }
411
412-uint32_t IntegerItem::hash(long, const XQPCollator*) const
413+uint32_t IntegerItemImpl::hash(long, const XQPCollator*) const
414 {
415 return theValue.hash();
416 }
417
418-void IntegerItem::appendStringValue(zstring& buf) const
419+
420+void IntegerItemImpl::appendStringValue(zstring& buf) const
421 {
422 buf += theValue.toString();
423 }
424
425
426-zstring IntegerItem::show() const
427+zstring IntegerItemImpl::show() const
428 {
429 zstring res("xs:integer(");
430 appendStringValue(res);
431@@ -2443,11 +2445,88 @@
432 /*******************************************************************************
433 class NonPositiveIntegerItem
434 ********************************************************************************/
435+long NonPositiveIntegerItem::compare( Item const *other, long,
436+ const XQPCollator* ) const {
437+ try
438+ {
439+ return theValue.compare( other->getIntegerValue() );
440+ }
441+ catch ( ZorbaException const& )
442+ {
443+ return getDecimalValue().compare( other->getDecimalValue() );
444+ }
445+}
446+
447+bool NonPositiveIntegerItem::equals( const store::Item* other, long,
448+ const XQPCollator* ) const
449+{
450+ try
451+ {
452+ return theValue == other->getIntegerValue();
453+ }
454+ catch (ZorbaException const&)
455+ {
456+ return getDecimalValue() == other->getDecimalValue();
457+ }
458+}
459+
460 store::Item* NonPositiveIntegerItem::getType() const
461 {
462 return GET_STORE().theSchemaTypeNames[store::XS_NON_POSITIVE_INTEGER];
463 }
464
465+xs_decimal NonPositiveIntegerItem::getDecimalValue() const
466+{
467+ return xs_decimal(theValue);
468+}
469+
470+xs_integer NonPositiveIntegerItem::getIntegerValue() const
471+{
472+ return xs_integer(theValue);
473+}
474+
475+xs_long NonPositiveIntegerItem::getLongValue() const
476+{
477+ try
478+ {
479+ return to_xs_long(theValue);
480+ }
481+ catch ( std::range_error const& )
482+ {
483+ throw XQUERY_EXCEPTION(
484+ err::FORG0001,
485+ ERROR_PARAMS( theValue, ZED( CastFromToFailed_34 ), "integer", "long" )
486+ );
487+ }
488+}
489+
490+zstring NonPositiveIntegerItem::getStringValue() const
491+{
492+ return theValue.toString();
493+}
494+
495+
496+void NonPositiveIntegerItem::getStringValue2(zstring& val) const
497+{
498+ val = theValue.toString();
499+}
500+
501+uint32_t NonPositiveIntegerItem::hash(long, const XQPCollator*) const
502+{
503+ return theValue.hash();
504+}
505+
506+
507+void NonPositiveIntegerItem::appendStringValue(zstring& buf) const
508+{
509+ buf += theValue.toString();
510+}
511+
512+bool NonPositiveIntegerItem::getEBV() const
513+{
514+ return !!theValue.sign();
515+}
516+
517 zstring NonPositiveIntegerItem::show() const
518 {
519 zstring res("xs:nonPositiveInteger(");
520@@ -2476,14 +2555,91 @@
521
522
523 /*******************************************************************************
524- class NonNegativeINtegerItem
525+ class NonNegativeIntegerItem
526 ********************************************************************************/
527+long NonNegativeIntegerItem::compare( Item const *other, long,
528+ const XQPCollator* ) const {
529+ try
530+ {
531+ return theValue.compare( other->getUnsignedIntegerValue() );
532+ }
533+ catch ( ZorbaException const& )
534+ {
535+ return getDecimalValue().compare( other->getDecimalValue() );
536+ }
537+}
538+
539+bool NonNegativeIntegerItem::equals( const store::Item* other, long,
540+ const XQPCollator* ) const
541+{
542+ try
543+ {
544+ return theValue == other->getUnsignedIntegerValue();
545+ }
546+ catch (ZorbaException const&)
547+ {
548+ return getDecimalValue() == other->getDecimalValue();
549+ }
550+}
551+
552 store::Item* NonNegativeIntegerItem::getType() const
553 {
554 return GET_STORE().theSchemaTypeNames[store::XS_NON_NEGATIVE_INTEGER];
555 }
556
557
558+xs_decimal NonNegativeIntegerItem::getDecimalValue() const
559+{
560+ return xs_decimal(theValue);
561+}
562+
563+xs_integer NonNegativeIntegerItem::getIntegerValue() const
564+{
565+ return xs_integer(theValue);
566+}
567+
568+xs_long NonNegativeIntegerItem::getLongValue() const
569+{
570+ try
571+ {
572+ return to_xs_long(theValue);
573+ }
574+ catch ( std::range_error const& )
575+ {
576+ throw XQUERY_EXCEPTION(
577+ err::FORG0001,
578+ ERROR_PARAMS( theValue, ZED( CastFromToFailed_34 ), "integer", "long" )
579+ );
580+ }
581+}
582+
583+zstring NonNegativeIntegerItem::getStringValue() const
584+{
585+ return theValue.toString();
586+}
587+
588+
589+void NonNegativeIntegerItem::getStringValue2(zstring& val) const
590+{
591+ val = theValue.toString();
592+}
593+
594+uint32_t NonNegativeIntegerItem::hash(long, const XQPCollator*) const
595+{
596+ return theValue.hash();
597+}
598+
599+
600+void NonNegativeIntegerItem::appendStringValue(zstring& buf) const
601+{
602+ buf += theValue.toString();
603+}
604+
605+bool NonNegativeIntegerItem::getEBV() const
606+{
607+ return !!theValue.sign();
608+}
609+
610 zstring NonNegativeIntegerItem::show() const
611 {
612 zstring res("xs:nonNegativeInteger(");
613@@ -2525,6 +2681,9 @@
614 return xs_integer(theValue);
615 }
616
617+xs_nonNegativeInteger LongItem::getUnsignedIntegerValue() const {
618+ return theValue >= 0 ? theValue : -theValue;
619+}
620
621 store::Item* LongItem::getType() const
622 {
623@@ -2758,9 +2917,9 @@
624 }
625
626
627-xs_uinteger UnsignedLongItem::getUnsignedIntegerValue() const
628+xs_nonNegativeInteger UnsignedLongItem::getUnsignedIntegerValue() const
629 {
630- return xs_uinteger(theValue);
631+ return xs_nonNegativeInteger(theValue);
632 }
633
634
635@@ -2822,9 +2981,9 @@
636 }
637
638
639-xs_uinteger UnsignedIntItem::getUnsignedIntegerValue() const
640+xs_nonNegativeInteger UnsignedIntItem::getUnsignedIntegerValue() const
641 {
642- return Integer(theValue);
643+ return xs_nonNegativeInteger(theValue);
644 }
645
646
647@@ -2886,9 +3045,9 @@
648 }
649
650
651-xs_uinteger UnsignedShortItem::getUnsignedIntegerValue() const
652+xs_nonNegativeInteger UnsignedShortItem::getUnsignedIntegerValue() const
653 {
654- return Integer(theValue);
655+ return xs_nonNegativeInteger(theValue);
656 }
657
658
659@@ -2946,13 +3105,13 @@
660
661 xs_integer UnsignedByteItem::getIntegerValue() const
662 {
663- return Integer((uint32_t)theValue);
664+ return xs_integer((uint32_t)theValue);
665 }
666
667
668-xs_uinteger UnsignedByteItem::getUnsignedIntegerValue() const
669+xs_nonNegativeInteger UnsignedByteItem::getUnsignedIntegerValue() const
670 {
671- return Integer(theValue);
672+ return xs_nonNegativeInteger(theValue);
673 }
674
675
676
677=== modified file 'src/store/naive/atomic_items.h'
678--- src/store/naive/atomic_items.h 2012-02-24 16:47:43 +0000
679+++ src/store/naive/atomic_items.h 2012-02-28 18:23:19 +0000
680@@ -171,7 +171,7 @@
681
682 xs_integer getIntegerValue() const { return theBaseItem->getIntegerValue(); }
683
684- xs_uinteger getUnsignedIntegerValue() const { return theBaseItem->getUnsignedIntegerValue(); }
685+ xs_nonNegativeInteger getUnsignedIntegerValue() const { return theBaseItem->getUnsignedIntegerValue(); }
686
687 xs_long getLongValue() const { return theBaseItem->getLongValue(); }
688
689@@ -1182,7 +1182,7 @@
690 return theValue.compare(other->getDoubleValue());
691 }
692
693- bool getEBV( ) const;
694+ bool getEBV() const;
695
696 zstring getStringValue() const;
697
698@@ -1339,6 +1339,31 @@
699 ********************************************************************************/
700 class IntegerItem : public AtomicItem
701 {
702+protected:
703+ IntegerItem() {}
704+
705+public:
706+ virtual xs_decimal getDecimalValue() const = 0;
707+ virtual xs_integer getIntegerValue() const = 0;
708+ virtual xs_long getLongValue() const = 0;
709+
710+ virtual bool getEBV() const = 0;
711+ virtual store::Item* getType() const = 0;
712+
713+ virtual zstring getStringValue() const = 0;
714+ virtual void getStringValue2(zstring&) const = 0;
715+ virtual void appendStringValue(zstring& buf) const = 0;
716+
717+ uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const = 0;
718+ bool isNaN() const { return false; }
719+};
720+
721+
722+/*******************************************************************************
723+ class IntegerItemImpl
724+********************************************************************************/
725+class IntegerItemImpl : public IntegerItem
726+{
727 friend class BasicItemFactory;
728 friend class AtomicItem;
729
730@@ -1346,40 +1371,37 @@
731 xs_integer theValue;
732
733 protected:
734- IntegerItem(const xs_integer& aValue) : theValue ( aValue ) {}
735+ IntegerItemImpl(const xs_integer& aValue) : theValue ( aValue ) {}
736
737- IntegerItem() {}
738+ IntegerItemImpl() {}
739
740 public:
741 xs_decimal getDecimalValue() const;
742-
743 xs_integer getIntegerValue() const { return theValue; }
744
745- xs_long getLongValue() const;
746+ xs_long getLongValue() const;
747+ xs_nonNegativeInteger getUnsignedIntegerValue() const { return theValue; }
748+
749+ zstring getStringValue() const;
750+ void getStringValue2(zstring&) const;
751+ void appendStringValue(zstring&) const;
752
753 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_INTEGER; }
754
755 virtual store::Item* getType() const;
756-
757 uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const;
758
759+ long compare(
760+ const Item* other,
761+ long timezone = 0,
762+ const XQPCollator* aCollation = 0) const;
763+
764 bool equals(
765 const store::Item* other,
766 long timezone = 0,
767 const XQPCollator* aCollation = 0) const;
768
769- long compare(
770- const Item* other,
771- long timezone = 0,
772- const XQPCollator* aCollation = 0) const;
773-
774- bool getEBV( ) const;
775-
776- zstring getStringValue() const;
777-
778- void getStringValue2(zstring& val) const;
779-
780- void appendStringValue(zstring& buf) const;
781+ bool getEBV() const;
782
783 bool isNaN() const { return false; }
784
785@@ -1395,28 +1417,53 @@
786 friend class BasicItemFactory;
787
788 protected:
789- NonPositiveIntegerItem(const xs_integer& aValue) : IntegerItem(aValue) {}
790+ xs_nonPositiveInteger theValue;
791+
792+ NonPositiveIntegerItem(const xs_integer& aValue) : theValue(aValue) {}
793
794 NonPositiveIntegerItem() {}
795
796 public:
797+ // inherited
798+ xs_decimal getDecimalValue() const;
799+ xs_integer getIntegerValue() const;
800+ xs_long getLongValue() const;
801+ xs_nonNegativeInteger getUnsignedIntegerValue() const { return theValue; }
802+
803+ zstring getStringValue() const;
804+ void getStringValue2(zstring& val) const;
805+ void appendStringValue(zstring&) const;
806+
807+ bool getEBV() const;
808+
809 store::SchemaTypeCode getTypeCode() const { return store::XS_NON_POSITIVE_INTEGER; }
810
811 store::Item* getType() const;
812+ uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const;
813
814 zstring show() const;
815+
816+ long compare(
817+ const Item* other,
818+ long timezone = 0,
819+ const XQPCollator* aCollation = 0) const;
820+
821+ bool equals(
822+ const store::Item* other,
823+ long timezone = 0,
824+ const XQPCollator* aCollation = 0) const;
825 };
826
827
828 /*******************************************************************************
829 class NegativeIntegerItem
830 ********************************************************************************/
831-class NegativeIntegerItem : public IntegerItem
832+class NegativeIntegerItem : public NonPositiveIntegerItem
833 {
834 friend class BasicItemFactory;
835
836 protected:
837- NegativeIntegerItem(const xs_integer& aValue) : IntegerItem(aValue) {}
838+ NegativeIntegerItem(const xs_integer& aValue) : NonPositiveIntegerItem(aValue) {}
839
840 NegativeIntegerItem() {}
841
842@@ -1431,38 +1478,61 @@
843
844 /*******************************************************************************
845 class NonNegativeIntegerItem
846-
847- Note: xs_uinteger is typedef of Integer
848 ********************************************************************************/
849 class NonNegativeIntegerItem : public IntegerItem
850 {
851 friend class BasicItemFactory;
852
853 protected:
854- NonNegativeIntegerItem(const xs_uinteger& aValue) : IntegerItem(aValue) {}
855+ xs_nonNegativeInteger theValue;
856+
857+ NonNegativeIntegerItem(const xs_nonNegativeInteger& aValue) : theValue(aValue) {}
858
859 NonNegativeIntegerItem() {}
860
861 public:
862- xs_uinteger getUnsignedIntegerValue() const { return theValue; }
863+ // inherited
864+ xs_decimal getDecimalValue() const;
865+ xs_integer getIntegerValue() const;
866+ xs_long getLongValue() const;
867+ xs_nonNegativeInteger getUnsignedIntegerValue() const { return theValue; }
868+
869+ bool getEBV() const;
870
871 store::SchemaTypeCode getTypeCode() const { return store::XS_NON_NEGATIVE_INTEGER; }
872
873+
874 store::Item* getType() const;
875
876+ uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const;
877+
878 zstring show() const;
879+
880+ zstring getStringValue() const;
881+ void getStringValue2(zstring& val) const;
882+ void appendStringValue(zstring&) const;
883+
884+ long compare(
885+ const Item* other,
886+ long timezone = 0,
887+ const XQPCollator* aCollation = 0) const;
888+
889+ bool equals(
890+ const store::Item* other,
891+ long timezone = 0,
892+ const XQPCollator* aCollation = 0) const;
893 };
894
895
896 /*******************************************************************************
897 class PositiveIntegerItem
898 ********************************************************************************/
899-class PositiveIntegerItem : public IntegerItem
900+class PositiveIntegerItem : public NonNegativeIntegerItem
901 {
902 friend class BasicItemFactory;
903
904 protected:
905- PositiveIntegerItem(const xs_uinteger& aValue) : IntegerItem(aValue) { }
906+ PositiveIntegerItem(const xs_positiveInteger& aValue) : NonNegativeIntegerItem(aValue) { }
907
908 PositiveIntegerItem() {}
909
910@@ -1500,6 +1570,8 @@
911
912 xs_long getLongValue() const { return theValue; }
913
914+ xs_nonNegativeInteger getUnsignedIntegerValue() const;
915+
916 store::SchemaTypeCode getTypeCode() const { return store::XS_LONG; }
917
918 store::Item* getType() const;
919@@ -1541,7 +1613,7 @@
920 }
921 }
922
923- bool getEBV( ) const;
924+ bool getEBV() const;
925
926 zstring getStringValue() const;
927
928@@ -1703,7 +1775,7 @@
929 }
930 }
931
932- bool getEBV( ) const;
933+ bool getEBV() const;
934
935 zstring getStringValue() const;
936
937@@ -1787,7 +1859,7 @@
938 }
939 }
940
941- bool getEBV( ) const;
942+ bool getEBV() const;
943
944 zstring getStringValue() const;
945
946@@ -1824,7 +1896,7 @@
947
948 xs_integer getIntegerValue() const;
949
950- xs_uinteger getUnsignedIntegerValue() const;
951+ xs_nonNegativeInteger getUnsignedIntegerValue() const;
952
953 xs_unsignedLong getUnsignedLongValue() const { return theValue; }
954
955@@ -1869,7 +1941,7 @@
956 }
957 }
958
959- bool getEBV( ) const;
960+ bool getEBV() const;
961
962 zstring getStringValue() const;
963
964@@ -1904,7 +1976,7 @@
965
966 xs_integer getIntegerValue() const;
967
968- xs_uinteger getUnsignedIntegerValue() const;
969+ xs_nonNegativeInteger getUnsignedIntegerValue() const;
970
971 xs_long getLongValue() const { return static_cast<xs_long>(theValue); }
972
973@@ -1960,7 +2032,7 @@
974 }
975 }
976
977- bool getEBV( ) const;
978+ bool getEBV() const;
979
980 zstring getStringValue() const;
981
982@@ -1993,7 +2065,7 @@
983
984 xs_integer getIntegerValue() const;
985
986- xs_uinteger getUnsignedIntegerValue() const;
987+ xs_nonNegativeInteger getUnsignedIntegerValue() const;
988
989 xs_long getLongValue() const { return static_cast<xs_long>(theValue); }
990
991@@ -2053,7 +2125,7 @@
992 }
993 }
994
995- bool getEBV( ) const;
996+ bool getEBV() const;
997
998 zstring getStringValue() const;
999
1000@@ -2086,7 +2158,7 @@
1001
1002 xs_integer getIntegerValue() const;
1003
1004- xs_uinteger getUnsignedIntegerValue() const;
1005+ xs_nonNegativeInteger getUnsignedIntegerValue() const;
1006
1007 xs_long getLongValue() const { return static_cast<xs_long>(theValue); }
1008
1009@@ -2202,7 +2274,7 @@
1010 (theValue == false ? -1 : 1));
1011 }
1012
1013- bool getEBV( ) const;
1014+ bool getEBV() const;
1015
1016 zstring getStringValue() const;
1017
1018
1019=== modified file 'src/store/naive/item.cpp'
1020--- src/store/naive/item.cpp 2012-02-22 04:03:16 +0000
1021+++ src/store/naive/item.cpp 2012-02-28 18:23:19 +0000
1022@@ -570,7 +570,7 @@
1023 * Accessor for xs:unsignedLong, xs:unsignedInt, xs:unsignedShort,
1024 * xs:unsignedByte, xs:nonNegativeInteager, xs:positiveInteger
1025 */
1026-xs_uinteger Item::getUnsignedIntegerValue() const
1027+xs_nonNegativeInteger Item::getUnsignedIntegerValue() const
1028 {
1029 throw ZORBA_EXCEPTION(
1030 zerr::ZSTR0040_TYPE_ERROR,
1031
1032=== modified file 'src/store/naive/simple_item_factory.cpp'
1033--- src/store/naive/simple_item_factory.cpp 2012-02-22 01:31:08 +0000
1034+++ src/store/naive/simple_item_factory.cpp 2012-02-28 18:23:19 +0000
1035@@ -318,7 +318,7 @@
1036
1037 bool BasicItemFactory::createInteger(store::Item_t& result, const xs_integer& value)
1038 {
1039- result = new IntegerItem( value );
1040+ result = new IntegerItemImpl( value );
1041 return true;
1042 }
1043
1044@@ -327,7 +327,7 @@
1045 store::Item_t& result,
1046 const xs_integer& value)
1047 {
1048- ZORBA_ASSERT(value <= Integer::zero());
1049+ ZORBA_ASSERT(value.sign() <= 0);
1050 result = new NonPositiveIntegerItem( value );
1051 return true;
1052 }
1053@@ -337,7 +337,7 @@
1054 store::Item_t& result,
1055 const xs_integer& value)
1056 {
1057- ZORBA_ASSERT(value < xs_integer::zero());
1058+ ZORBA_ASSERT(value.sign() < 0);
1059 result = new NegativeIntegerItem(value);
1060 return true;
1061 }
1062@@ -345,7 +345,7 @@
1063
1064 bool BasicItemFactory::createNonNegativeInteger(
1065 store::Item_t& result,
1066- const xs_uinteger& value )
1067+ const xs_nonNegativeInteger& value )
1068 {
1069 result = new NonNegativeIntegerItem( value );
1070 return true;
1071@@ -355,9 +355,9 @@
1072
1073 bool BasicItemFactory::createPositiveInteger(
1074 store::Item_t& result,
1075- const xs_uinteger& value)
1076+ const xs_positiveInteger& value)
1077 {
1078- ZORBA_ASSERT(value > Integer::zero());
1079+ ZORBA_ASSERT(value.sign() > 0);
1080 result = new PositiveIntegerItem( value );
1081 return true;
1082 }
1083
1084=== modified file 'src/store/naive/simple_item_factory.h'
1085--- src/store/naive/simple_item_factory.h 2012-02-24 16:47:43 +0000
1086+++ src/store/naive/simple_item_factory.h 2012-02-28 18:23:19 +0000
1087@@ -131,9 +131,9 @@
1088
1089 bool createInteger(store::Item_t& result, const xs_integer& value);
1090
1091- bool createNonNegativeInteger(store::Item_t& result, const xs_uinteger& value);
1092+ bool createNonNegativeInteger(store::Item_t& result, const xs_nonNegativeInteger& value);
1093
1094- bool createPositiveInteger(store::Item_t& result, const xs_uinteger& value );
1095+ bool createPositiveInteger(store::Item_t& result, const xs_positiveInteger& value );
1096
1097 bool createNonPositiveInteger(store::Item_t& result, const xs_integer& value);
1098
1099
1100=== modified file 'src/types/casting.cpp'
1101--- src/types/casting.cpp 2012-02-22 04:03:16 +0000
1102+++ src/types/casting.cpp 2012-02-28 18:23:19 +0000
1103@@ -166,6 +166,7 @@
1104 SAME_S_AND_T(aURI)
1105 SAME_S_AND_T(QN)
1106 SAME_S_AND_T(NOT)
1107+SAME_S_AND_T(uint)
1108
1109 #undef SAME_S_AND_T
1110
1111@@ -1344,6 +1345,153 @@
1112 return uA_str(result, aItem, strval, aFactory, nsCtx, aErrorInfo);
1113 }
1114
1115+T1_TO_T2(uint, uA)
1116+{
1117+ zstring strval2;
1118+ aItem->getStringValue2(strval2);
1119+ return str_uA(result, aItem, strval2, aFactory, nsCtx, aErrorInfo);
1120+}
1121+
1122+
1123+T1_TO_T2(uint, str)
1124+{
1125+ return uA_str(result, aItem, strval, aFactory, nsCtx, aErrorInfo);
1126+}
1127+
1128+
1129+T1_TO_T2(uint, flt)
1130+{
1131+ return aFactory->createFloat(
1132+ result, xs_float(aItem->getUnsignedIntegerValue())
1133+ );
1134+}
1135+
1136+
1137+T1_TO_T2(uint, dbl)
1138+{
1139+ return aFactory->createDouble(
1140+ result, xs_double(aItem->getUnsignedIntegerValue())
1141+ );
1142+}
1143+
1144+
1145+T1_TO_T2(uint, dec)
1146+{
1147+ return aFactory->createDecimal(
1148+ result, xs_decimal(aItem->getUnsignedIntegerValue())
1149+ );
1150+}
1151+
1152+
1153+T1_TO_T2(uint, bool)
1154+{
1155+ aFactory->createBoolean(result, aItem->getEBV());
1156+ return true;
1157+}
1158+
1159+
1160+T1_TO_T2(uA, uint)
1161+{
1162+ zstring strval2;
1163+ aItem->getStringValue2(strval2);
1164+ return str_int(result, aItem, strval2, aFactory, nsCtx, aErrorInfo);
1165+}
1166+
1167+
1168+T1_TO_T2(flt, uint)
1169+{
1170+ try
1171+ {
1172+ xs_nonNegativeInteger const n(aItem->getFloatValue());
1173+ return aFactory->createNonNegativeInteger(result, n);
1174+ }
1175+ catch ( std::exception const& )
1176+ {
1177+ throwTypeException( err::FOCA0002, aErrorInfo );
1178+ return NULL;
1179+ }
1180+}
1181+
1182+
1183+T1_TO_T2(int, uint)
1184+{
1185+ try
1186+ {
1187+ xs_nonNegativeInteger const n(aItem->getIntegerValue());
1188+ return aFactory->createNonNegativeInteger(result, n);
1189+ }
1190+ catch ( std::exception const& )
1191+ {
1192+ throwTypeException( err::FOCA0002, aErrorInfo );
1193+ return NULL;
1194+ }
1195+}
1196+
1197+
1198+T1_TO_T2(uint, int)
1199+{
1200+ try
1201+ {
1202+ xs_integer const n(aItem->getIntegerValue());
1203+ return aFactory->createInteger(result, n);
1204+ }
1205+ catch ( std::exception const& )
1206+ {
1207+ throwTypeException( err::FOCA0002, aErrorInfo );
1208+ return NULL;
1209+ }
1210+}
1211+
1212+
1213+T1_TO_T2(dbl, uint)
1214+{
1215+ try
1216+ {
1217+ xs_nonNegativeInteger const n(aItem->getDoubleValue());
1218+ return aFactory->createInteger(result, n);
1219+ }
1220+ catch ( std::exception const& )
1221+ {
1222+ throwTypeException( err::FOCA0002, aErrorInfo );
1223+ return NULL;
1224+ }
1225+}
1226+
1227+
1228+T1_TO_T2(dec, uint)
1229+{
1230+ xs_nonNegativeInteger const n(aItem->getDecimalValue());
1231+ return aFactory->createNonNegativeInteger(result, n);
1232+}
1233+
1234+
1235+T1_TO_T2(bool, uint)
1236+{
1237+ if (aItem->getBooleanValue())
1238+ return aFactory->createNonNegativeInteger(
1239+ result, xs_nonNegativeInteger::one()
1240+ );
1241+ else
1242+ return aFactory->createNonNegativeInteger(
1243+ result, xs_nonNegativeInteger::zero()
1244+ );
1245+}
1246+
1247+
1248+T1_TO_T2(str, uint)
1249+{
1250+ try {
1251+ xs_nonNegativeInteger const n(strval.c_str());
1252+ return aFactory->createNonNegativeInteger(result, n);
1253+ }
1254+ catch ( std::invalid_argument const& ) {
1255+ throwTypeException( err::FORG0001, aErrorInfo );
1256+ }
1257+ catch ( std::range_error const& ) {
1258+ throwTypeException( err::FOCA0002, aErrorInfo );
1259+ }
1260+ return NULL;
1261+}
1262
1263 /*******************************************************************************
1264
1265@@ -1451,14 +1599,14 @@
1266 case store::XS_NON_POSITIVE_INTEGER:
1267 {
1268 xs_integer const lInteger = aItem->getIntegerValue();
1269- if (lInteger <= xs_integer::zero())
1270+ if (lInteger.sign() <= 0)
1271 return aFactory->createNonPositiveInteger(result, lInteger);
1272 break;
1273 }
1274 case store::XS_NEGATIVE_INTEGER:
1275 {
1276 xs_integer const lInteger = aItem->getIntegerValue();
1277- if (lInteger < xs_integer::zero())
1278+ if (lInteger.sign() < 0)
1279 return aFactory->createNegativeInteger(result, lInteger);
1280 break;
1281 }
1282@@ -1522,9 +1670,15 @@
1283 }
1284 case store::XS_NON_NEGATIVE_INTEGER:
1285 {
1286- xs_integer const lInteger = aItem->getIntegerValue();
1287- if (lInteger >= xs_integer::zero())
1288- return aFactory->createNonNegativeInteger(result, lInteger);
1289+ xs_decimal const d = aItem->getDecimalValue();
1290+ if (d.sign() >= 0)
1291+ try {
1292+ xs_nonNegativeInteger const i(d);
1293+ return aFactory->createNonNegativeInteger(result, i);
1294+ }
1295+ catch ( std::exception const& ) {
1296+ // ignore
1297+ }
1298 break;
1299 }
1300 case store::XS_UNSIGNED_LONG:
1301@@ -1587,9 +1741,9 @@
1302 }
1303 case store::XS_POSITIVE_INTEGER:
1304 {
1305- xs_integer lInteger = aItem->getIntegerValue();
1306- if (lInteger > xs_integer::zero())
1307- return aFactory->createPositiveInteger(result, lInteger);
1308+ xs_positiveInteger const i = aItem->getUnsignedIntegerValue();
1309+ if (i.sign() > 0)
1310+ return aFactory->createPositiveInteger(result, i);
1311 break;
1312 }
1313 default:
1314@@ -1634,12 +1788,12 @@
1315 5, // 25 XS_INT
1316 5, // 26 XS_SHORT
1317 5, // 27 XS_BYTE
1318- 5, // 28 XS_NON_NEGATIVE_INTEGER
1319- 5, // 29 XS_UNSIGNED_LONG
1320- 5, // 30 XS_UNSIGNED_INT
1321- 5, // 31 XS_UNSIGNED_SHORT
1322- 5, // 32 XS_UNSIGNED_BYTE
1323- 5, // 33 XS_POSITIVE_INTEGER
1324+ 23, // 28 XS_NON_NEGATIVE_INTEGER
1325+ 23, // 29 XS_UNSIGNED_LONG
1326+ 23, // 30 XS_UNSIGNED_INT
1327+ 23, // 31 XS_UNSIGNED_SHORT
1328+ 23, // 32 XS_UNSIGNED_BYTE
1329+ 23, // 33 XS_POSITIVE_INTEGER
1330 12, // 34 XS_GYEAR_MONTH
1331 13, // 35 XS_GYEAR
1332 14, // 36 XS_GMONTH_DAY
1333@@ -1657,98 +1811,155 @@
1334 /*******************************************************************************
1335
1336 ********************************************************************************/
1337-const GenericCast::DownCastFunc GenericCast::theDownCastMatrix[23] =
1338+const GenericCast::DownCastFunc GenericCast::theDownCastMatrix[24] =
1339 {
1340-/*uA*/ 0, /*str*/ str_down, /*flt*/ 0, /*dbl*/ 0, /*dec*/ 0, /*int*/ int_down, /*dur*/ 0,
1341-/*yMD*/ 0, /*dTD*/ 0, /*dT*/ 0, /*tim*/ 0, /*dat*/ 0, /*gYM*/ 0, /*gYr*/ 0, /*gMD*/ 0,
1342-/*gDay*/0, /*gMon*/0, /*bool*/0, /*b64*/ 0, /*hxB*/ 0, /*aURI*/0, /*QN*/ 0, /*NOT*/ 0
1343+/*uA*/ 0,
1344+/*str*/ str_down,
1345+/*flt*/ 0,
1346+/*dbl*/ 0,
1347+/*dec*/ 0,
1348+/*int*/ int_down,
1349+/*dur*/ 0,
1350+/*yMD*/ 0,
1351+/*dTD*/ 0,
1352+/*dT*/ 0,
1353+/*tim*/ 0,
1354+/*dat*/ 0,
1355+/*gYM*/ 0,
1356+/*gYr*/ 0,
1357+/*gMD*/ 0,
1358+/*gDay*/ 0,
1359+/*gMon*/ 0,
1360+/*bool*/ 0,
1361+/*b64*/ 0,
1362+/*hxB*/ 0,
1363+/*aURI*/ 0,
1364+/*QN*/ 0,
1365+/*NOT*/ 0,
1366+/*uint*/ int_down,
1367 };
1368
1369
1370 /*******************************************************************************
1371
1372 ********************************************************************************/
1373-const GenericCast::CastFunc GenericCast::theCastMatrix[23][23] =
1374+const GenericCast::CastFunc GenericCast::theCastMatrix[24][24] =
1375 {
1376 /*uA*/ /*str*/ /*flt*/ /*dbl*/ /*dec*/ /*int*/ /*dur*/ /*yMD*/ /*dTD*/ /*dT*/
1377 /*tim*/ /*dat*/ /*gYM*/ /*gYr*/ /*gMD*/ /*gDay*/ /*gMon*/ /*bool*/ /*b64*/ /*hxB*/
1378- /*aURI*/ /*QN*/ /*NOT*/
1379+ /*aURI*/ /*QN*/ /*NOT*/ /*uint*/
1380+
1381 /*uA*/ {&uA_uA, &uA_str, &uA_flt, &uA_dbl, &uA_dec, &uA_int, &uA_dur, &uA_yMD, &uA_dTD, &uA_dT,
1382 &uA_tim, &uA_dat, &uA_gYM, &uA_gYr, &uA_gMD, &uA_gDay, &uA_gMon, &uA_bool, &uA_b64, &uA_hxB,
1383- &uA_aURI, 0, 0},
1384+ &uA_aURI, 0, 0, &uA_uint},
1385
1386 /*str*/ {&str_uA, &str_str, &str_flt, &str_dbl, &str_dec, &str_int, &str_dur, &str_yMD, &str_dTD, &str_dT,
1387 &str_tim, &str_dat, &str_gYM, &str_gYr, &str_gMD, &str_gDay, &str_gMon, &str_bool, &str_b64, &str_hxB,
1388- &str_aURI, &str_QN, &str_NOT},
1389+ &str_aURI, &str_QN, &str_NOT, &str_uint},
1390
1391 /*flt*/ {&flt_uA, &flt_str, &flt_flt, &flt_dbl, &flt_dec, &flt_int, 0, 0, 0, 0,
1392 0, 0, 0, 0, 0, 0, 0, &flt_bool, 0, 0,
1393- 0, 0, 0},
1394+ 0, 0, 0, &flt_uint},
1395
1396 /*dbl*/ {&dbl_uA, &dbl_str, &dbl_flt, &dbl_dbl, &dbl_dec, &dbl_int, 0, 0, 0, 0,
1397 0, 0, 0, 0, 0, 0, 0, &dbl_bool, 0, 0,
1398- 0, 0, 0},
1399+ 0, 0, 0, &dbl_uint},
1400
1401 /*dec*/ {&dec_uA, &dec_str, &dec_flt, &dec_dbl, &dec_dec, &dec_int, 0, 0, 0, 0,
1402 0, 0, 0, 0, 0, 0, 0, &dec_bool, 0, 0,
1403- 0, 0, 0},
1404+ 0, 0, 0, &dec_uint},
1405+
1406+ /*uA*/ /*str*/ /*flt*/ /*dbl*/ /*dec*/ /*int*/ /*dur*/ /*yMD*/ /*dTD*/ /*dT*/
1407+ /*tim*/ /*dat*/ /*gYM*/ /*gYr*/ /*gMD*/ /*gDay*/ /*gMon*/ /*bool*/ /*b64*/ /*hxB*/
1408+ /*aURI*/ /*QN*/ /*NOT*/ /*uint*/
1409+
1410 /*int*/ {&int_uA, &int_str, &int_flt, &int_dbl, &int_dec, &int_int, 0, 0, 0, 0,
1411 0, 0, 0, 0, 0, 0, 0, &int_bool, 0, 0,
1412- 0, 0, 0},
1413+ 0, 0, 0, &int_uint},
1414+
1415 /*dur*/ {&dur_uA, &dur_str, 0, 0, 0, 0, &dur_dur, &dur_yMD, &dur_dTD, 0,
1416 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1417- 0, 0, 0},
1418+ 0, 0, 0, 0},
1419+
1420 /*yMD*/ {&yMD_uA, &yMD_str, 0, 0, 0, 0, &yMD_dur, &yMD_yMD, &yMD_dTD, 0,
1421 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1422- 0, 0, 0},
1423+ 0, 0, 0, 0},
1424+
1425 /*dTD*/ {&dTD_uA, &dTD_str, 0, 0, 0, 0, &dTD_dur, &dTD_yMD, &dTD_dTD, 0,
1426 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1427- 0, 0, 0},
1428- /*uA*/ /*str*/ /*flt*/ /*dbl*/ /*dec*/ /*int*/ /*dur*/ /*yMD*/ /*dTD*/ /*dT*/
1429- /*tim*/ /*dat*/ /*gYM*/ /*gYr*/ /*gMD*/ /*gDay*/ /*gMon*/ /*bool*/ /*b64*/ /*hxB*/
1430- /*aURI*/ /*QN*/ /*NOT*/
1431+ 0, 0, 0, 0},
1432+
1433 /*dT*/ {&dT_uA, &dT_str, 0, 0, 0, 0, 0, 0, 0, &dT_dT,
1434 &dT_tim, &dT_dat, &dT_gYM, &dT_gYr, &dT_gMD, &dT_gDay, &dT_gMon, 0, 0, 0,
1435- 0, 0, 0},
1436+ 0, 0, 0, 0},
1437+
1438+ /*uA*/ /*str*/ /*flt*/ /*dbl*/ /*dec*/ /*int*/ /*dur*/ /*yMD*/ /*dTD*/ /*dT*/
1439+ /*tim*/ /*dat*/ /*gYM*/ /*gYr*/ /*gMD*/ /*gDay*/ /*gMon*/ /*bool*/ /*b64*/ /*hxB*/
1440+ /*aURI*/ /*QN*/ /*NOT*/ /*uint*/
1441+
1442 /*tim*/ {&tim_uA, &tim_str, 0, 0, 0, 0, 0, 0, 0, 0,
1443 &tim_tim, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1444- 0, 0, 0},
1445+ 0, 0, 0, 0},
1446+
1447 /*dat*/ {&dat_uA, &dat_str, 0, 0, 0, 0, 0, 0, 0, &dat_dT,
1448 0, &dat_dat, &dat_gYM, &dat_gYr, &dat_gMD, &dat_gDay, &dat_gMon, 0, 0, 0,
1449- 0, 0, 0},
1450+ 0, 0, 0, 0},
1451+
1452 /*gYM*/ {&gYM_uA, &gYM_str, 0, 0, 0, 0, 0, 0, 0, 0,
1453 0, 0, &gYM_gYM, 0, 0, 0, 0, 0, 0, 0,
1454- 0, 0, 0},
1455+ 0, 0, 0, 0},
1456+
1457 /*gYr*/ {&gYr_uA, &gYr_str, 0, 0, 0, 0, 0, 0, 0, 0,
1458 0, 0, 0, &gYr_gYr, 0, 0, 0, 0, 0, 0,
1459- 0, 0, 0},
1460+ 0, 0, 0, 0},
1461+
1462 /*gMD*/ {&gMD_uA, &gMD_str, 0, 0, 0, 0, 0, 0, 0, 0,
1463 0, 0, 0, 0, &gMD_gMD, 0, 0, 0, 0, 0,
1464- 0, 0, 0},
1465+ 0, 0, 0, 0},
1466+
1467+ /*uA*/ /*str*/ /*flt*/ /*dbl*/ /*dec*/ /*int*/ /*dur*/ /*yMD*/ /*dTD*/ /*dT*/
1468+ /*tim*/ /*dat*/ /*gYM*/ /*gYr*/ /*gMD*/ /*gDay*/ /*gMon*/ /*bool*/ /*b64*/ /*hxB*/
1469+ /*aURI*/ /*QN*/ /*NOT*/ /*uint*/
1470+
1471 /*gDay*/ {&gDay_uA, &gDay_str, 0, 0, 0, 0, 0, 0, 0, 0,
1472 0, 0, 0, 0, 0, &gDay_gDay,0, 0, 0, 0,
1473- 0, 0, 0},
1474+ 0, 0, 0, 0},
1475+
1476 /*gMon*/ {&gMon_uA, &gMon_str, 0, 0, 0, 0, 0, 0, 0, 0,
1477 0, 0, 0, 0, 0, 0, &gMon_gMon,0, 0, 0,
1478- 0, 0, 0},
1479+ 0, 0, 0, 0},
1480+
1481 /*bool*/ {&bool_uA, &bool_str, &bool_flt, &bool_dbl, &bool_dec, &bool_int, 0, 0, 0, 0,
1482 0, 0, 0, 0, 0, 0, 0, &bool_bool,0, 0,
1483- 0, 0, 0},
1484+ 0, 0, 0, &bool_uint},
1485+
1486 /*b64*/ {&b64_uA, &b64_str, 0, 0, 0, 0, 0, 0, 0, 0,
1487 0, 0, 0, 0, 0, 0, 0, 0, &b64_b64, &b64_hxB,
1488- 0, 0, 0},
1489+ 0, 0, 0, 0},
1490+
1491 /*hxB*/ {&hxB_uA, &hxB_str, 0, 0, 0, 0, 0, 0, 0, 0,
1492 0, 0, 0, 0, 0, 0, 0, 0, &hxB_b64, &hxB_hxB,
1493- 0, 0, 0},
1494+ 0, 0, 0, 0},
1495+
1496+ /*uA*/ /*str*/ /*flt*/ /*dbl*/ /*dec*/ /*int*/ /*dur*/ /*yMD*/ /*dTD*/ /*dT*/
1497+ /*tim*/ /*dat*/ /*gYM*/ /*gYr*/ /*gMD*/ /*gDay*/ /*gMon*/ /*bool*/ /*b64*/ /*hxB*/
1498+ /*aURI*/ /*QN*/ /*NOT*/ /*uint*/
1499+
1500 /*aURI*/ {&aURI_uA, &aURI_str, 0, 0, 0, 0, 0, 0, 0, 0,
1501 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1502- &aURI_aURI,0, 0},
1503+ &aURI_aURI,0, 0, 0},
1504+
1505 /*QN*/ {&QN_uA, &QN_str, 0, 0, 0, 0, 0, 0, 0, 0,
1506 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1507- 0, &QN_QN, 0},
1508+ 0, &QN_QN, 0, 0},
1509+
1510 /*NOT*/ {&NOT_uA, &NOT_str, 0, 0, 0, 0, 0, 0, 0, 0,
1511 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1512- 0, 0, &NOT_NOT}
1513+ 0, 0, &NOT_NOT, 0},
1514+
1515+/*uint*/ {&uint_uA, &uint_str, &uint_flt, &uint_dbl, &uint_dec, &uint_int, 0, 0, 0, 0,
1516+ 0, 0, 0, 0, 0, 0, 0, &uint_bool,0, 0,
1517+ 0, 0, 0, &uint_uint},
1518 };
1519
1520
1521
1522=== modified file 'src/types/casting.h'
1523--- src/types/casting.h 2012-01-24 11:24:56 +0000
1524+++ src/types/casting.h 2012-02-28 18:23:19 +0000
1525@@ -51,8 +51,8 @@
1526
1527 private:
1528 static const int theMapping[store::XS_LAST];
1529- static const CastFunc theCastMatrix[23][23];
1530- static const DownCastFunc theDownCastMatrix[23];
1531+ static const CastFunc theCastMatrix[24][24];
1532+ static const DownCastFunc theDownCastMatrix[24];
1533
1534 GenericCast() {}
1535
1536
1537=== modified file 'src/types/schema/XercesParseUtils.cpp'
1538--- src/types/schema/XercesParseUtils.cpp 2011-06-30 05:16:55 +0000
1539+++ src/types/schema/XercesParseUtils.cpp 2012-02-28 18:23:19 +0000
1540@@ -118,7 +118,7 @@
1541 {
1542 long value = xsval->fData.fValue.f_long;
1543
1544- xs_integer tvalue(value);
1545+ xs_positiveInteger tvalue(value);
1546
1547 store::ItemFactory* factory = GENV_ITEMFACTORY;
1548 return factory->createPositiveInteger(result, tvalue);
1549@@ -207,7 +207,7 @@
1550 {
1551 long value = xsval->fData.fValue.f_long;
1552
1553- xs_integer tvalue(value);
1554+ xs_nonNegativeInteger tvalue(value);
1555
1556 store::ItemFactory* factory = GENV_ITEMFACTORY;
1557 return factory->createNonNegativeInteger(result, tvalue);
1558
1559=== modified file 'src/util/stl_util.h'
1560--- src/util/stl_util.h 2012-02-16 14:11:02 +0000
1561+++ src/util/stl_util.h 2012-02-28 18:23:19 +0000
1562@@ -248,6 +248,13 @@
1563 ///////////////////////////////////////////////////////////////////////////////
1564
1565 template<typename NumericType> inline
1566+typename std::enable_if<ZORBA_TR1_NS::is_arithmetic<NumericType>::value,
1567+ bool>::type
1568+gt0( NumericType n ) { // for completeness
1569+ return n > 0;
1570+}
1571+
1572+template<typename NumericType> inline
1573 typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type
1574 ge0( NumericType n ) {
1575 return n >= 0;
1576@@ -259,6 +266,30 @@
1577 return true;
1578 }
1579
1580+template<typename NumericType> inline
1581+typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type
1582+lt0( NumericType n ) {
1583+ return n < 0;
1584+}
1585+
1586+template<typename IntType> inline
1587+typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntType>::value,bool>::type
1588+lt0( IntType ) {
1589+ return false;
1590+}
1591+
1592+template<typename NumericType> inline
1593+typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type
1594+le0( NumericType n ) {
1595+ return n <= 0;
1596+}
1597+
1598+template<typename IntType> inline
1599+typename std::enable_if<ZORBA_TR1_NS::is_unsigned<IntType>::value,bool>::type
1600+le0( IntType n ) {
1601+ return n == 0;
1602+}
1603+
1604 ///////////////////////////////////////////////////////////////////////////////
1605
1606 template<typename T> class stack_generator {
1607
1608=== modified file 'src/util/string_util.cpp'
1609--- src/util/string_util.cpp 2011-07-07 18:48:27 +0000
1610+++ src/util/string_util.cpp 2012-02-28 18:23:19 +0000
1611@@ -110,14 +110,22 @@
1612 // We have to check for '-' ourselves since strtoull(3) allows it (oddly).
1613 //
1614 s = ascii::trim_start_whitespace( s );
1615- if ( *s == '-' )
1616+ bool const minus = *s == '-';
1617+
1618+ char *end;
1619+ errno = 0;
1620+ unsigned long long const result = std::strtoull( s, &end, 10 );
1621+ check_parse_number( s, end, static_cast<unsigned long long*>( nullptr ) );
1622+
1623+ if ( minus && result ) {
1624+ //
1625+ // Throw an exception only if there was a '-' and the result is non-zero.
1626+ // Hence, this allows "-0" and treats it as "0".
1627+ //
1628 throw std::invalid_argument(
1629 "\"-\": invalid character for unsigned integer"
1630 );
1631- char *end;
1632- errno = 0;
1633- unsigned long long const result = std::strtoull( s, &end, 10 );
1634- check_parse_number( s, end, static_cast<unsigned long long*>( nullptr ) );
1635+ }
1636 return result;
1637 }
1638
1639
1640=== modified file 'src/zorbaserialization/zorba_class_serializer.cpp'
1641--- src/zorbaserialization/zorba_class_serializer.cpp 2012-02-22 04:03:16 +0000
1642+++ src/zorbaserialization/zorba_class_serializer.cpp 2012-02-28 18:23:19 +0000
1643@@ -205,10 +205,19 @@
1644 }
1645 }
1646
1647-void operator&(serialization::Archiver &ar, Integer &obj)
1648+#ifdef ZORBA_WITH_BIG_INTEGER
1649+void operator&(serialization::Archiver &ar, IntegerImpl &obj)
1650+#else
1651+template<typename IntType>
1652+void operator&(serialization::Archiver &ar, IntegerImpl<IntType> &obj)
1653+#endif /* ZORBA_WITH_BIG_INTEGER */
1654 {
1655 ar & obj.value_;
1656 }
1657+#ifndef ZORBA_WITH_BIG_INTEGER
1658+template void operator&(serialization::Archiver&, IntegerImpl<long long>&);
1659+template void operator&(serialization::Archiver&, IntegerImpl<unsigned long long>&);
1660+#endif /* ZORBA_WITH_BIG_INTEGER */
1661
1662 void iterator_to_vector(store::Iterator_t iter, std::vector<store::Item_t> &items)
1663 {
1664@@ -590,7 +599,7 @@
1665 }
1666 else if(name_of_type == "nonNegativeInteger")
1667 {
1668- SERIALIZE_FIELD(xs_uinteger, value, getUnsignedIntegerValue());
1669+ SERIALIZE_FIELD(xs_nonNegativeInteger, value, getUnsignedIntegerValue());
1670 FINALIZE_SERIALIZE(createNonNegativeInteger, (result, value));
1671 }
1672 else if(name_of_type == "negativeInteger")
1673@@ -600,7 +609,7 @@
1674 }
1675 else if(name_of_type == "positiveInteger")
1676 {
1677- SERIALIZE_FIELD(xs_uinteger, value, getUnsignedIntegerValue());
1678+ SERIALIZE_FIELD(xs_positiveInteger, value, getUnsignedIntegerValue());
1679 FINALIZE_SERIALIZE(createPositiveInteger, (result, value));
1680 }
1681
1682
1683=== modified file 'src/zorbaserialization/zorba_class_serializer.h'
1684--- src/zorbaserialization/zorba_class_serializer.h 2012-02-02 09:56:52 +0000
1685+++ src/zorbaserialization/zorba_class_serializer.h 2012-02-28 18:23:19 +0000
1686@@ -38,13 +38,22 @@
1687 class function;
1688 class Diagnostic;
1689 class ZorbaException;
1690- class Integer;
1691+#ifdef ZORBA_WITH_BIG_INTEGER
1692+ class IntegerImpl;
1693+#else
1694+ template<typename IntType> class IntegerImpl;
1695+#endif /* ZORBA_WITH_BIG_INTEGER */
1696
1697 namespace serialization{
1698 //void operator&(Archiver &ar, XQType *&obj);
1699 void operator&(Archiver &ar, const XQType *&obj);
1700 void operator&(Archiver &ar, MAPM &obj);
1701-void operator&(Archiver &ar, Integer &obj);
1702+#ifdef ZORBA_WITH_BIG_INTEGER
1703+void operator&(Archiver &ar, IntegerImpl &obj);
1704+#else
1705+template<typename IntType>
1706+void operator&(Archiver &ar, IntegerImpl<IntType> &obj);
1707+#endif /* ZORBA_WITH_BIG_INTEGER */
1708
1709 void operator&(Archiver &ar, XQPCollator *&obj);
1710 void operator&(Archiver &ar, store::Item* &obj);
1711
1712=== modified file 'src/zorbatypes/decimal.cpp'
1713--- src/zorbatypes/decimal.cpp 2011-07-06 19:59:26 +0000
1714+++ src/zorbatypes/decimal.cpp 2012-02-28 18:23:19 +0000
1715@@ -28,6 +28,16 @@
1716 #include "integer.h"
1717 #include "numconversions.h"
1718
1719+#ifdef ZORBA_WITH_BIG_INTEGER
1720+# define TEMPLATE_DECL(T) /* nothing */
1721+# define INTEGER_IMPL(T) IntegerImpl
1722+#else
1723+# define TEMPLATE_DECL(T) template<typename T>
1724+# define INTEGER_IMPL(T) IntegerImpl<T>
1725+#endif /* ZORBA_WITH_BIG_INTEGER */
1726+#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
1727+#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
1728+
1729 namespace zorba {
1730
1731 SERIALIZABLE_CLASS_VERSIONS(Decimal)
1732@@ -218,8 +228,13 @@
1733 value_ = f.getNumber();
1734 }
1735
1736-Decimal::Decimal( Integer const &i ) : value_( i.itod() ) {
1737+TEMPLATE_DECL(T)
1738+Decimal::Decimal( INTEGER_IMPL(T) const &i ) : value_( i.itod() ) {
1739 }
1740+#ifndef ZORBA_WITH_BIG_INTEGER
1741+template Decimal::Decimal( INTEGER_IMPL_LL const& );
1742+template Decimal::Decimal( INTEGER_IMPL_ULL const& );
1743+#endif /* ZORBA_WITH_BIG_INTEGER */
1744
1745 ////////// assignment operators ///////////////////////////////////////////////
1746
1747@@ -235,10 +250,15 @@
1748 return *this;
1749 }
1750
1751-Decimal& Decimal::operator=( Integer const &i ) {
1752+TEMPLATE_DECL(T)
1753+Decimal& Decimal::operator=( INTEGER_IMPL(T) const &i ) {
1754 value_ = i.itod();
1755 return *this;
1756 }
1757+#ifndef ZORBA_WITH_BIG_INTEGER
1758+template Decimal& Decimal::operator=( INTEGER_IMPL_LL const& );
1759+template Decimal& Decimal::operator=( INTEGER_IMPL_ULL const& );
1760+#endif /* ZORBA_WITH_BIG_INTEGER */
1761
1762 Decimal& Decimal::operator=( Double const &d ) {
1763 if ( !d.isFinite() )
1764@@ -256,61 +276,69 @@
1765
1766 ////////// arithmetic operators ///////////////////////////////////////////////
1767
1768-Decimal operator+( Decimal const &d, Integer const &i ) {
1769- return d.value_ + i.itod();
1770-}
1771-
1772-Decimal operator-( Decimal const &d, Integer const &i ) {
1773- return d.value_ - i.itod();
1774-}
1775-
1776-Decimal operator*( Decimal const &d, Integer const &i ) {
1777- return d.value_ * i.itod();
1778-}
1779-
1780-Decimal operator/( Decimal const &d, Integer const &i ) {
1781- return d.value_ / i.itod();
1782-}
1783-
1784-Decimal operator%( Decimal const &d, Integer const &i ) {
1785- return d.value_ % i.itod();
1786-}
1787+#ifdef ZORBA_WITH_BIG_INTEGER
1788+# define ZORBA_INSTANTIATE(OP) /* nothing */
1789+#else
1790+# define ZORBA_INSTANTIATE(OP) \
1791+ template Decimal operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \
1792+ template Decimal operator OP( Decimal const&, INTEGER_IMPL_ULL const& )
1793+#endif /* ZORBA_WITH_BIG_INTEGER */
1794+
1795+#define ZORBA_DECIMAL_OP(OP) \
1796+ TEMPLATE_DECL(T) \
1797+ Decimal operator OP( Decimal const &d, INTEGER_IMPL(T) const &i ) { \
1798+ return d.value_ OP i.itod(); \
1799+ } \
1800+ ZORBA_INSTANTIATE(OP)
1801+
1802+ZORBA_DECIMAL_OP(+);
1803+ZORBA_DECIMAL_OP(-);
1804+ZORBA_DECIMAL_OP(*);
1805+ZORBA_DECIMAL_OP(/);
1806+ZORBA_DECIMAL_OP(%);
1807+#undef ZORBA_DECIMAL_OP
1808+#undef ZORBA_INSTANTIATE
1809
1810 ////////// relational operators ///////////////////////////////////////////////
1811
1812-bool operator==( Decimal const &d, Integer const &i ) {
1813- return d.value_ == i.itod();
1814-}
1815-
1816-bool operator!=( Decimal const &d, Integer const &i ) {
1817- return d.value_ != i.itod();
1818-}
1819-
1820-bool operator<( Decimal const &d, Integer const &i ) {
1821- return d.value_ < i.itod();
1822-}
1823-
1824-bool operator<=( Decimal const &d, Integer const &i ) {
1825- return d.value_ <= i.itod();
1826-}
1827-
1828-bool operator>( Decimal const &d, Integer const &i ) {
1829- return d.value_ > i.itod();
1830-}
1831-
1832-bool operator>=( Decimal const &d, Integer const &i ) {
1833- return d.value_ >= i.itod();
1834-}
1835+#ifdef ZORBA_WITH_BIG_INTEGER
1836+# define ZORBA_INSTANTIATE(OP) /* nothing */
1837+#else
1838+# define ZORBA_INSTANTIATE(OP) \
1839+ template bool operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \
1840+ template bool operator OP( Decimal const&, INTEGER_IMPL_ULL const& )
1841+#endif /* ZORBA_WITH_BIG_INTEGER */
1842+
1843+#define ZORBA_DECIMAL_OP(OP) \
1844+ TEMPLATE_DECL(T) \
1845+ bool operator OP( Decimal const &d, INTEGER_IMPL(T) const &i ) { \
1846+ return d.value_ OP i.itod(); \
1847+ } \
1848+ ZORBA_INSTANTIATE(OP)
1849+
1850+ZORBA_DECIMAL_OP(==);
1851+ZORBA_DECIMAL_OP(!=);
1852+ZORBA_DECIMAL_OP(< );
1853+ZORBA_DECIMAL_OP(<=);
1854+ZORBA_DECIMAL_OP(> );
1855+ZORBA_DECIMAL_OP(>=);
1856+#undef ZORBA_DECIMAL_OP
1857+#undef ZORBA_INSTANTIATE
1858
1859 ////////// math functions /////////////////////////////////////////////////////
1860
1861 Decimal Decimal::round() const {
1862- return round( Integer::zero() );
1863+ return round( INTEGER_IMPL_LL::zero() );
1864 }
1865
1866-Decimal Decimal::round( Integer const &precision ) const {
1867+TEMPLATE_DECL(T)
1868+Decimal Decimal::round( INTEGER_IMPL(T) const &precision ) const {
1869 return round( value_, precision.itod() );
1870 }
1871+#ifndef ZORBA_WITH_BIG_INTEGER
1872+template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const;
1873+template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const;
1874+#endif /* ZORBA_WITH_BIG_INTEGER */
1875
1876 Decimal::value_type Decimal::round( value_type const &v,
1877 value_type const &precision ) {
1878@@ -322,9 +350,14 @@
1879 return result;
1880 }
1881
1882-Decimal Decimal::roundHalfToEven( Integer const &precision ) const {
1883+TEMPLATE_DECL(T)
1884+Decimal Decimal::roundHalfToEven( INTEGER_IMPL(T) const &precision ) const {
1885 return roundHalfToEven( value_, precision.itod() );
1886 }
1887+#ifndef ZORBA_WITH_BIG_INTEGER
1888+template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const;
1889+template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const;
1890+#endif /* ZORBA_WITH_BIG_INTEGER */
1891
1892 Decimal::value_type Decimal::roundHalfToEven( value_type const &v,
1893 value_type const &precision ) {
1894
1895=== modified file 'src/zorbatypes/decimal.h'
1896--- src/zorbatypes/decimal.h 2011-06-24 18:27:08 +0000
1897+++ src/zorbatypes/decimal.h 2012-02-28 18:23:19 +0000
1898@@ -29,6 +29,14 @@
1899 #include "zorbatypes_decl.h"
1900 #include "zstring.h"
1901
1902+#ifdef ZORBA_WITH_BIG_INTEGER
1903+# define TEMPLATE_DECL(T) /* nothing */
1904+# define INTEGER_IMPL(T) IntegerImpl
1905+#else
1906+# define TEMPLATE_DECL(T) template<typename T>
1907+# define INTEGER_IMPL(T) IntegerImpl<T>
1908+#endif /* ZORBA_WITH_BIG_INTEGER */
1909+
1910 namespace zorba {
1911
1912 ///////////////////////////////////////////////////////////////////////////////
1913@@ -52,7 +60,9 @@
1914 Decimal( float n );
1915 Decimal( double n );
1916 Decimal( Decimal const &d );
1917- Decimal( Integer const &i );
1918+
1919+ TEMPLATE_DECL(T)
1920+ Decimal( INTEGER_IMPL(T) const &i );
1921
1922 /**
1923 * Constructs a %Decimal from a C string.
1924@@ -98,27 +108,30 @@
1925 Decimal& operator=( Decimal const &d );
1926 Decimal& operator=( Double const &d );
1927 Decimal& operator=( Float const &f );
1928- Decimal& operator=( Integer const &i );
1929+
1930+ TEMPLATE_DECL(T)
1931+ Decimal& operator=( INTEGER_IMPL(T) const &i );
1932
1933 ////////// arithmetic operators /////////////////////////////////////////////
1934
1935- friend Decimal operator+( Decimal const &d1, Decimal const &d2 );
1936- friend Decimal operator-( Decimal const &d1, Decimal const &d2 );
1937- friend Decimal operator*( Decimal const &d1, Decimal const &d2 );
1938- friend Decimal operator/( Decimal const &d1, Decimal const &d2 );
1939- friend Decimal operator%( Decimal const &d1, Decimal const &d2 );
1940-
1941- friend Decimal operator+( Decimal const &d, Integer const &i );
1942- friend Decimal operator-( Decimal const &d, Integer const &i );
1943- friend Decimal operator*( Decimal const &d, Integer const &i );
1944- friend Decimal operator/( Decimal const &d, Integer const &i );
1945- friend Decimal operator%( Decimal const &d, Integer const &i );
1946-
1947- friend Decimal operator+( Integer const &i, Decimal const &d );
1948- friend Decimal operator-( Integer const &i, Decimal const &d );
1949- friend Decimal operator*( Integer const &i, Decimal const &d );
1950- friend Decimal operator/( Integer const &i, Decimal const &d );
1951- friend Decimal operator%( Integer const &i, Decimal const &d );
1952+ friend Decimal operator+( Decimal const&, Decimal const& );
1953+ friend Decimal operator-( Decimal const&, Decimal const& );
1954+ friend Decimal operator*( Decimal const&, Decimal const& );
1955+ friend Decimal operator/( Decimal const&, Decimal const& );
1956+ friend Decimal operator%( Decimal const&, Decimal const& );
1957+
1958+#define ZORBA_DECIMAL_OP(OP) \
1959+ TEMPLATE_DECL(T) \
1960+ friend Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \
1961+ TEMPLATE_DECL(T) \
1962+ friend Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& )
1963+
1964+ ZORBA_DECIMAL_OP(+);
1965+ ZORBA_DECIMAL_OP(-);
1966+ ZORBA_DECIMAL_OP(*);
1967+ ZORBA_DECIMAL_OP(/);
1968+ ZORBA_DECIMAL_OP(%);
1969+#undef ZORBA_DECIMAL_OP
1970
1971 Decimal& operator+=( Decimal const& );
1972 Decimal& operator-=( Decimal const& );
1973@@ -126,46 +139,49 @@
1974 Decimal& operator/=( Decimal const& );
1975 Decimal& operator%=( Decimal const& );
1976
1977- Decimal& operator+=( Integer const& );
1978- Decimal& operator-=( Integer const& );
1979- Decimal& operator*=( Integer const& );
1980- Decimal& operator/=( Integer const& );
1981- Decimal& operator%=( Integer const& );
1982+#define ZORBA_DECIMAL_OP(OP) \
1983+ TEMPLATE_DECL(T) Decimal& operator OP( INTEGER_IMPL(T) const& )
1984+
1985+ ZORBA_DECIMAL_OP(+=);
1986+ ZORBA_DECIMAL_OP(-=);
1987+ ZORBA_DECIMAL_OP(*=);
1988+ ZORBA_DECIMAL_OP(/=);
1989+ ZORBA_DECIMAL_OP(%=);
1990+#undef ZORBA_DECIMAL_OP
1991
1992 Decimal operator-() const;
1993
1994 ////////// relational operators /////////////////////////////////////////////
1995
1996- friend bool operator==( Decimal const &d1, Decimal const &d2 );
1997- friend bool operator!=( Decimal const &d1, Decimal const &d2 );
1998- friend bool operator< ( Decimal const &d1, Decimal const &d2 );
1999- friend bool operator<=( Decimal const &d1, Decimal const &d2 );
2000- friend bool operator> ( Decimal const &d1, Decimal const &d2 );
2001- friend bool operator>=( Decimal const &d1, Decimal const &d2 );
2002-
2003- friend bool operator==( Decimal const &d, Integer const &i );
2004- friend bool operator!=( Decimal const &d, Integer const &i );
2005- friend bool operator< ( Decimal const &d, Integer const &i );
2006- friend bool operator<=( Decimal const &d, Integer const &i );
2007- friend bool operator> ( Decimal const &d, Integer const &i );
2008- friend bool operator>=( Decimal const &d, Integer const &i );
2009-
2010- friend bool operator==( Integer const &i, Decimal const &d );
2011- friend bool operator!=( Integer const &i, Decimal const &d );
2012- friend bool operator< ( Integer const &i, Decimal const &d );
2013- friend bool operator<=( Integer const &i, Decimal const &d );
2014- friend bool operator> ( Integer const &i, Decimal const &d );
2015- friend bool operator>=( Integer const &i, Decimal const &d );
2016+#define ZORBA_DECIMAL_OP(OP) \
2017+ friend bool operator OP( Decimal const&, Decimal const& ); \
2018+ TEMPLATE_DECL(T) \
2019+ friend bool operator OP( Decimal const&, INTEGER_IMPL(T) const& ); \
2020+ TEMPLATE_DECL(T) \
2021+ friend bool operator OP( INTEGER_IMPL(T) const&, Decimal const& )
2022+
2023+ ZORBA_DECIMAL_OP(==);
2024+ ZORBA_DECIMAL_OP(!=);
2025+ ZORBA_DECIMAL_OP(< );
2026+ ZORBA_DECIMAL_OP(<=);
2027+ ZORBA_DECIMAL_OP(> );
2028+ ZORBA_DECIMAL_OP(>=);
2029+#undef ZORBA_DECIMAL_OP
2030
2031 ////////// math functions ///////////////////////////////////////////////////
2032
2033- int compare( Decimal const &d ) const;
2034+ int compare( Decimal const& ) const;
2035
2036 Decimal ceil() const;
2037 Decimal floor() const;
2038 Decimal round() const;
2039- Decimal round( Integer const &precision ) const;
2040- Decimal roundHalfToEven( Integer const &precision ) const;
2041+
2042+ TEMPLATE_DECL(T)
2043+ Decimal round( INTEGER_IMPL(T) const &precision ) const;
2044+
2045+ TEMPLATE_DECL(T)
2046+ Decimal roundHalfToEven( INTEGER_IMPL(T) const &precision ) const;
2047+
2048 Decimal sqrt() const;
2049
2050 ////////// miscellaneous ////////////////////////////////////////////////////
2051@@ -215,7 +231,7 @@
2052 static zstring toString( value_type const&,
2053 int precision = ZORBA_FLOAT_POINT_PRECISION );
2054
2055- friend class Integer;
2056+ TEMPLATE_DECL(T) friend class IntegerImpl;
2057 template<typename T> friend class FloatImpl;
2058
2059 friend xs_long to_xs_long( Decimal const& );
2060@@ -443,6 +459,10 @@
2061 ///////////////////////////////////////////////////////////////////////////////
2062
2063 } // namespace zorba
2064+
2065+#undef TEMPLATE_DECL
2066+#undef INTEGER_IMPL
2067+
2068 #endif /* ZORBA_DECIMAL_H */
2069 /*
2070 * Local variables:
2071
2072=== modified file 'src/zorbatypes/floatimpl.cpp'
2073--- src/zorbatypes/floatimpl.cpp 2011-07-07 12:05:43 +0000
2074+++ src/zorbatypes/floatimpl.cpp 2012-02-28 18:23:19 +0000
2075@@ -29,6 +29,16 @@
2076
2077 #include "zorbaserialization/serialization_engine.h"
2078
2079+#ifdef ZORBA_WITH_BIG_INTEGER
2080+# define TEMPLATE_DECL(T) /* nothing */
2081+# define INTEGER_IMPL(T) IntegerImpl
2082+#else
2083+# define TEMPLATE_DECL(T) template<typename T>
2084+# define INTEGER_IMPL(T) IntegerImpl<T>
2085+#endif /* ZORBA_WITH_BIG_INTEGER */
2086+#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
2087+#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
2088+
2089 ///////////////////////////////////////////////////////////////////////////////
2090
2091 namespace zorba {
2092@@ -144,11 +154,20 @@
2093 }
2094
2095 template<typename FloatType>
2096-FloatImpl<FloatType>::FloatImpl( Integer const &i ) {
2097+TEMPLATE_DECL(IntType)
2098+FloatImpl<FloatType>::FloatImpl( INTEGER_IMPL(IntType) const &i ) {
2099 zstring const temp( i.toString() );
2100 parse( temp.c_str() );
2101 }
2102
2103+#ifndef ZORBA_WITH_BIG_INTEGER
2104+template FloatImpl<float>::FloatImpl( INTEGER_IMPL_LL const& );
2105+template FloatImpl<float>::FloatImpl( INTEGER_IMPL_ULL const& );
2106+
2107+template FloatImpl<double>::FloatImpl( INTEGER_IMPL_LL const& );
2108+template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& );
2109+#endif /* ZORBA_WITH_BIG_INTEGER */
2110+
2111 ////////// math functions /////////////////////////////////////////////////////
2112
2113 template<typename FloatType>
2114
2115=== modified file 'src/zorbatypes/floatimpl.h'
2116--- src/zorbatypes/floatimpl.h 2011-10-03 09:18:49 +0000
2117+++ src/zorbatypes/floatimpl.h 2012-02-28 18:23:19 +0000
2118@@ -29,13 +29,22 @@
2119 #include "schema_types.h"
2120 #include "zorbatypes_decl.h"
2121
2122+#ifdef ZORBA_WITH_BIG_INTEGER
2123+# define TEMPLATE_DECL(T) /* nothing */
2124+# define INTEGER_IMPL(T) IntegerImpl
2125+#else
2126+# define TEMPLATE_DECL(T) template<typename T>
2127+# define INTEGER_IMPL(T) IntegerImpl<T>
2128+#endif /* ZORBA_WITH_BIG_INTEGER */
2129+
2130 namespace zorba {
2131
2132 template<typename FloatType>
2133 class FloatImpl;
2134-namespace serialization{
2135+
2136+namespace serialization {
2137 template<typename FloatType>
2138- void operator&(Archiver &ar, FloatImpl<FloatType> &obj);
2139+ void operator&( Archiver&, FloatImpl<FloatType>& );
2140 }
2141
2142 ///////////////////////////////////////////////////////////////////////////////
2143@@ -61,7 +70,9 @@
2144 FloatImpl( float n );
2145 FloatImpl( double n );
2146 FloatImpl( Decimal const &d );
2147- FloatImpl( Integer const &i );
2148+
2149+ TEMPLATE_DECL(T)
2150+ FloatImpl( INTEGER_IMPL(T) const &i );
2151
2152 /**
2153 * Constructs a %FloatImpl from a C string.
2154@@ -220,7 +231,7 @@
2155 void parse( char const* );
2156 bool parse_etc( char const* );
2157
2158- friend class Integer;
2159+ TEMPLATE_DECL(T) friend class IntegerImpl;
2160 friend class Decimal;
2161
2162 friend class FloatImpl<float>;
2163@@ -772,6 +783,10 @@
2164 ///////////////////////////////////////////////////////////////////////////////
2165
2166 } // namespace zorba
2167+
2168+#undef TEMPLATE_DECL
2169+#undef INTEGER_IMPL
2170+
2171 #endif // ZORBA_FLOATIMPL_H
2172 /*
2173 * Local variables:
2174
2175=== modified file 'src/zorbatypes/integer.cpp'
2176--- src/zorbatypes/integer.cpp 2011-07-06 20:13:28 +0000
2177+++ src/zorbatypes/integer.cpp 2012-02-28 18:23:19 +0000
2178@@ -27,62 +27,82 @@
2179 #include "floatimpl.h"
2180 #include "numconversions.h"
2181
2182+#ifdef ZORBA_WITH_BIG_INTEGER
2183+# define TEMPLATE_DECL(T) /* nothing */
2184+# define INTEGER_IMPL(T) IntegerImpl
2185+#else
2186+# define TEMPLATE_DECL(T) template<typename T>
2187+# define INTEGER_IMPL(T) IntegerImpl<T>
2188+#endif /* ZORBA_WITH_BIG_INTEGER */
2189+#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
2190+#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
2191+
2192 using namespace std;
2193
2194-#ifdef WIN32
2195-namespace std {
2196- inline long long strtoll( char const *s, char **end, int base ) {
2197- return ::_strtoi64( s, end, base );
2198- }
2199-
2200- inline long long strtoull( char const *s, char **end, int base ) {
2201- return ::_strtoui64( s, end, base );
2202- }
2203-}
2204-#endif /* WIN32 */
2205+#ifndef ZORBA_WITH_BIG_INTEGER
2206+unsigned long long MaxUIntegerValue = ~0ull >> 1;
2207+
2208+inline bool is_too_big( long long ) {
2209+ return false;
2210+}
2211+
2212+inline bool is_too_big( unsigned long long n ) {
2213+ return n > MaxUIntegerValue;
2214+}
2215+#endif /* ZORBA_WITH_BIG_INTEGER */
2216
2217 namespace zorba {
2218
2219 ///////////////////////////////////////////////////////////////////////////////
2220
2221-void Integer::parse( char const *s ) {
2222 #ifdef ZORBA_WITH_BIG_INTEGER
2223+void IntegerImpl::parse( char const *s ) {
2224 Decimal::parse( s, &value_, Decimal::parse_integer );
2225 #else
2226- value_ = ztd::aton<value_type>( s );
2227+template<typename IntType>
2228+void IntegerImpl<IntType>::parse( char const *s ) {
2229+ value_type const temp = ztd::aton<value_type>( s );
2230+ if ( is_too_big( temp ) )
2231+ throw std::invalid_argument(
2232+ BUILD_STRING( '"', temp, "\": unsigned integer too big" )
2233+ );
2234+ value_ = temp;
2235 #endif /* ZORBA_WITH_BIG_INTEGER */
2236 }
2237
2238 ////////// constructors ///////////////////////////////////////////////////////
2239
2240 #ifdef ZORBA_WITH_BIG_INTEGER
2241-Integer::Integer( long long n ) {
2242- ztd::itoa_buf_type buf;
2243- value_ = ztd::itoa( n, buf );
2244-}
2245-
2246-Integer::Integer( unsigned long n ) {
2247- ztd::itoa_buf_type buf;
2248- value_ = ztd::itoa( n, buf );
2249-}
2250-
2251-Integer::Integer( unsigned long long n ) {
2252+IntegerImpl::IntegerImpl( long long n ) {
2253+ ztd::itoa_buf_type buf;
2254+ value_ = ztd::itoa( n, buf );
2255+}
2256+
2257+IntegerImpl::IntegerImpl( unsigned long n ) {
2258+ ztd::itoa_buf_type buf;
2259+ value_ = ztd::itoa( n, buf );
2260+}
2261+
2262+IntegerImpl::IntegerImpl( unsigned long long n ) {
2263 ztd::itoa_buf_type buf;
2264 value_ = ztd::itoa( n, buf );
2265 }
2266 #endif /* ZORBA_WITH_BIG_INTEGER */
2267
2268-Integer::Integer( Decimal const &d ) {
2269+TEMPLATE_DECL(T)
2270+INTEGER_IMPL(T)::IntegerImpl( Decimal const &d ) {
2271 value_ = ftoi( d.value_ );
2272 }
2273
2274-Integer::Integer( Double const &d ) {
2275+TEMPLATE_DECL(T)
2276+INTEGER_IMPL(T)::IntegerImpl( Double const &d ) {
2277 if ( !d.isFinite() )
2278 throw std::invalid_argument( "not finite" );
2279 value_ = ftoi( d.getNumber() );
2280 }
2281
2282-Integer::Integer( Float const &f ) {
2283+TEMPLATE_DECL(T)
2284+INTEGER_IMPL(T)::IntegerImpl( Float const &f ) {
2285 if ( !f.isFinite() )
2286 throw std::invalid_argument( "not finite" );
2287 value_ = ftoi( f.getNumber() );
2288@@ -91,38 +111,41 @@
2289 ////////// assignment operators ///////////////////////////////////////////////
2290
2291 #ifdef ZORBA_WITH_BIG_INTEGER
2292-Integer& Integer::operator=( long long n ) {
2293- ztd::itoa_buf_type buf;
2294- value_ = ztd::itoa( n, buf );
2295- return *this;
2296-}
2297-
2298-Integer& Integer::operator=( unsigned long n ) {
2299- ztd::itoa_buf_type buf;
2300- value_ = ztd::itoa( n, buf );
2301- return *this;
2302-}
2303-
2304-Integer& Integer::operator=( unsigned long long n ) {
2305+IntegerImpl& IntegerImpl::operator=( long long n ) {
2306+ ztd::itoa_buf_type buf;
2307+ value_ = ztd::itoa( n, buf );
2308+ return *this;
2309+}
2310+
2311+IntegerImpl& IntegerImpl::operator=( unsigned long n ) {
2312+ ztd::itoa_buf_type buf;
2313+ value_ = ztd::itoa( n, buf );
2314+ return *this;
2315+}
2316+
2317+IntegerImpl& IntegerImpl::operator=( unsigned long long n ) {
2318 ztd::itoa_buf_type buf;
2319 value_ = ztd::itoa( n, buf );
2320 return *this;
2321 }
2322 #endif /* ZORBA_WITH_BIG_INTEGER */
2323
2324-Integer& Integer::operator=( Decimal const &d ) {
2325+TEMPLATE_DECL(T)
2326+INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Decimal const &d ) {
2327 value_ = ftoi( d.value_ );
2328 return *this;
2329 }
2330
2331-Integer& Integer::operator=( Double const &d ) {
2332+TEMPLATE_DECL(T)
2333+INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Double const &d ) {
2334 if ( !d.isFinite() )
2335 throw std::invalid_argument( "not finite" );
2336 value_ = ftoi( d.getNumber() );
2337 return *this;
2338 }
2339
2340-Integer& Integer::operator=( Float const &f ) {
2341+TEMPLATE_DECL(T)
2342+INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Float const &f ) {
2343 if ( !f.isFinite() )
2344 throw std::invalid_argument( "not finite" );
2345 value_ = ftoi( f.getNumber() );
2346@@ -131,55 +154,67 @@
2347
2348 ////////// arithmetic operators ///////////////////////////////////////////////
2349
2350-Decimal operator+( Integer const &i, Decimal const &d ) {
2351- return i.itod() + d.value_;
2352-}
2353-
2354-Decimal operator-( Integer const &i, Decimal const &d ) {
2355- return i.itod() - d.value_;
2356-}
2357-
2358-Decimal operator*( Integer const &i, Decimal const &d ) {
2359- return i.itod() * d.value_;
2360-}
2361-
2362-Decimal operator/( Integer const &i, Decimal const &d ) {
2363- return i.itod() / d.value_;
2364-}
2365-
2366-Decimal operator%( Integer const &i, Decimal const &d ) {
2367- return i.itod() % d.value_;
2368-}
2369+#ifdef ZORBA_WITH_BIG_INTEGER
2370+# define ZORBA_INSTANTIATE(OP) /* nothing */
2371+#else
2372+# define ZORBA_INSTANTIATE(OP) \
2373+ template Decimal operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \
2374+ template Decimal operator OP( INTEGER_IMPL_ULL const&, Decimal const& );
2375+#endif /* ZORBA_WITH_BIG_INTEGER */
2376+
2377+#define ZORBA_INTEGER_OP(OP) \
2378+ TEMPLATE_DECL(T) \
2379+ Decimal operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \
2380+ return i.itod() OP d.value_; \
2381+ } \
2382+ ZORBA_INSTANTIATE(OP)
2383+
2384+ZORBA_INTEGER_OP(+)
2385+ZORBA_INTEGER_OP(-)
2386+ZORBA_INTEGER_OP(*)
2387+ZORBA_INTEGER_OP(/)
2388+ZORBA_INTEGER_OP(%)
2389+#undef ZORBA_INTEGER_OP
2390+#undef ZORBA_INSTANTIATE
2391
2392 ////////// relational operators ///////////////////////////////////////////////
2393
2394-bool operator==( Integer const &i, Decimal const &d ) {
2395+TEMPLATE_DECL(T)
2396+bool operator==( INTEGER_IMPL(T) const &i, Decimal const &d ) {
2397 return d.is_integer() && i.itod() == d.value_;
2398 }
2399
2400-bool operator!=( Integer const &i, Decimal const &d ) {
2401- return i.itod() != d.value_;
2402-}
2403-
2404-bool operator<( Integer const &i, Decimal const &d ) {
2405- return i.itod() < d.value_;
2406-}
2407-
2408-bool operator<=( Integer const &i, Decimal const &d ) {
2409- return i.itod() <= d.value_;
2410-}
2411-
2412-bool operator>( Integer const &i, Decimal const &d ) {
2413- return i.itod() > d.value_;
2414-}
2415-
2416-bool operator>=( Integer const &i, Decimal const &d ) {
2417- return i.itod() >= d.value_;
2418-}
2419+#define ZORBA_INTEGER_OP(OP) \
2420+ TEMPLATE_DECL(T) \
2421+ bool operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \
2422+ return i.itod() OP d.value_; \
2423+ }
2424+
2425+ZORBA_INTEGER_OP(!=)
2426+ZORBA_INTEGER_OP(< )
2427+ZORBA_INTEGER_OP(<=)
2428+ZORBA_INTEGER_OP(> )
2429+ZORBA_INTEGER_OP(>=)
2430+#undef ZORBA_INTEGER_OP
2431+
2432+#ifndef ZORBA_WITH_BIG_INTEGER
2433+#define ZORBA_INSTANTIATE(OP) \
2434+ template bool operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \
2435+ template bool operator OP( INTEGER_IMPL_ULL const&, Decimal const& )
2436+
2437+ZORBA_INSTANTIATE(==);
2438+ZORBA_INSTANTIATE(!=);
2439+ZORBA_INSTANTIATE(< );
2440+ZORBA_INSTANTIATE(<=);
2441+ZORBA_INSTANTIATE(> );
2442+ZORBA_INSTANTIATE(>=);
2443+#undef ZORBA_INSTANTIATE
2444+#endif /* ZORBA_WITH_BIG_INTEGER */
2445
2446 ////////// math functions /////////////////////////////////////////////////////
2447
2448-Double Integer::pow( Integer const &power ) const {
2449+TEMPLATE_DECL(T)
2450+Double INTEGER_IMPL(T)::pow( INTEGER_IMPL(T) const &power ) const {
2451 #ifdef ZORBA_WITH_BIG_INTEGER
2452 value_type const result( value_.pow( power.value_, 15 ) );
2453 char buf[300];
2454@@ -193,27 +228,32 @@
2455 #endif /* ZORBA_WITH_BIG_INTEGER */
2456 }
2457
2458-Integer Integer::round( Integer const &precision ) const {
2459- return Integer( Decimal::round( itod(), precision.itod() ) );
2460+TEMPLATE_DECL(T)
2461+INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const {
2462+ return IntegerImpl( Decimal::round( itod(), precision.itod() ) );
2463 }
2464
2465-Integer Integer::roundHalfToEven( Integer const &precision ) const {
2466- return Integer( Decimal::roundHalfToEven( itod(), precision.itod() ) );
2467+TEMPLATE_DECL(T)
2468+INTEGER_IMPL(T)
2469+INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const {
2470+ return IntegerImpl( Decimal::roundHalfToEven( itod(), precision.itod() ) );
2471 }
2472
2473 ////////// miscellaneous //////////////////////////////////////////////////////
2474
2475 #ifndef ZORBA_WITH_BIG_INTEGER
2476-Integer::value_type Integer::ftoi( MAPM const &d ) {
2477+TEMPLATE_DECL(T)
2478+typename INTEGER_IMPL(T)::value_type INTEGER_IMPL(T)::ftoi( MAPM const &d ) {
2479 MAPM const temp( d.sign() >= 0 ? d.floor() : d.ceil() );
2480 char *const buf = new char[ temp.exponent() + 3 ];
2481 temp.toIntegerString( buf );
2482- value_type const result( std::strtoll( buf, nullptr, 10 ) );
2483+ value_type const result( ztd::aton<value_type>( buf ) );
2484 delete[] buf;
2485 return result;
2486 }
2487
2488-MAPM Integer::itod() const {
2489+TEMPLATE_DECL(T)
2490+MAPM INTEGER_IMPL(T)::itod() const {
2491 if ( is_long() )
2492 return static_cast<long>( value_ );
2493 ztd::itoa_buf_type buf;
2494@@ -222,17 +262,19 @@
2495 #endif /* ZORBA_WITH_BIG_INTEGER */
2496
2497 #ifdef ZORBA_WITH_BIG_INTEGER
2498-uint32_t Integer::hash() const {
2499+uint32_t IntegerImpl::hash() const {
2500 return Decimal::hash( value_ );
2501 }
2502 #endif /* ZORBA_WITH_BIG_INTEGER */
2503
2504-Integer const& Integer::one() {
2505- static Integer const i(1);
2506+TEMPLATE_DECL(T)
2507+INTEGER_IMPL(T) const& INTEGER_IMPL(T)::one() {
2508+ static INTEGER_IMPL(T) const i(1);
2509 return i;
2510 }
2511
2512-zstring Integer::toString() const {
2513+TEMPLATE_DECL(T)
2514+zstring INTEGER_IMPL(T)::toString() const {
2515 #ifdef ZORBA_WITH_BIG_INTEGER
2516 char *const buf = new char[ value_.exponent() + 3 ];
2517 value_.toIntegerString( buf );
2518@@ -245,12 +287,18 @@
2519 #endif /* ZORBA_WITH_BIG_INTEGER */
2520 }
2521
2522-Integer const& Integer::zero() {
2523- static Integer const i(0);
2524+TEMPLATE_DECL(T)
2525+INTEGER_IMPL(T) const& INTEGER_IMPL(T)::zero() {
2526+ static INTEGER_IMPL(T) const i(0);
2527 return i;
2528 }
2529
2530 ///////////////////////////////////////////////////////////////////////////////
2531
2532+#ifndef ZORBA_WITH_BIG_INTEGER
2533+template class IntegerImpl<long long>;
2534+template class IntegerImpl<unsigned long long>;
2535+#endif /* ZORBA_WITH_BIG_INTEGER */
2536+
2537 } // namespace zorba
2538 /* vim:set et sw=2 ts=2: */
2539
2540=== modified file 'src/zorbatypes/integer.h'
2541--- src/zorbatypes/integer.h 2011-06-29 20:31:44 +0000
2542+++ src/zorbatypes/integer.h 2012-02-28 18:23:19 +0000
2543@@ -24,6 +24,7 @@
2544 #include <zorba/config.h>
2545 #include "common/common.h"
2546
2547+#include "util/stl_util.h"
2548 #include "zorbaserialization/archiver.h"
2549 #include "zorbaserialization/zorba_class_serializer.h"
2550
2551@@ -32,39 +33,53 @@
2552 #include "zorbatypes_decl.h"
2553 #include "zstring.h"
2554
2555+#ifdef ZORBA_WITH_BIG_INTEGER
2556+# define TEMPLATE_DECL(T) /* nothing */
2557+# define INTEGER_IMPL(T) IntegerImpl
2558+#else
2559+# define TEMPLATE_DECL(T) template<typename T>
2560+# define INTEGER_IMPL(T) IntegerImpl<T>
2561+#endif /* ZORBA_WITH_BIG_INTEGER */
2562+#define INTEGER_IMPL_LL INTEGER_IMPL(long long)
2563+#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long)
2564+
2565 namespace zorba {
2566
2567-class Integer;
2568+TEMPLATE_DECL(T)
2569+class IntegerImpl;
2570+
2571 namespace serialization {
2572- void operator&(serialization::Archiver&, zorba::Integer&);
2573+ TEMPLATE_DECL(T) void operator&( Archiver&, INTEGER_IMPL(T)& );
2574 }
2575
2576 ///////////////////////////////////////////////////////////////////////////////
2577
2578-// exported for testing only
2579-class ZORBA_DLL_PUBLIC Integer {
2580+TEMPLATE_DECL(IntType)
2581+class IntegerImpl {
2582 public:
2583
2584 ////////// constructors /////////////////////////////////////////////////////
2585
2586- Integer( char c );
2587- Integer( signed char c );
2588- Integer( short n );
2589- Integer( int n = 0 );
2590- Integer( long n );
2591- Integer( long long n );
2592- Integer( unsigned char c );
2593- Integer( unsigned short n );
2594- Integer( unsigned int n );
2595- Integer( unsigned long n );
2596- Integer( unsigned long long n );
2597- Integer( float n );
2598- Integer( double n );
2599- Integer( Decimal const &d );
2600- Integer( Integer const &i );
2601+ IntegerImpl( char c );
2602+ IntegerImpl( signed char c );
2603+ IntegerImpl( short n );
2604+ IntegerImpl( int n = 0 );
2605+ IntegerImpl( long n );
2606+ IntegerImpl( long long n );
2607+ IntegerImpl( unsigned char c );
2608+ IntegerImpl( unsigned short n );
2609+ IntegerImpl( unsigned int n );
2610+ IntegerImpl( unsigned long n );
2611+ IntegerImpl( unsigned long long n );
2612+ IntegerImpl( float n );
2613+ IntegerImpl( double n );
2614+ IntegerImpl( Decimal const &d );
2615+
2616+ TEMPLATE_DECL(U)
2617+ IntegerImpl( INTEGER_IMPL(U) const &i );
2618
2619 /**
2620- * Constructs an %Integer from a C string.
2621+ * Constructs an %IntegerImpl from a C string.
2622 *
2623 * @param s The null-terminated C string to parse. Leading and trailing
2624 * whitespace is ignored.
2625@@ -73,115 +88,110 @@
2626 * or overflows the smallest or largest representable integer (only when not
2627 * compiled with ZORBA_WITH_BIG_INTEGER).
2628 */
2629- Integer( char const *s );
2630+ IntegerImpl( char const *s );
2631
2632 /**
2633- * Constructs an %Integer from a Double.
2634+ * Constructs an %IntegerImpl from a Double.
2635 *
2636 * @param d The Double.
2637 * @throw std::invalid_argument if \a d is not finite.
2638 */
2639- Integer( Double const &d );
2640+ IntegerImpl( Double const &d );
2641
2642 /**
2643- * Constructs an %Integer from a Float.
2644+ * Constructs an %IntegerImpl from a Float.
2645 *
2646 * @param f The Float.
2647 * @throw std::invalid_argument if \a f is not finite.
2648 */
2649- Integer( Float const &f );
2650+ IntegerImpl( Float const &f );
2651
2652 ////////// assignment operators /////////////////////////////////////////////
2653
2654- Integer& operator=( char c );
2655- Integer& operator=( signed char c );
2656- Integer& operator=( short n );
2657- Integer& operator=( int n );
2658- Integer& operator=( long n );
2659- Integer& operator=( long long n );
2660- Integer& operator=( unsigned char c );
2661- Integer& operator=( unsigned short n );
2662- Integer& operator=( unsigned int n );
2663- Integer& operator=( unsigned long n );
2664- Integer& operator=( unsigned long long n );
2665- Integer& operator=( float n );
2666- Integer& operator=( double n );
2667- Integer& operator=( char const *s );
2668- Integer& operator=( Decimal const &d );
2669- Integer& operator=( Double const &d );
2670- Integer& operator=( Float const &f );
2671- Integer& operator=( Integer const &i );
2672+ IntegerImpl& operator=( char c );
2673+ IntegerImpl& operator=( signed char c );
2674+ IntegerImpl& operator=( short n );
2675+ IntegerImpl& operator=( int n );
2676+ IntegerImpl& operator=( long n );
2677+ IntegerImpl& operator=( long long n );
2678+ IntegerImpl& operator=( unsigned char c );
2679+ IntegerImpl& operator=( unsigned short n );
2680+ IntegerImpl& operator=( unsigned int n );
2681+ IntegerImpl& operator=( unsigned long n );
2682+ IntegerImpl& operator=( unsigned long long n );
2683+ IntegerImpl& operator=( float n );
2684+ IntegerImpl& operator=( double n );
2685+ IntegerImpl& operator=( char const *s );
2686+ IntegerImpl& operator=( Decimal const &d );
2687+ IntegerImpl& operator=( Double const &d );
2688+ IntegerImpl& operator=( Float const &f );
2689+
2690+ TEMPLATE_DECL(U)
2691+ IntegerImpl& operator=( INTEGER_IMPL(U) const &i );
2692
2693 ////////// arithmetic operators /////////////////////////////////////////////
2694
2695- friend Integer operator+( Integer const &i, Integer const &j );
2696- friend Integer operator-( Integer const &i, Integer const &j );
2697- friend Integer operator*( Integer const &i, Integer const &j );
2698- friend Integer operator/( Integer const &i, Integer const &j );
2699- friend Integer operator%( Integer const &i, Integer const &j );
2700-
2701- friend Decimal operator+( Integer const &i, Decimal const &d );
2702- friend Decimal operator-( Integer const &i, Decimal const &d );
2703- friend Decimal operator*( Integer const &i, Decimal const &d );
2704- friend Decimal operator/( Integer const &i, Decimal const &d );
2705- friend Decimal operator%( Integer const &i, Decimal const &d );
2706-
2707- friend Decimal operator+( Decimal const &d, Integer const &i );
2708- friend Decimal operator-( Decimal const &d, Integer const &i );
2709- friend Decimal operator*( Decimal const &d, Integer const &i );
2710- friend Decimal operator/( Decimal const &d, Integer const &i );
2711- friend Decimal operator%( Decimal const &d, Integer const &i );
2712-
2713- Integer& operator+=( Integer const &i );
2714- Integer& operator-=( Integer const &i );
2715- Integer& operator*=( Integer const &i );
2716- Integer& operator/=( Integer const &i );
2717- Integer& operator%=( Integer const &i );
2718-
2719- Integer operator-() const;
2720-
2721- Integer& operator++();
2722- Integer operator++(int);
2723- Integer& operator--();
2724- Integer operator--(int);
2725+#define ZORBA_INTEGER_OP(OP) \
2726+ TEMPLATE_DECL(T) friend \
2727+ INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const&, \
2728+ INTEGER_IMPL(T) const& ); \
2729+ TEMPLATE_DECL(T) friend \
2730+ Decimal operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \
2731+ TEMPLATE_DECL(T) friend \
2732+ Decimal operator OP( Decimal const&, INTEGER_IMPL(T) const& )
2733+
2734+ ZORBA_INTEGER_OP(+);
2735+ ZORBA_INTEGER_OP(-);
2736+ ZORBA_INTEGER_OP(*);
2737+ ZORBA_INTEGER_OP(/);
2738+ ZORBA_INTEGER_OP(%);
2739+#undef ZORBA_INTEGER_OP
2740+
2741+ IntegerImpl& operator+=( IntegerImpl const& );
2742+ IntegerImpl& operator-=( IntegerImpl const& );
2743+ IntegerImpl& operator*=( IntegerImpl const& );
2744+ IntegerImpl& operator/=( IntegerImpl const& );
2745+ IntegerImpl& operator%=( IntegerImpl const& );
2746+
2747+ IntegerImpl operator-() const;
2748+
2749+ IntegerImpl& operator++();
2750+ IntegerImpl operator++(int);
2751+ IntegerImpl& operator--();
2752+ IntegerImpl operator--(int);
2753
2754 ////////// relational operators /////////////////////////////////////////////
2755
2756- friend bool operator==( Integer const &i, Integer const &j );
2757- friend bool operator!=( Integer const &i, Integer const &j );
2758- friend bool operator< ( Integer const &i, Integer const &j );
2759- friend bool operator<=( Integer const &i, Integer const &j );
2760- friend bool operator> ( Integer const &i, Integer const &j );
2761- friend bool operator>=( Integer const &i, Integer const &j );
2762-
2763- friend bool operator==( Integer const &i, Decimal const &d );
2764- friend bool operator!=( Integer const &i, Decimal const &d );
2765- friend bool operator< ( Integer const &i, Decimal const &d );
2766- friend bool operator<=( Integer const &i, Decimal const &d );
2767- friend bool operator> ( Integer const &i, Decimal const &d );
2768- friend bool operator>=( Integer const &i, Decimal const &d );
2769-
2770- friend bool operator==( Decimal const &d, Integer const &i );
2771- friend bool operator!=( Decimal const &d, Integer const &i );
2772- friend bool operator< ( Decimal const &d, Integer const &i );
2773- friend bool operator<=( Decimal const &d, Integer const &i );
2774- friend bool operator> ( Decimal const &d, Integer const &i );
2775- friend bool operator>=( Decimal const &d, Integer const &i );
2776+#define ZORBA_INTEGER_OP(OP) \
2777+ TEMPLATE_DECL(T) friend \
2778+ bool operator OP( INTEGER_IMPL(T) const&, INTEGER_IMPL(T) const& ); \
2779+ TEMPLATE_DECL(T) friend \
2780+ bool operator OP( INTEGER_IMPL(T) const&, Decimal const& ); \
2781+ TEMPLATE_DECL(T) friend \
2782+ bool operator OP( Decimal const&, INTEGER_IMPL(T) const& )
2783+
2784+ ZORBA_INTEGER_OP(==);
2785+ ZORBA_INTEGER_OP(!=);
2786+ ZORBA_INTEGER_OP(< );
2787+ ZORBA_INTEGER_OP(<=);
2788+ ZORBA_INTEGER_OP(> );
2789+ ZORBA_INTEGER_OP(>=);
2790+#undef ZORBA_INTEGER_OP
2791
2792 ////////// math functions ///////////////////////////////////////////////////
2793
2794- Double pow( Integer const &power ) const;
2795- Integer round( Integer const &precision ) const;
2796- Integer roundHalfToEven( Integer const &precision ) const;
2797+ Double pow( IntegerImpl const &power ) const;
2798+ IntegerImpl round( IntegerImpl const &precision ) const;
2799+ IntegerImpl roundHalfToEven( IntegerImpl const &precision ) const;
2800
2801 ////////// miscellaneous ////////////////////////////////////////////////////
2802
2803- int compare( Integer const &i ) const;
2804+ int compare( IntegerImpl const& ) const;
2805 uint32_t hash() const;
2806 int sign() const;
2807 zstring toString() const;
2808- static Integer const& one();
2809- static Integer const& zero();
2810+ static IntegerImpl const& one();
2811+ static IntegerImpl const& zero();
2812
2813 /////////////////////////////////////////////////////////////////////////////
2814
2815@@ -189,13 +199,13 @@
2816 #ifdef ZORBA_WITH_BIG_INTEGER
2817 typedef MAPM value_type;
2818 #else
2819- typedef long long value_type;
2820+ typedef IntType value_type;
2821 #endif /* ZORBA_WITH_BIG_INTEGER */
2822
2823 value_type value_;
2824
2825 #ifdef ZORBA_WITH_BIG_INTEGER
2826- Integer( value_type const &v ) : value_( v ) { }
2827+ IntegerImpl( value_type const &v ) : value_( v ) { }
2828 #endif /* ZORBA_WITH_BIG_INTEGER */
2829
2830 static value_type ftoi( double d ) {
2831@@ -227,58 +237,96 @@
2832 friend class Decimal;
2833 template<typename T> friend class FloatImpl;
2834
2835- friend xs_int to_xs_int( Integer const& );
2836- friend xs_long to_xs_long( Integer const& );
2837- friend xs_unsignedInt to_xs_unsignedInt( Integer const& );
2838- friend xs_unsignedLong to_xs_unsignedLong( Integer const& );
2839-
2840- friend void serialization::operator&(serialization::Archiver&, Integer&);
2841+#ifndef ZORBA_WITH_BIG_INTEGER
2842+ template<typename U> friend class IntegerImpl;
2843+#endif /* ZORBA_WITH_BIG_INTEGER */
2844+
2845+ friend xs_int to_xs_int( INTEGER_IMPL_LL const& );
2846+ friend xs_long to_xs_long( INTEGER_IMPL_LL const& );
2847+ friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& );
2848+ friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& );
2849+
2850+ TEMPLATE_DECL(T) friend
2851+ void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(T)& );
2852 };
2853
2854+typedef INTEGER_IMPL_LL Integer;
2855+typedef INTEGER_IMPL_ULL UInteger;
2856+
2857 ////////// constructors ///////////////////////////////////////////////////////
2858
2859-inline Integer::Integer( char c ) : value_( static_cast<long>( c ) ) {
2860-}
2861-
2862-inline Integer::Integer( signed char c ) : value_( static_cast<long>( c ) ) {
2863-}
2864-
2865-inline Integer::Integer( short n ) : value_( static_cast<long>( n ) ) {
2866-}
2867-
2868-inline Integer::Integer( int n ) : value_( static_cast<long>( n ) ) {
2869-}
2870-
2871-inline Integer::Integer( long n ) : value_( n ) {
2872-}
2873-
2874-#ifndef ZORBA_WITH_BIG_INTEGER
2875-inline Integer::Integer( long long n ) : value_( n ) {
2876-}
2877-#endif /* ZORBA_WITH_BIG_INTEGER */
2878-
2879-inline Integer::Integer( unsigned char c ) : value_( static_cast<long>( c ) ) {
2880-}
2881-
2882-inline Integer::Integer( unsigned short n ) : value_( static_cast<long>( n ) ) {
2883-}
2884-
2885-inline Integer::Integer( unsigned int n ) : value_( static_cast<long>( n ) ) {
2886-}
2887-
2888-#ifndef ZORBA_WITH_BIG_INTEGER
2889-inline Integer::Integer( unsigned long n ) :
2890- value_( static_cast<value_type>( n ) )
2891-{
2892-}
2893-
2894-inline Integer::Integer( unsigned long long n ) :
2895- value_( static_cast<value_type>( n ) )
2896-{
2897-}
2898-#endif /* ZORBA_WITH_BIG_INTEGER */
2899-
2900-inline Integer::Integer( float n ) :
2901+TEMPLATE_DECL(T)
2902+inline INTEGER_IMPL(T)::IntegerImpl( char c ) :
2903+ value_( static_cast<long>( c ) )
2904+{
2905+}
2906+
2907+TEMPLATE_DECL(T)
2908+inline INTEGER_IMPL(T)::IntegerImpl( signed char c ) :
2909+ value_( static_cast<long>( c ) )
2910+{
2911+}
2912+
2913+TEMPLATE_DECL(T)
2914+inline INTEGER_IMPL(T)::IntegerImpl( short n ) :
2915+ value_( static_cast<long>( n ) )
2916+{
2917+}
2918+
2919+TEMPLATE_DECL(T)
2920+inline INTEGER_IMPL(T)::IntegerImpl( int n ) :
2921+ value_( static_cast<long>( n ) )
2922+{
2923+}
2924+
2925+TEMPLATE_DECL(T)
2926+inline INTEGER_IMPL(T)::IntegerImpl( long n ) :
2927+ value_( n )
2928+{
2929+}
2930+
2931+#ifndef ZORBA_WITH_BIG_INTEGER
2932+TEMPLATE_DECL(T)
2933+inline INTEGER_IMPL(T)::IntegerImpl( long long n ) :
2934+ value_( n )
2935+{
2936+}
2937+#endif /* ZORBA_WITH_BIG_INTEGER */
2938+
2939+TEMPLATE_DECL(T)
2940+inline INTEGER_IMPL(T)::IntegerImpl( unsigned char c ) :
2941+ value_( static_cast<long>( c ) )
2942+{
2943+}
2944+
2945+TEMPLATE_DECL(T)
2946+inline INTEGER_IMPL(T)::IntegerImpl( unsigned short n ) :
2947+ value_( static_cast<long>( n ) )
2948+{
2949+}
2950+
2951+TEMPLATE_DECL(T)
2952+inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) :
2953+ value_( static_cast<long>( n ) )
2954+{
2955+}
2956+
2957+#ifndef ZORBA_WITH_BIG_INTEGER
2958+TEMPLATE_DECL(T)
2959+inline INTEGER_IMPL(T)::IntegerImpl( unsigned long n ) :
2960+ value_( static_cast<value_type>( n ) )
2961+{
2962+}
2963+
2964+TEMPLATE_DECL(T)
2965+inline INTEGER_IMPL(T)::IntegerImpl( unsigned long long n ) :
2966+ value_( static_cast<value_type>( n ) )
2967+{
2968+}
2969+#endif /* ZORBA_WITH_BIG_INTEGER */
2970+
2971+TEMPLATE_DECL(T)
2972+inline INTEGER_IMPL(T)::IntegerImpl( float n ) :
2973 #ifdef ZORBA_WITH_BIG_INTEGER
2974 value_( static_cast<double>( n ) )
2975 #else
2976@@ -287,7 +335,8 @@
2977 {
2978 }
2979
2980-inline Integer::Integer( double n ) :
2981+TEMPLATE_DECL(T)
2982+inline INTEGER_IMPL(T)::IntegerImpl( double n ) :
2983 #ifdef ZORBA_WITH_BIG_INTEGER
2984 value_( n )
2985 #else
2986@@ -296,240 +345,252 @@
2987 {
2988 }
2989
2990-inline Integer::Integer( char const *s ) {
2991+TEMPLATE_DECL(T)
2992+inline INTEGER_IMPL(T)::IntegerImpl( char const *s ) {
2993 parse( s );
2994 }
2995
2996-inline Integer::Integer( Integer const &i ) :
2997+TEMPLATE_DECL(T)
2998+TEMPLATE_DECL(U)
2999+inline INTEGER_IMPL(T)::IntegerImpl( INTEGER_IMPL(U) const &i ) :
3000 value_( i.value_ )
3001 {
3002 }
3003
3004 ////////// assignment operators ///////////////////////////////////////////////
3005
3006-inline Integer& Integer::operator=( char c ) {
3007- value_ = static_cast<long>( c );
3008- return *this;
3009-}
3010-
3011-inline Integer& Integer::operator=( signed char c ) {
3012- value_ = static_cast<long>( c );
3013- return *this;
3014-}
3015-
3016-inline Integer& Integer::operator=( short n ) {
3017- value_ = static_cast<long>( n );
3018- return *this;
3019-}
3020-
3021-inline Integer& Integer::operator=( int n ) {
3022- value_ = static_cast<long>( n );
3023- return *this;
3024-}
3025-
3026-inline Integer& Integer::operator=( long n ) {
3027- value_ = n;
3028- return *this;
3029-}
3030-
3031-#ifndef ZORBA_WITH_BIG_INTEGER
3032-inline Integer& Integer::operator=( long long n ) {
3033- value_ = n;
3034- return *this;
3035-}
3036-#endif /* ZORBA_WITH_BIG_INTEGER */
3037-
3038-inline Integer& Integer::operator=( unsigned char c ) {
3039- value_ = static_cast<long>( c );
3040- return *this;
3041-}
3042-
3043-inline Integer& Integer::operator=( unsigned short n ) {
3044- value_ = static_cast<long>( n );
3045- return *this;
3046-}
3047-
3048-inline Integer& Integer::operator=( unsigned int n ) {
3049- value_ = static_cast<long>( n );
3050- return *this;
3051-}
3052-
3053-#ifndef ZORBA_WITH_BIG_INTEGER
3054-inline Integer& Integer::operator=( unsigned long n ) {
3055- value_ = static_cast<long>( n );
3056- return *this;
3057-}
3058-
3059-inline Integer& Integer::operator=( unsigned long long n ) {
3060- value_ = n;
3061- return *this;
3062-}
3063-#endif /* ZORBA_WITH_BIG_INTEGER */
3064-
3065-inline Integer& Integer::operator=( float n ) {
3066- value_ = static_cast<long>( n );
3067- return *this;
3068-}
3069-
3070-inline Integer& Integer::operator=( double n ) {
3071- value_ = static_cast<long>( n );
3072- return *this;
3073-}
3074-
3075-inline Integer& Integer::operator=( char const *s ) {
3076+TEMPLATE_DECL(T)
3077+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char c ) {
3078+ value_ = static_cast<long>( c );
3079+ return *this;
3080+}
3081+
3082+TEMPLATE_DECL(T)
3083+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( signed char c ) {
3084+ value_ = static_cast<long>( c );
3085+ return *this;
3086+}
3087+
3088+TEMPLATE_DECL(T)
3089+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( short n ) {
3090+ value_ = static_cast<long>( n );
3091+ return *this;
3092+}
3093+
3094+TEMPLATE_DECL(T)
3095+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( int n ) {
3096+ value_ = static_cast<long>( n );
3097+ return *this;
3098+}
3099+
3100+TEMPLATE_DECL(T)
3101+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long n ) {
3102+ value_ = n;
3103+ return *this;
3104+}
3105+
3106+#ifndef ZORBA_WITH_BIG_INTEGER
3107+TEMPLATE_DECL(T)
3108+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( long long n ) {
3109+ value_ = n;
3110+ return *this;
3111+}
3112+#endif /* ZORBA_WITH_BIG_INTEGER */
3113+
3114+TEMPLATE_DECL(T)
3115+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned char c ) {
3116+ value_ = static_cast<long>( c );
3117+ return *this;
3118+}
3119+
3120+TEMPLATE_DECL(T)
3121+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned short n ) {
3122+ value_ = static_cast<long>( n );
3123+ return *this;
3124+}
3125+
3126+TEMPLATE_DECL(T)
3127+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned int n ) {
3128+ value_ = static_cast<long>( n );
3129+ return *this;
3130+}
3131+
3132+#ifndef ZORBA_WITH_BIG_INTEGER
3133+TEMPLATE_DECL(T)
3134+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long n ) {
3135+ value_ = static_cast<long>( n );
3136+ return *this;
3137+}
3138+
3139+TEMPLATE_DECL(T)
3140+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( unsigned long long n ) {
3141+ value_ = n;
3142+ return *this;
3143+}
3144+#endif /* ZORBA_WITH_BIG_INTEGER */
3145+
3146+TEMPLATE_DECL(T)
3147+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( float n ) {
3148+ value_ = static_cast<long>( n );
3149+ return *this;
3150+}
3151+
3152+TEMPLATE_DECL(T)
3153+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( double n ) {
3154+ value_ = static_cast<long>( n );
3155+ return *this;
3156+}
3157+
3158+TEMPLATE_DECL(T)
3159+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( char const *s ) {
3160 parse( s );
3161 return *this;
3162 }
3163
3164-inline Integer& Integer::operator=( Integer const &i ) {
3165+TEMPLATE_DECL(T)
3166+TEMPLATE_DECL(U)
3167+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( INTEGER_IMPL(U) const &i ) {
3168 value_ = i.value_;
3169 return *this;
3170 }
3171
3172 ////////// arithmetic operators ///////////////////////////////////////////////
3173
3174-inline Integer operator+( Integer const &i, Integer const &j ) {
3175- return i.value_ + j.value_;
3176-}
3177-
3178-inline Integer operator-( Integer const &i, Integer const &j ) {
3179- return i.value_ - j.value_;
3180-}
3181-
3182-inline Integer operator*( Integer const &i, Integer const &j ) {
3183- return i.value_ * j.value_;
3184-}
3185-
3186-inline Integer operator/( Integer const &i, Integer const &j ) {
3187- return Integer::ftoi( i.value_ / j.value_ );
3188-}
3189-
3190-inline Integer operator%( Integer const &i, Integer const &j ) {
3191- return i.value_ % j.value_;
3192-}
3193-
3194-inline Integer& Integer::operator+=( Integer const &i ) {
3195- value_ += i.value_;
3196- return *this;
3197-}
3198-
3199-inline Integer& Integer::operator-=( Integer const &i ) {
3200- value_ -= i.value_;
3201- return *this;
3202-}
3203-
3204-inline Integer& Integer::operator*=( Integer const &i ) {
3205- value_ *= i.value_;
3206- return *this;
3207-}
3208-
3209-inline Integer& Integer::operator/=( Integer const &i ) {
3210+#define ZORBA_INTEGER_OP(OP) \
3211+ TEMPLATE_DECL(T) inline \
3212+ INTEGER_IMPL(T) operator OP( INTEGER_IMPL(T) const &i, \
3213+ INTEGER_IMPL(T) const &j ) { \
3214+ return i.value_ OP j.value_; \
3215+ }
3216+
3217+ZORBA_INTEGER_OP(+)
3218+ZORBA_INTEGER_OP(-)
3219+ZORBA_INTEGER_OP(*)
3220+ZORBA_INTEGER_OP(%)
3221+#undef ZORBA_INTEGER_OP
3222+
3223+TEMPLATE_DECL(T) inline
3224+INTEGER_IMPL(T) operator/( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) {
3225+ return INTEGER_IMPL(T)::ftoi( i.value_ / j.value_ );
3226+}
3227+
3228+#define ZORBA_INTEGER_OP(OP) \
3229+ TEMPLATE_DECL(T) inline \
3230+ INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator OP( IntegerImpl const &i ) { \
3231+ value_ OP i.value_; \
3232+ return *this; \
3233+ }
3234+
3235+ZORBA_INTEGER_OP(+=)
3236+ZORBA_INTEGER_OP(-=)
3237+ZORBA_INTEGER_OP(*=)
3238+ZORBA_INTEGER_OP(%=)
3239+#undef ZORBA_INTEGER_OP
3240+
3241+TEMPLATE_DECL(T)
3242+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator/=( IntegerImpl const &i ) {
3243 value_ = ftoi( value_ / i.value_ );
3244 return *this;
3245 }
3246
3247-inline Integer& Integer::operator%=( Integer const &i ) {
3248- value_ %= i.value_;
3249- return *this;
3250-}
3251-
3252-inline Integer Integer::operator-() const {
3253+TEMPLATE_DECL(T)
3254+inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator-() const {
3255 return -value_;
3256 }
3257
3258-inline Integer& Integer::operator++() {
3259+TEMPLATE_DECL(T)
3260+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator++() {
3261 ++value_;
3262 return *this;
3263 }
3264
3265-inline Integer Integer::operator++(int) {
3266- Integer const result( *this );
3267+TEMPLATE_DECL(T)
3268+inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator++(int) {
3269+ INTEGER_IMPL(T) const result( *this );
3270 ++value_;
3271 return result;
3272 }
3273
3274-inline Integer& Integer::operator--() {
3275+TEMPLATE_DECL(T)
3276+inline INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator--() {
3277 --value_;
3278 return *this;
3279 }
3280
3281-inline Integer Integer::operator--(int) {
3282- Integer const result( *this );
3283+TEMPLATE_DECL(T)
3284+inline INTEGER_IMPL(T) INTEGER_IMPL(T)::operator--(int) {
3285+ INTEGER_IMPL(T) const result( *this );
3286 --value_;
3287 return result;
3288 }
3289
3290 ////////// relational operators ///////////////////////////////////////////////
3291
3292-inline bool operator==( Integer const &i, Integer const &j ) {
3293- return i.value_ == j.value_;
3294-}
3295-
3296-inline bool operator!=( Integer const &i, Integer const &j ) {
3297- return i.value_ != j.value_;
3298-}
3299-
3300-inline bool operator<( Integer const &i, Integer const &j ) {
3301- return i.value_ < j.value_;
3302-}
3303-
3304-inline bool operator<=( Integer const &i, Integer const &j ) {
3305- return i.value_ <= j.value_;
3306-}
3307-
3308-inline bool operator>( Integer const &i, Integer const &j ) {
3309- return i.value_ > j.value_;
3310-}
3311-
3312-inline bool operator>=( Integer const &i, Integer const &j ) {
3313- return i.value_ >= j.value_;
3314-}
3315+#define ZORBA_INTEGER_OP(OP) \
3316+ TEMPLATE_DECL(T) inline \
3317+ bool operator OP( INTEGER_IMPL(T) const &i, INTEGER_IMPL(T) const &j ) { \
3318+ return i.value_ OP j.value_; \
3319+ }
3320+
3321+ZORBA_INTEGER_OP(==)
3322+ZORBA_INTEGER_OP(!=)
3323+ZORBA_INTEGER_OP(< )
3324+ZORBA_INTEGER_OP(<=)
3325+ZORBA_INTEGER_OP(> )
3326+ZORBA_INTEGER_OP(>=)
3327+#undef ZORBA_INTEGER_OP
3328
3329 ////////// miscellaneous //////////////////////////////////////////////////////
3330
3331 #ifdef ZORBA_WITH_BIG_INTEGER
3332
3333-inline int Integer::compare( Integer const &i ) const {
3334+inline int IntegerImpl::compare( IntegerImpl const &i ) const {
3335 return value_.compare( i.value_ );
3336 }
3337
3338-inline int Integer::sign() const {
3339+inline int IntegerImpl::sign() const {
3340 return value_.sign();
3341 }
3342
3343 #else
3344
3345-inline int Integer::compare( Integer const &i ) const {
3346- //
3347- // Note that we can't return the difference directly since it will be
3348- // truncated if it's ether > max(int) or < min(int) yielding a wrong result.
3349- //
3350- value_type const temp = value_ - i.value_;
3351- return temp < 0 ? -1 : temp > 0 ? 1 : 0;
3352+template<typename IntType>
3353+inline int IntegerImpl<IntType>::compare( IntegerImpl const &i ) const {
3354+ return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0;
3355 }
3356
3357-inline uint32_t Integer::hash() const {
3358+template<typename IntType>
3359+inline uint32_t IntegerImpl<IntType>::hash() const {
3360 return static_cast<uint32_t>( value_ );
3361 }
3362
3363-inline bool Integer::is_long() const {
3364+template<typename IntType>
3365+inline bool IntegerImpl<IntType>::is_long() const {
3366 return value_ >= std::numeric_limits<long>::min() &&
3367 value_ <= std::numeric_limits<long>::max();
3368 }
3369
3370-inline int Integer::sign() const {
3371- return value_ < 0 ? -1 : value_ > 0 ? 1 : 0;
3372+template<typename IntType>
3373+inline int IntegerImpl<IntType>::sign() const {
3374+ return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0;
3375 }
3376
3377 #endif /* ZORBA_WITH_BIG_INTEGER */
3378
3379-inline std::ostream& operator<<( std::ostream &os, Integer const &i ) {
3380+TEMPLATE_DECL(T)
3381+inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(T) const &i ) {
3382 return os << i.toString();
3383 }
3384
3385 ///////////////////////////////////////////////////////////////////////////////
3386
3387 } // namespace zorba
3388+
3389+#undef TEMPLATE_DECL
3390+#undef INTEGER_IMPL
3391+#undef INTEGER_IMPL_LL
3392+#undef INTEGER_IMPL_ULL
3393+
3394 #endif // ZORBA_INTEGER_H
3395 /*
3396 * Local variables:
3397
3398=== modified file 'src/zorbatypes/numconversions.cpp'
3399--- src/zorbatypes/numconversions.cpp 2011-06-29 20:31:44 +0000
3400+++ src/zorbatypes/numconversions.cpp 2012-02-28 18:23:19 +0000
3401@@ -33,7 +33,7 @@
3402 zstring const temp( i.toString() );
3403 return ztd::aton<xs_int>( temp.c_str() );
3404 #else
3405- return static_cast<xs_int>(i.value_);
3406+ return static_cast<xs_int>( i.value_ );
3407 #endif /* ZORBA_WITH_BIG_INTEGER */
3408 }
3409
3410@@ -56,6 +56,13 @@
3411 #endif /* ZORBA_WITH_BIG_INTEGER */
3412 }
3413
3414+#ifndef ZORBA_WITH_BIG_INTEGER
3415+xs_long to_xs_long( xs_nonNegativeInteger const &i ) {
3416+ zstring const temp( i.toString() );
3417+ return ztd::aton<xs_long>( temp.c_str() );
3418+}
3419+#endif /* ZORBA_WITH_BIG_INTEGER */
3420+
3421 xs_unsignedInt to_xs_unsignedInt( xs_integer const &i ) {
3422 #ifdef ZORBA_WITH_BIG_INTEGER
3423 zstring const temp( i.toString() );
3424
3425=== modified file 'src/zorbatypes/numconversions.h'
3426--- src/zorbatypes/numconversions.h 2011-06-29 20:31:44 +0000
3427+++ src/zorbatypes/numconversions.h 2012-02-28 18:23:19 +0000
3428@@ -64,6 +64,10 @@
3429 */
3430 xs_long to_xs_long( xs_integer const &i );
3431
3432+#ifndef ZORBA_WITH_BIG_INTEGER
3433+xs_long to_xs_long( xs_nonNegativeInteger const &i );
3434+#endif /* ZORBA_WITH_BIG_INTEGER */
3435+
3436 /**
3437 * Converts an \c xs:integer value to an \c xs:unsignedInt.
3438 *
3439
3440=== modified file 'src/zorbatypes/schema_types.h'
3441--- src/zorbatypes/schema_types.h 2011-06-24 13:38:42 +0000
3442+++ src/zorbatypes/schema_types.h 2012-02-28 18:23:19 +0000
3443@@ -46,8 +46,12 @@
3444 typedef DateTime xs_gYearMonth;
3445 typedef Base16 xs_hexBinary;
3446 typedef Integer xs_integer;
3447+typedef Integer xs_negativeInteger; // this isn't quite right
3448+typedef UInteger xs_nonNegativeInteger; // i.e., "unsigned"
3449+typedef Integer xs_nonPositiveInteger; // this isn't quite right either
3450+typedef UInteger xs_positiveInteger;
3451 typedef DateTime xs_time;
3452-typedef Integer xs_uinteger;
3453+typedef UInteger xs_uinteger; // old, deprecated name
3454 typedef Duration xs_yearMonthDuration;
3455
3456 ///////////////////////////////////////////////////////////////////////////////
3457
3458=== modified file 'src/zorbatypes/zorbatypes_decl.h'
3459--- src/zorbatypes/zorbatypes_decl.h 2011-06-14 17:26:33 +0000
3460+++ src/zorbatypes/zorbatypes_decl.h 2012-02-28 18:23:19 +0000
3461@@ -18,11 +18,23 @@
3462 #ifndef ZORBA_ZORBATYPES_DECL_H
3463 #define ZORBA_ZORBATYPES_DECL_H
3464
3465+#include <zorba/config.h>
3466+
3467 namespace zorba
3468 {
3469 /* numerics */
3470 class Decimal;
3471- class Integer;
3472+
3473+#ifdef ZORBA_WITH_BIG_INTEGER
3474+ class IntegerImpl;
3475+ typedef IntegerImpl Integer;
3476+ typedef IntegerImpl UInteger;
3477+#else
3478+ template<typename T> class IntegerImpl;
3479+ typedef IntegerImpl<long long> Integer;
3480+ typedef IntegerImpl<unsigned long long> UInteger;
3481+#endif /* ZORBA_WITH_BIG_INTEGER */
3482+
3483 template<typename T> class FloatImpl;
3484 typedef FloatImpl<double> Double;
3485 typedef FloatImpl<float> Float;
3486
3487=== modified file 'test/rbkt/Queries/CMakeLists.txt'
3488--- test/rbkt/Queries/CMakeLists.txt 2012-02-22 02:41:05 +0000
3489+++ test/rbkt/Queries/CMakeLists.txt 2012-02-28 18:23:19 +0000
3490@@ -235,15 +235,7 @@
3491 EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/PathExpr/Steps/Steps-leading-lone-slash-8a 3408285)
3492 EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/Functions/QNameFunc/NamespaceURIForPrefixFunc/K2-NamespaceURIForPrefixFunc-2 872732)
3493
3494- IF(NOT ZORBA_WITH_BIG_INTEGER)
3495- # These tests fail due to integer overflow.
3496- EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericGT/K2-NumericGT-1 3323548)
3497- EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericGT/K2-NumericGT-2 3323548)
3498- EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericLT/K2-NumericLT-1 3323548)
3499- EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericLT/K2-NumericLT-2 3323548)
3500- ENDIF(NOT ZORBA_WITH_BIG_INTEGER)
3501-
3502- IF(ZORBA_TEST_XQUERYX)
3503+ IF (ZORBA_TEST_XQUERYX)
3504
3505 EXPECTED_FAILURE(test/rbkt/w3c_testsuite/XQueryX/PathExpr/Steps/Steps-leading-lone-slash-8a 3408285)
3506
3507@@ -263,12 +255,22 @@
3508 EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQueryX/StaticTyping/STPathExpr/STSteps/STAxes/ST-Axes013 3355019)
3509 EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQueryX/StaticTyping/STPathExpr/STSteps/STAxes/ST-Axes014 3355019)
3510 EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQueryX/StaticTyping/STPathExpr/STSteps/STAxes/ST-Axes015 3355019)
3511- ENDIF(ZORBA_TEST_XQUERYX)
3512-
3513+ ENDIF (ZORBA_TEST_XQUERYX)
3514+
3515 #this is marked as expected failure because the RQ uses XQTS_1_0_3. In that version the expected result is err:FODC0004 instead of err:FODC0002.
3516 #W3C has changed the expected result for this test in the meantime: please see http://www.w3.org/Bugs/Public/show_bug.cgi?id=12542
3517 #EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQuery/Functions/NodeSeqFunc/SeqCollectionFunc/fn-collection-2 882002)
3518
3519+ IF (NOT ZORBA_WITH_BIG_INTEGER)
3520+ # These test will never pass without big integers beause the integers used
3521+ # in the queries exceed a 63-bit signed integer.
3522+ EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQuery/exprSeqTypes/SeqExprCast/K2-SeqExprCast-22 867059)
3523+ EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericLT/K2-NumericLT-1 867059)
3524+ EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericLT/K2-NumericLT-2 867059)
3525+ EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericGT/K2-NumericGT-1 867059)
3526+ EXPECTED_FAILURE (test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericGT/K2-NumericGT-2 867059)
3527+ ENDIF (NOT ZORBA_WITH_BIG_INTEGER)
3528+
3529 ENDIF (FOUND_XQTS AND NOT ZORBA_TEST_W3C_TO_SUBMIT_RESULTS)
3530
3531
3532
3533=== modified file 'test/rbkt/Queries/w3c_known_failures.txt'
3534--- test/rbkt/Queries/w3c_known_failures.txt 2012-02-02 09:56:52 +0000
3535+++ test/rbkt/Queries/w3c_known_failures.txt 2012-02-28 18:23:19 +0000
3536@@ -77,4 +77,14 @@
3537 test/rbkt/w3c_testsuite/XQuery/Functions/AllStringFunc/MatchStringFunc/MatchesFunc/caselessmatch10
3538 test/rbkt/w3c_testsuite/XQuery/Functions/AllStringFunc/MatchStringFunc/MatchesFunc/caselessmatch11
3539 test/rbkt/w3c_testsuite/XQuery/exprSeqTypes/PrologExpr/VariableProlog/ExternalVariablesWith/K2-ExternalVariablesWith-22
3540-
3541+test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFLWORExpr/ST-PITest-02
3542+test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFLWORExpr/ST-WhereExpr001
3543+test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFLWORExpr/statictyping-24
3544+test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFLWORExpr/ST-PITest-01
3545+test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFunctions/ST-Data001
3546+test/rbkt/w3c_testsuite/XQuery/SchemaImport/SchemaImportProlog/modules-schema-context
3547+test/rbkt/w3c_testsuite/XQuery/exprSeqTypes/SeqExprCast/K2-SeqExprCast-22
3548+test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericLT/K2-NumericLT-1
3549+test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericLT/K2-NumericLT-2
3550+test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericGT/K2-NumericGT-1
3551+test/rbkt/w3c_testsuite/XQuery/Operators/CompExpr/ValComp/NumericComp/NumericGT/K2-NumericGT-2

Subscribers

People subscribed via source and target branches