Merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba
- bug-1090089
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Matthias Brantner |
Approved revision: | 11447 |
Merged at revision: | 11443 |
Proposed branch: | lp:~paul-lucas/zorba/bug-1090089 |
Merge into: | lp:zorba |
Diff against target: |
5153 lines (+1559/-1216) 91 files modified
ChangeLog (+1/-0) src/api/dynamiccontextimpl.cpp (+1/-0) src/api/item.cpp (+3/-1) src/api/itemfactoryimpl.cpp (+6/-3) src/api/serialization/serializer.cpp (+1/-0) src/capi/csequence.cpp (+4/-3) src/common/shared_types.h (+12/-10) src/compiler/expression/expr.cpp (+3/-0) src/compiler/expression/expr_manager.cpp (+10/-8) src/compiler/parser/jsoniq_parser.cpp (+5/-6) src/compiler/parser/parser_helpers.h (+2/-0) src/compiler/parser/parser_y_includes.h (+6/-6) src/compiler/parser/symbol_table.cpp (+3/-0) src/compiler/parser/xquery_parser.cpp (+5/-6) src/compiler/parsetree/parsenode_print_xml_visitor.cpp (+5/-2) src/compiler/parsetree/parsenodes.cpp (+1/-0) src/compiler/parsetree/parsenodes.h (+3/-0) src/compiler/rewriter/rules/flwor_rules.cpp (+5/-3) src/compiler/rewriter/rules/fold_rules.cpp (+2/-0) src/compiler/translator/translator.cpp (+7/-4) src/functions/udf.cpp (+1/-0) src/runtime/base/plan_iterator.cpp (+4/-8) src/runtime/booleans/BooleanImpl.cpp (+1/-0) src/runtime/collections/collections_base.h (+1/-0) src/runtime/collections/collections_impl.cpp (+6/-7) src/runtime/core/arithmetic_impl.cpp (+1/-0) src/runtime/core/var_iterators.h (+1/-1) src/runtime/durations_dates_times/durations_dates_times_impl.cpp (+2/-0) src/runtime/full_text/ft_module_impl.cpp (+1/-0) src/runtime/full_text/ft_util.cpp (+1/-0) src/runtime/full_text/ftcontains_visitor.cpp (+1/-2) src/runtime/hof/dynamic_fncall_iterator.cpp (+1/-0) src/runtime/hof/fn_hof_functions_impl.cpp (+1/-0) src/runtime/indexing/index_ddl.cpp (+13/-11) src/runtime/introspection/sctx_impl.cpp (+1/-0) src/runtime/item/item_impl.cpp (+1/-0) src/runtime/json/jsoniq_functions_impl.cpp (+1/-0) src/runtime/maths/pregenerated/maths.cpp (+4/-4) src/runtime/maths/pregenerated/maths.h (+1/-0) src/runtime/numerics/NumericsImpl.cpp (+9/-7) src/runtime/numerics/format_integer.cpp (+1/-0) src/runtime/numerics/format_number.cpp (+3/-2) src/runtime/numerics/numerics_impl.cpp (+5/-3) src/runtime/random/pregenerated/random.h (+1/-0) src/runtime/sequences/pregenerated/sequences.cpp (+14/-14) src/runtime/sequences/pregenerated/sequences.h (+1/-0) src/runtime/sequences/sequences_impl.cpp (+12/-8) src/runtime/spec/maths/maths.xml (+3/-2) src/runtime/spec/random/random.xml (+4/-0) src/runtime/spec/sequences/sequences.xml (+8/-7) src/runtime/store/maps_impl.cpp (+1/-0) src/runtime/strings/strings_impl.cpp (+7/-2) src/store/api/collection.h (+1/-1) src/store/api/iterator.h (+1/-1) src/store/naive/atomic_items.cpp (+1/-1) src/store/naive/atomic_items.h (+4/-1) src/store/naive/collection.h (+1/-0) src/store/naive/collection_tree_info.h (+1/-0) src/store/naive/pul_primitives.cpp (+1/-1) src/store/naive/simple_collection.cpp (+2/-2) src/store/naive/simple_index_value.h (+1/-0) src/store/naive/simple_lazy_temp_seq.cpp (+2/-2) src/store/naive/simple_pul.cpp (+3/-6) src/store/naive/simple_temp_seq.cpp (+1/-0) src/system/globalenv.cpp (+1/-0) src/types/casting.cpp (+33/-19) src/types/schema/XercesParseUtils.cpp (+7/-4) src/util/stl_util.h (+18/-0) src/zorbaserialization/serialize_basic_types.cpp (+1/-0) src/zorbaserialization/serialize_zorba_types.cpp (+15/-20) src/zorbaserialization/serialize_zorba_types.h (+7/-18) src/zorbatypes/CMakeLists.txt (+1/-0) src/zorbatypes/datetime.h (+3/-4) src/zorbatypes/datetime/datetimetype.cpp (+9/-8) src/zorbatypes/datetime/duration.cpp (+8/-4) src/zorbatypes/datetime/timezone.cpp (+1/-0) src/zorbatypes/decimal.cpp (+63/-79) src/zorbatypes/decimal.h (+24/-36) src/zorbatypes/duration.h (+6/-6) src/zorbatypes/floatimpl.cpp (+91/-116) src/zorbatypes/floatimpl.h (+21/-36) src/zorbatypes/integer.cpp (+253/-192) src/zorbatypes/integer.h (+553/-483) src/zorbatypes/numconversions.cpp (+8/-1) src/zorbatypes/numconversions.h (+2/-0) src/zorbatypes/numeric_types.cpp (+82/-0) src/zorbatypes/numeric_types.h (+106/-0) src/zorbatypes/schema_types.h (+26/-25) src/zorbatypes/timezone.h (+1/-1) src/zorbatypes/zorbatypes_decl.h (+1/-17) test/fots/CMakeLists.txt (+2/-2) |
To merge this branch: | bzr merge lp:~paul-lucas/zorba/bug-1090089 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+160962@code.launchpad.net |
Commit message
Completely reworked the implementation of Integer so that it now correctly handles xs:integer, xs:negativeInteger, xs:nonNegativeI
Also cleaned-up #includes for Zorba classes so as to reduce uncessary #includes.
This is an intermediate merge proposal just go get all of the above changes in. The actual fix for distinct-values() will come later depending on the outcome of the thread posted to zorba-dev.
Description of the change
Completely reworked the implementation of Integer so that it now correctly handles xs:integer, xs:negativeInteger, xs:nonNegativeI
Also cleaned-up #includes for Zorba classes so as to reduce uncessary #includes.
This is an intermediate merge proposal just go get all of the above changes in. The actual fix for distinct-values() will come later depending on the outcome of the thread posted to zorba-dev.
Paul J. Lucas (paul-lucas) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-04-
final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-04-
final status was:
No tests were run - build or configure step must have failed.
Not commiting changes.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-04-
final status was:
25 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-04-
final status was:
25 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-05-
final status was:
8 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-05-
final status was:
3 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-05-
final status was:
2 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
The attempt to merge lp:~paul-lucas/zorba/bug-1090089 into lp:zorba failed. Below is the output from the failed tests.
CMake Error at /home/ceej/
Validation queue job bug-1090089-2013-05-
final status was:
1 tests did not succeed - changes not commited.
Error in read script: /home/ceej/
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1090089-2013-05-
All tests succeeded!
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.
- 11442. By Paul J. Lucas
-
Merge from trunk.
- 11443. By Paul J. Lucas
-
Cosmetic change.
- 11444. By Paul J. Lucas
-
Now always returning Integer for binary operators.
- 11445. By Paul J. Lucas
-
Merge from trunk.
- 11446. By Paul J. Lucas
-
Updated ChangeLog.
- 11447. By Paul J. Lucas
-
Undid change.
Matthias Brantner (matthias-brantner) : | # |
Matthias Brantner (matthias-brantner) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job bug-1090089-2013-05-
All tests succeeded!
Preview Diff
1 | === modified file 'ChangeLog' |
2 | --- ChangeLog 2013-05-08 03:22:27 +0000 |
3 | +++ ChangeLog 2013-05-08 15:05:31 +0000 |
4 | @@ -1,5 +1,6 @@ |
5 | Zorba - The XQuery Processor |
6 | |
7 | + |
8 | version 2.9 |
9 | |
10 | New Features: |
11 | |
12 | === modified file 'src/api/dynamiccontextimpl.cpp' |
13 | --- src/api/dynamiccontextimpl.cpp 2013-05-08 03:19:57 +0000 |
14 | +++ src/api/dynamiccontextimpl.cpp 2013-05-08 15:05:31 +0000 |
15 | @@ -27,6 +27,7 @@ |
16 | #include "types/typemanager.h" |
17 | #include "types/root_typemanager.h" |
18 | #include "types/schema/validate.h" |
19 | +#include "zorbatypes/integer.h" |
20 | |
21 | #include "api/unmarshaller.h" |
22 | #include "api/zorbaimpl.h" |
23 | |
24 | === modified file 'src/api/item.cpp' |
25 | --- src/api/item.cpp 2013-02-26 04:12:43 +0000 |
26 | +++ src/api/item.cpp 2013-05-08 15:05:31 +0000 |
27 | @@ -38,7 +38,9 @@ |
28 | #include "store/api/iterator.h" |
29 | #include "store/api/collection.h" |
30 | |
31 | -#include <zorbatypes/numconversions.h> |
32 | +#include "zorbatypes/floatimpl.h" |
33 | +#include "zorbatypes/integer.h" |
34 | +#include "zorbatypes/numconversions.h" |
35 | |
36 | namespace zorba { |
37 | |
38 | |
39 | === modified file 'src/api/itemfactoryimpl.cpp' |
40 | --- src/api/itemfactoryimpl.cpp 2013-03-27 03:30:14 +0000 |
41 | +++ src/api/itemfactoryimpl.cpp 2013-05-08 15:05:31 +0000 |
42 | @@ -25,14 +25,17 @@ |
43 | |
44 | #include "api/itemfactoryimpl.h" |
45 | |
46 | -#include "zorbatypes/duration.h" |
47 | +#include "zorbatypes/decimal.h" |
48 | +#include "zorbatypes/floatimpl.h" |
49 | +#include "zorbatypes/integer.h" |
50 | +#include "zorbatypes/schema_types.h" |
51 | |
52 | #include "system/globalenv.h" |
53 | |
54 | +#include "store/api/copymode.h" |
55 | +#include "store/api/item.h" |
56 | #include "store/api/item_factory.h" |
57 | #include "store/api/store.h" |
58 | -#include "store/api/copymode.h" |
59 | -#include "store/api/item.h" |
60 | |
61 | #include "api/unmarshaller.h" |
62 | |
63 | |
64 | === modified file 'src/api/serialization/serializer.cpp' |
65 | --- src/api/serialization/serializer.cpp 2013-04-25 02:05:20 +0000 |
66 | +++ src/api/serialization/serializer.cpp 2013-05-08 15:05:31 +0000 |
67 | @@ -39,6 +39,7 @@ |
68 | |
69 | #include "system/globalenv.h" |
70 | #include "zorbamisc/ns_consts.h" |
71 | +#include "zorbatypes/integer.h" |
72 | #include "zorbatypes/numconversions.h" |
73 | |
74 | #include "store/api/iterator.h" |
75 | |
76 | === modified file 'src/capi/csequence.cpp' |
77 | --- src/capi/csequence.cpp 2013-02-07 17:24:36 +0000 |
78 | +++ src/capi/csequence.cpp 2013-05-08 15:05:31 +0000 |
79 | @@ -18,16 +18,17 @@ |
80 | #include "capi/csequence.h" |
81 | |
82 | #include <cassert> |
83 | -#include <string.h> |
84 | +#include <cstring> |
85 | |
86 | #include <zorba/zorba.h> |
87 | #include <zorba/diagnostic_list.h> |
88 | #include <zorba/iterator.h> |
89 | #include <zorba/store_consts.h> |
90 | -#include <zorbamisc/ns_consts.h> |
91 | -#include <zorbatypes/numconversions.h> |
92 | |
93 | #include "util/string_util.h" |
94 | +#include "zorbamisc/ns_consts.h" |
95 | +#include "zorbatypes/floatimpl.h" |
96 | +#include "zorbatypes/numconversions.h" |
97 | |
98 | #include "error.h" |
99 | |
100 | |
101 | === modified file 'src/common/shared_types.h' |
102 | --- src/common/shared_types.h 2013-04-26 04:44:36 +0000 |
103 | +++ src/common/shared_types.h 2013-05-08 15:05:31 +0000 |
104 | @@ -133,18 +133,20 @@ |
105 | typedef rchandle<GMonth> GMonth_t; |
106 | |
107 | /* numerics */ |
108 | -template<typename FloatType> class FloatImpl; |
109 | +template<typename F> class FloatImpl; |
110 | typedef FloatImpl<double> Double; |
111 | typedef FloatImpl<float> Float; |
112 | -#ifdef ZORBA_WITH_BIG_INTEGER |
113 | -class IntegerImpl; |
114 | -typedef IntegerImpl Integer; |
115 | -typedef IntegerImpl UInteger; |
116 | -#else |
117 | -template<typename IntType> class IntegerImpl; |
118 | -typedef IntegerImpl<long long> Integer; |
119 | -typedef IntegerImpl<unsigned long long> UInteger; |
120 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
121 | +class integer_traits; |
122 | +class negative_traits; |
123 | +class nonNegative_traits; |
124 | +class nonPositive_traits; |
125 | +class positive_traits; |
126 | +template<class T> class IntegerImpl; |
127 | +typedef IntegerImpl<integer_traits> Integer; |
128 | +typedef IntegerImpl<negative_traits> NegativeInteger; |
129 | +typedef IntegerImpl<nonNegative_traits> NonNegativeInteger; |
130 | +typedef IntegerImpl<nonPositive_traits> NonPositiveInteger; |
131 | +typedef IntegerImpl<positive_traits> PositiveInteger; |
132 | |
133 | /* api */ |
134 | class serializer; |
135 | |
136 | === modified file 'src/compiler/expression/expr.cpp' |
137 | --- src/compiler/expression/expr.cpp 2013-03-07 10:10:10 +0000 |
138 | +++ src/compiler/expression/expr.cpp 2013-05-08 15:05:31 +0000 |
139 | @@ -49,6 +49,9 @@ |
140 | |
141 | #include "store/api/store.h" |
142 | #include "store/api/item_factory.h" |
143 | +#include "zorbatypes/decimal.h" |
144 | +#include "zorbatypes/floatimpl.h" |
145 | +#include "zorbatypes/integer.h" |
146 | |
147 | |
148 | namespace zorba |
149 | |
150 | === modified file 'src/compiler/expression/expr_manager.cpp' |
151 | --- src/compiler/expression/expr_manager.cpp 2013-04-16 20:06:08 +0000 |
152 | +++ src/compiler/expression/expr_manager.cpp 2013-05-08 15:05:31 +0000 |
153 | @@ -15,22 +15,24 @@ |
154 | */ |
155 | |
156 | #include "stdafx.h" |
157 | + |
158 | +#include "zorbatypes/decimal.h" |
159 | +#include "zorbatypes/integer.h" |
160 | + |
161 | +#include "expr.h" |
162 | #include "expr_manager.h" |
163 | - |
164 | -#include "mem_manager.h" |
165 | - |
166 | -#include "expr.h" |
167 | -#include "ftnode.h" |
168 | -#include "var_expr.h" |
169 | #include "flwor_expr.h" |
170 | #include "fo_expr.h" |
171 | #include "ft_expr.h" |
172 | +#include "ftnode.h" |
173 | #include "function_item_expr.h" |
174 | +#include "json_exprs.h" |
175 | +#include "mem_manager.h" |
176 | #include "path_expr.h" |
177 | +#include "pragma.h" |
178 | #include "script_exprs.h" |
179 | #include "update_exprs.h" |
180 | -#include "json_exprs.h" |
181 | -#include "pragma.h" |
182 | +#include "var_expr.h" |
183 | |
184 | namespace zorba |
185 | { |
186 | |
187 | === modified file 'src/compiler/parser/jsoniq_parser.cpp' |
188 | --- src/compiler/parser/jsoniq_parser.cpp 2013-04-24 17:26:02 +0000 |
189 | +++ src/compiler/parser/jsoniq_parser.cpp 2013-05-08 15:05:31 +0000 |
190 | @@ -50,14 +50,13 @@ |
191 | #pragma warning(disable: 4786) |
192 | #endif |
193 | |
194 | +#include "compiler/api/compilercb.h" |
195 | +#include "compiler/parser/parse_constants.h" |
196 | +#include "compiler/parser/parser_helpers.h" |
197 | +#include "compiler/parser/xquery_driver.h" |
198 | #include "compiler/parsetree/parsenodes.h" |
199 | -#include "compiler/parser/parse_constants.h" |
200 | -#include "compiler/api/compilercb.h" |
201 | #include "store/api/update_consts.h" |
202 | - |
203 | -#include "compiler/parser/xquery_driver.h" |
204 | - |
205 | -#include "compiler/parser/parser_helpers.h" |
206 | +#include "zorbatypes/integer.h" |
207 | |
208 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) |
209 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) |
210 | |
211 | === modified file 'src/compiler/parser/parser_helpers.h' |
212 | --- src/compiler/parser/parser_helpers.h 2013-03-16 00:58:28 +0000 |
213 | +++ src/compiler/parser/parser_helpers.h 2013-05-08 15:05:31 +0000 |
214 | @@ -23,6 +23,8 @@ |
215 | |
216 | namespace zorba { |
217 | |
218 | + class location; |
219 | + |
220 | namespace parser { |
221 | |
222 | extern const char *the_tumbling, *the_sliding, *the_start, *the_end, *the_only_end, *the_declare, *the_create; |
223 | |
224 | === modified file 'src/compiler/parser/parser_y_includes.h' |
225 | --- src/compiler/parser/parser_y_includes.h 2013-04-17 18:08:27 +0000 |
226 | +++ src/compiler/parser/parser_y_includes.h 2013-05-08 15:05:31 +0000 |
227 | @@ -60,14 +60,14 @@ |
228 | #pragma warning(disable: 4786) |
229 | #endif |
230 | |
231 | -#include "compiler/parsetree/parsenodes.h" |
232 | +#include "compiler/api/compilercb.h" |
233 | #include "compiler/parser/parse_constants.h" |
234 | -#include "compiler/api/compilercb.h" |
235 | +#include "compiler/parser/parser_helpers.h" |
236 | +#include "compiler/parser/xquery_driver.h" |
237 | +#include "compiler/parsetree/parsenodes.h" |
238 | #include "store/api/update_consts.h" |
239 | - |
240 | -#include "compiler/parser/xquery_driver.h" |
241 | - |
242 | -#include "compiler/parser/parser_helpers.h" |
243 | +#include "zorbatypes/decimal.h" |
244 | +#include "zorbatypes/integer.h" |
245 | |
246 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) |
247 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) |
248 | |
249 | === modified file 'src/compiler/parser/symbol_table.cpp' |
250 | --- src/compiler/parser/symbol_table.cpp 2013-03-25 19:47:18 +0000 |
251 | +++ src/compiler/parser/symbol_table.cpp 2013-05-08 15:05:31 +0000 |
252 | @@ -15,6 +15,9 @@ |
253 | */ |
254 | #include "stdafx.h" |
255 | |
256 | +#include "zorbatypes/decimal.h" |
257 | +#include "zorbatypes/floatimpl.h" |
258 | +#include "zorbatypes/integer.h" |
259 | #include "zorbatypes/numconversions.h" |
260 | |
261 | #include "compiler/parser/symbol_table.h" |
262 | |
263 | === modified file 'src/compiler/parser/xquery_parser.cpp' |
264 | --- src/compiler/parser/xquery_parser.cpp 2013-04-24 17:26:02 +0000 |
265 | +++ src/compiler/parser/xquery_parser.cpp 2013-05-08 15:05:31 +0000 |
266 | @@ -50,14 +50,13 @@ |
267 | #pragma warning(disable: 4786) |
268 | #endif |
269 | |
270 | +#include "compiler/api/compilercb.h" |
271 | +#include "compiler/parser/parse_constants.h" |
272 | +#include "compiler/parser/parser_helpers.h" |
273 | +#include "compiler/parser/xquery_driver.h" |
274 | #include "compiler/parsetree/parsenodes.h" |
275 | -#include "compiler/parser/parse_constants.h" |
276 | -#include "compiler/api/compilercb.h" |
277 | #include "store/api/update_consts.h" |
278 | - |
279 | -#include "compiler/parser/xquery_driver.h" |
280 | - |
281 | -#include "compiler/parser/parser_helpers.h" |
282 | +#include "zorbatypes/integer.h" |
283 | |
284 | #define SYMTAB( n ) driver.symtab.get( (off_t)n ) |
285 | #define SYMTAB_PUT( s ) driver.symtab.put( s ) |
286 | |
287 | === modified file 'src/compiler/parsetree/parsenode_print_xml_visitor.cpp' |
288 | --- src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-03-22 00:38:18 +0000 |
289 | +++ src/compiler/parsetree/parsenode_print_xml_visitor.cpp 2013-05-08 15:05:31 +0000 |
290 | @@ -16,9 +16,12 @@ |
291 | #include "stdafx.h" |
292 | |
293 | #include <ostream> |
294 | -#include "compiler/parsetree/parsenode_print_xml_visitor.h" |
295 | -#include "compiler/parsetree/parsenode_visitor.h" |
296 | + |
297 | #include "types/typemanager.h" |
298 | +#include "zorbatypes/integer.h" |
299 | + |
300 | +#include "parsenode_print_xml_visitor.h" |
301 | +#include "parsenode_visitor.h" |
302 | |
303 | using namespace std; |
304 | |
305 | |
306 | === modified file 'src/compiler/parsetree/parsenodes.cpp' |
307 | --- src/compiler/parsetree/parsenodes.cpp 2013-04-17 22:41:05 +0000 |
308 | +++ src/compiler/parsetree/parsenodes.cpp 2013-05-08 15:05:31 +0000 |
309 | @@ -29,6 +29,7 @@ |
310 | #include "compiler/parsetree/parsenodes.h" |
311 | #include "compiler/parser/parse_constants.h" |
312 | #include "compiler/parsetree/parsenode_visitor.h" |
313 | +#include "zorbatypes/integer.h" |
314 | |
315 | #include <iostream> |
316 | #include <sstream> |
317 | |
318 | === modified file 'src/compiler/parsetree/parsenodes.h' |
319 | --- src/compiler/parsetree/parsenodes.h 2013-05-08 03:19:57 +0000 |
320 | +++ src/compiler/parsetree/parsenodes.h 2013-05-08 15:05:31 +0000 |
321 | @@ -32,6 +32,9 @@ |
322 | |
323 | #include "store/api/item.h" |
324 | |
325 | +#include "zorbatypes/decimal.h" |
326 | +#include "zorbatypes/integer.h" |
327 | +#include "zorbatypes/floatimpl.h" |
328 | #include "zorbatypes/rchandle.h" |
329 | #include "zorbatypes/schema_types.h" |
330 | #include "zorbatypes/zstring.h" |
331 | |
332 | === modified file 'src/compiler/rewriter/rules/flwor_rules.cpp' |
333 | --- src/compiler/rewriter/rules/flwor_rules.cpp 2013-04-15 12:07:41 +0000 |
334 | +++ src/compiler/rewriter/rules/flwor_rules.cpp 2013-05-08 15:05:31 +0000 |
335 | @@ -37,6 +37,8 @@ |
336 | |
337 | #include "system/properties.h" |
338 | |
339 | +#include "zorbatypes/integer.h" |
340 | + |
341 | #include <memory> |
342 | #include <iterator> |
343 | |
344 | @@ -300,7 +302,7 @@ |
345 | if (pvar != NULL) |
346 | { |
347 | expr* constExpr = rCtx.theEM-> |
348 | - create_const_expr(sctx, udf, loc, xs_integer::zero()); |
349 | + create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::zero()); |
350 | |
351 | subst_vars(rCtx, pvar, constExpr, 2); |
352 | fc->set_pos_var(NULL); |
353 | @@ -318,7 +320,7 @@ |
354 | if (pvar != NULL && (domQuant == TypeConstants::QUANT_ONE || ! outerFor)) |
355 | { |
356 | expr* constExpr = rCtx.theEM-> |
357 | - create_const_expr(sctx, udf, loc, xs_integer::one()); |
358 | + create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::one()); |
359 | |
360 | subst_vars(rCtx, pvar, constExpr, 2); |
361 | fc->set_pos_var(NULL); |
362 | @@ -461,7 +463,7 @@ |
363 | // since one value is still returned, count variables are changed to 1 |
364 | subst_vars(rCtx, |
365 | static_cast<count_clause*>(clause)->get_var(), |
366 | - rCtx.theEM->create_const_expr(sctx, udf, loc, xs_integer::one()), |
367 | + rCtx.theEM->create_const_expr(sctx, udf, loc, numeric_consts<xs_integer>::one()), |
368 | 2); |
369 | |
370 | theFlwor->remove_clause(0); |
371 | |
372 | === modified file 'src/compiler/rewriter/rules/fold_rules.cpp' |
373 | --- src/compiler/rewriter/rules/fold_rules.cpp 2013-05-04 20:20:05 +0000 |
374 | +++ src/compiler/rewriter/rules/fold_rules.cpp 2013-05-08 15:05:31 +0000 |
375 | @@ -47,6 +47,8 @@ |
376 | #include "store/api/store.h" |
377 | #include "store/api/item_factory.h" |
378 | |
379 | +#include "zorbatypes/integer.h" |
380 | + |
381 | #include <iterator> |
382 | |
383 | namespace zorba { |
384 | |
385 | === modified file 'src/compiler/translator/translator.cpp' |
386 | --- src/compiler/translator/translator.cpp 2013-05-08 08:01:05 +0000 |
387 | +++ src/compiler/translator/translator.cpp 2013-05-08 15:05:31 +0000 |
388 | @@ -88,9 +88,12 @@ |
389 | #include "types/typemanagerimpl.h" |
390 | #include "types/schema/schema.h" |
391 | |
392 | +#include "zorbamisc/ns_consts.h" |
393 | +#include "zorbatypes/decimal.h" |
394 | +#include "zorbatypes/floatimpl.h" |
395 | +#include "zorbatypes/integer.h" |
396 | +#include "zorbatypes/numconversions.h" |
397 | #include "zorbatypes/URI.h" |
398 | -#include "zorbatypes/numconversions.h" |
399 | -#include "zorbamisc/ns_consts.h" |
400 | |
401 | #ifdef ZORBA_WITH_DEBUGGER |
402 | #include "debugger/debugger_commons.h" |
403 | @@ -11932,8 +11935,8 @@ |
404 | } |
405 | case FunctionConsts::FN_HEAD_1: |
406 | { |
407 | - arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, xs_integer::one())); |
408 | - arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, xs_integer::one())); |
409 | + arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, numeric_consts<xs_integer>::one())); |
410 | + arguments.push_back(CREATE(const)(theRootSctx, theUDF, loc, numeric_consts<xs_integer>::one())); |
411 | |
412 | function* f = BUILTIN_FUNC(OP_ZORBA_SUBSEQUENCE_INT_3); |
413 | |
414 | |
415 | === modified file 'src/functions/udf.cpp' |
416 | --- src/functions/udf.cpp 2013-04-24 01:35:58 +0000 |
417 | +++ src/functions/udf.cpp 2013-05-08 15:05:31 +0000 |
418 | @@ -36,6 +36,7 @@ |
419 | #include "diagnostics/assert.h" |
420 | |
421 | #include "types/typeops.h" |
422 | +#include "zorbatypes/integer.h" |
423 | |
424 | #include "zorbaserialization/serialize_template_types.h" |
425 | #include "zorbaserialization/serialize_zorba_types.h" |
426 | |
427 | === modified file 'src/runtime/base/plan_iterator.cpp' |
428 | --- src/runtime/base/plan_iterator.cpp 2013-03-24 20:40:03 +0000 |
429 | +++ src/runtime/base/plan_iterator.cpp 2013-05-08 15:05:31 +0000 |
430 | @@ -15,18 +15,14 @@ |
431 | */ |
432 | #include "stdafx.h" |
433 | |
434 | +#include "compiler/api/compilercb.h" |
435 | #include "context/static_context.h" |
436 | - |
437 | -#include "compiler/api/compilercb.h" |
438 | - |
439 | #include "runtime/base/plan_iterator.h" |
440 | - |
441 | #include "runtime/util/flowctl_exception.h" |
442 | - |
443 | +#include "store/api/item_factory.h" |
444 | +#include "store/api/store.h" |
445 | #include "system/globalenv.h" |
446 | - |
447 | -#include "store/api/store.h" |
448 | -#include "store/api/item_factory.h" |
449 | +#include "zorbatypes/integer.h" |
450 | |
451 | |
452 | namespace zorba |
453 | |
454 | === modified file 'src/runtime/booleans/BooleanImpl.cpp' |
455 | --- src/runtime/booleans/BooleanImpl.cpp 2013-05-02 00:18:56 +0000 |
456 | +++ src/runtime/booleans/BooleanImpl.cpp 2013-05-08 15:05:31 +0000 |
457 | @@ -20,6 +20,7 @@ |
458 | |
459 | #include "zorbatypes/collation_manager.h" |
460 | #include "zorbatypes/datetime.h" |
461 | +#include "zorbatypes/integer.h" |
462 | |
463 | #include "system/globalenv.h" |
464 | |
465 | |
466 | === modified file 'src/runtime/collections/collections_base.h' |
467 | --- src/runtime/collections/collections_base.h 2013-02-07 17:24:36 +0000 |
468 | +++ src/runtime/collections/collections_base.h 2013-05-08 15:05:31 +0000 |
469 | @@ -31,6 +31,7 @@ |
470 | #include "types/typeimpl.h" |
471 | |
472 | #include "diagnostics/util_macros.h" |
473 | +#include "zorbatypes/integer.h" |
474 | |
475 | |
476 | namespace zorba { |
477 | |
478 | === modified file 'src/runtime/collections/collections_impl.cpp' |
479 | --- src/runtime/collections/collections_impl.cpp 2013-03-24 20:40:03 +0000 |
480 | +++ src/runtime/collections/collections_impl.cpp 2013-05-08 15:05:31 +0000 |
481 | @@ -307,9 +307,9 @@ |
482 | lSkip = lSkipItem->getIntegerValue(); |
483 | |
484 | // negative skip is not allowed |
485 | - if (lSkip < xs_integer::zero()) |
486 | + if (lSkip.sign() < 0) |
487 | { |
488 | - lSkip = xs_integer::zero(); |
489 | + lSkip = numeric_consts<xs_integer>::zero(); |
490 | } |
491 | |
492 | if (!lRefPassed) |
493 | @@ -381,11 +381,10 @@ |
494 | // skip parameter passed |
495 | store::Item_t skipItem; |
496 | consumeNext(skipItem, theChildren[1].getp(), planState); |
497 | - xs_integer skip = skipItem->getIntegerValue(); |
498 | - |
499 | - count -= (skip <= xs_integer::zero() ? xs_integer::zero() : skip); |
500 | - |
501 | - count = (count < xs_integer::zero() ? xs_integer::zero() : count); |
502 | + xs_integer skip( skipItem->getIntegerValue() ); |
503 | + |
504 | + count -= (skip.sign() <= 0 ? numeric_consts<xs_integer>::zero() : skip); |
505 | + count = (count.sign() < 0 ? numeric_consts<xs_integer>::zero() : count); |
506 | } |
507 | |
508 | STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, count), state); |
509 | |
510 | === modified file 'src/runtime/core/arithmetic_impl.cpp' |
511 | --- src/runtime/core/arithmetic_impl.cpp 2013-04-08 21:32:54 +0000 |
512 | +++ src/runtime/core/arithmetic_impl.cpp 2013-05-08 15:05:31 +0000 |
513 | @@ -21,6 +21,7 @@ |
514 | #include "diagnostics/util_macros.h" |
515 | |
516 | #include "zorbatypes/datetime.h" |
517 | +#include "zorbatypes/decimal.h" |
518 | #include "zorbatypes/duration.h" |
519 | |
520 | #include "system/globalenv.h" |
521 | |
522 | === modified file 'src/runtime/core/var_iterators.h' |
523 | --- src/runtime/core/var_iterators.h 2013-05-08 08:01:05 +0000 |
524 | +++ src/runtime/core/var_iterators.h 2013-05-08 15:05:31 +0000 |
525 | @@ -23,7 +23,7 @@ |
526 | #include "runtime/base/unarybase.h" |
527 | #include "runtime/base/narybase.h" |
528 | |
529 | -#include "zorbatypes/schema_types.h" |
530 | +#include "zorbatypes/integer.h" |
531 | |
532 | |
533 | namespace zorba |
534 | |
535 | === modified file 'src/runtime/durations_dates_times/durations_dates_times_impl.cpp' |
536 | --- src/runtime/durations_dates_times/durations_dates_times_impl.cpp 2013-02-07 17:24:36 +0000 |
537 | +++ src/runtime/durations_dates_times/durations_dates_times_impl.cpp 2013-05-08 15:05:31 +0000 |
538 | @@ -17,6 +17,8 @@ |
539 | |
540 | #include "zorbatypes/datetime.h" |
541 | #include "zorbatypes/duration.h" |
542 | +#include "zorbatypes/decimal.h" |
543 | +#include "zorbatypes/integer.h" |
544 | #include "zorbatypes/numconversions.h" |
545 | #include "zorbatypes/datetime/parse.h" |
546 | |
547 | |
548 | === modified file 'src/runtime/full_text/ft_module_impl.cpp' |
549 | --- src/runtime/full_text/ft_module_impl.cpp 2013-04-16 22:12:03 +0000 |
550 | +++ src/runtime/full_text/ft_module_impl.cpp 2013-05-08 15:05:31 +0000 |
551 | @@ -46,6 +46,7 @@ |
552 | #include "types/typeops.h" |
553 | #include "util/stl_util.h" |
554 | #include "util/utf8_util.h" |
555 | +#include "zorbatypes/integer.h" |
556 | #include "zorbatypes/URI.h" |
557 | #include "zorbautils/locale.h" |
558 | |
559 | |
560 | === modified file 'src/runtime/full_text/ft_util.cpp' |
561 | --- src/runtime/full_text/ft_util.cpp 2013-02-07 17:24:36 +0000 |
562 | +++ src/runtime/full_text/ft_util.cpp 2013-05-08 15:05:31 +0000 |
563 | @@ -20,6 +20,7 @@ |
564 | |
565 | #include "diagnostics/xquery_diagnostics.h" |
566 | #include "zorbamisc/ns_consts.h" |
567 | +#include "zorbatypes/integer.h" |
568 | #include "zorbatypes/numconversions.h" |
569 | #include "zorbautils/locale.h" |
570 | |
571 | |
572 | === modified file 'src/runtime/full_text/ftcontains_visitor.cpp' |
573 | --- src/runtime/full_text/ftcontains_visitor.cpp 2013-02-07 17:24:36 +0000 |
574 | +++ src/runtime/full_text/ftcontains_visitor.cpp 2013-05-08 15:05:31 +0000 |
575 | @@ -24,12 +24,11 @@ |
576 | #include "compiler/parser/query_loc.h" |
577 | #include "diagnostics/xquery_diagnostics.h" |
578 | #include "store/api/store.h" |
579 | - |
580 | #include "system/globalenv.h" |
581 | - |
582 | #include "util/cxx_util.h" |
583 | #include "util/indent.h" |
584 | #include "util/stl_util.h" |
585 | +#include "zorbatypes/integer.h" |
586 | |
587 | #ifndef NDEBUG |
588 | #include "system/properties.h" |
589 | |
590 | === modified file 'src/runtime/hof/dynamic_fncall_iterator.cpp' |
591 | --- src/runtime/hof/dynamic_fncall_iterator.cpp 2013-05-05 04:49:50 +0000 |
592 | +++ src/runtime/hof/dynamic_fncall_iterator.cpp 2013-05-08 15:05:31 +0000 |
593 | @@ -34,6 +34,7 @@ |
594 | #include "types/root_typemanager.h" |
595 | #include "types/casting.h" |
596 | #include "types/typeops.h" |
597 | +#include "zorbatypes/integer.h" |
598 | |
599 | #include "system/globalenv.h" |
600 | |
601 | |
602 | === modified file 'src/runtime/hof/fn_hof_functions_impl.cpp' |
603 | --- src/runtime/hof/fn_hof_functions_impl.cpp 2013-04-24 01:35:58 +0000 |
604 | +++ src/runtime/hof/fn_hof_functions_impl.cpp 2013-05-08 15:05:31 +0000 |
605 | @@ -42,6 +42,7 @@ |
606 | #include "system/globalenv.h" |
607 | |
608 | #include "zorbamisc/ns_consts.h" |
609 | +#include "zorbatypes/integer.h" |
610 | |
611 | |
612 | #include "compiler/expression/expr_manager.h" |
613 | |
614 | === modified file 'src/runtime/indexing/index_ddl.cpp' |
615 | --- src/runtime/indexing/index_ddl.cpp 2013-03-24 20:40:03 +0000 |
616 | +++ src/runtime/indexing/index_ddl.cpp 2013-05-08 15:05:31 +0000 |
617 | @@ -34,6 +34,8 @@ |
618 | #include "types/typeimpl.h" |
619 | #include "types/typeops.h" |
620 | #include "types/casting.h" |
621 | +#include "zorbatypes/decimal.h" |
622 | +#include "zorbatypes/integer.h" |
623 | |
624 | #include "context/static_context.h" |
625 | #include "context/dynamic_context.h" |
626 | @@ -623,7 +625,7 @@ |
627 | PlanState& planState) const |
628 | { |
629 | store::IndexCondition_t cond; |
630 | - xs_integer skip = xs_integer::zero(); |
631 | + xs_integer skip( numeric_consts<xs_integer>::zero() ); |
632 | |
633 | try |
634 | { |
635 | @@ -641,8 +643,8 @@ |
636 | store::Item_t skipItem; |
637 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
638 | skip = skipItem->getIntegerValue(); |
639 | - if (skip < xs_integer::zero()) |
640 | - skip = xs_integer::zero(); |
641 | + if (skip.sign() < 0) |
642 | + skip = numeric_consts<xs_integer>::zero(); |
643 | } |
644 | |
645 | state->theIterator->init(cond, skip); |
646 | @@ -687,8 +689,8 @@ |
647 | store::Item_t skipItem; |
648 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
649 | skip = skipItem->getIntegerValue(); |
650 | - if (skip < xs_integer::zero()) |
651 | - skip = xs_integer::zero(); |
652 | + if (skip.sign() < 0) |
653 | + skip = numeric_consts<xs_integer>::zero(); |
654 | } |
655 | |
656 | state->theIterator->init(cond, skip); |
657 | @@ -1071,7 +1073,7 @@ |
658 | PlanState& planState) const |
659 | { |
660 | store::IndexCondition_t cond; |
661 | - xs_integer skip = xs_integer::zero(); |
662 | + xs_integer skip( numeric_consts<xs_integer>::zero() ); |
663 | |
664 | try |
665 | { |
666 | @@ -1087,8 +1089,8 @@ |
667 | store::Item_t skipItem; |
668 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
669 | skip = skipItem->getIntegerValue(); |
670 | - if (skip < xs_integer::zero()) |
671 | - skip = xs_integer::zero(); |
672 | + if (skip.sign() < 0) |
673 | + skip = numeric_consts<xs_integer>::zero(); |
674 | } |
675 | |
676 | state->theIterator->init(cond, skip); |
677 | @@ -1114,7 +1116,7 @@ |
678 | PlanState& planState) const |
679 | { |
680 | store::IndexCondition_t cond; |
681 | - xs_integer skip = xs_integer::zero(); |
682 | + xs_integer skip( numeric_consts<xs_integer>::zero() ); |
683 | |
684 | try |
685 | { |
686 | @@ -1130,8 +1132,8 @@ |
687 | store::Item_t skipItem; |
688 | ZORBA_ASSERT(consumeNext(skipItem, theChildren[1], planState)); |
689 | skip = skipItem->getIntegerValue(); |
690 | - if (skip < xs_integer::zero()) |
691 | - skip = xs_integer::zero(); |
692 | + if (skip.sign() < 0) |
693 | + skip = numeric_consts<xs_integer>::zero(); |
694 | } |
695 | |
696 | state->theIterator->init(cond, skip); |
697 | |
698 | === modified file 'src/runtime/introspection/sctx_impl.cpp' |
699 | --- src/runtime/introspection/sctx_impl.cpp 2013-02-07 17:24:36 +0000 |
700 | +++ src/runtime/introspection/sctx_impl.cpp 2013-05-08 15:05:31 +0000 |
701 | @@ -19,6 +19,7 @@ |
702 | |
703 | #include "diagnostics/assert.h" |
704 | #include "diagnostics/xquery_diagnostics.h" |
705 | +#include "zorbatypes/integer.h" |
706 | #include "zorbatypes/numconversions.h" |
707 | |
708 | #include "system/globalenv.h" |
709 | |
710 | === modified file 'src/runtime/item/item_impl.cpp' |
711 | --- src/runtime/item/item_impl.cpp 2012-07-17 18:47:54 +0000 |
712 | +++ src/runtime/item/item_impl.cpp 2013-05-08 15:05:31 +0000 |
713 | @@ -25,6 +25,7 @@ |
714 | #include "store/api/store.h" |
715 | |
716 | #include "util/mem_sizeof.h" |
717 | +#include "zorbatypes/integer.h" |
718 | |
719 | using namespace std; |
720 | |
721 | |
722 | === modified file 'src/runtime/json/jsoniq_functions_impl.cpp' |
723 | --- src/runtime/json/jsoniq_functions_impl.cpp 2013-05-05 04:49:50 +0000 |
724 | +++ src/runtime/json/jsoniq_functions_impl.cpp 2013-05-08 15:05:31 +0000 |
725 | @@ -46,6 +46,7 @@ |
726 | #include "types/typeimpl.h" |
727 | #include "types/typeops.h" |
728 | #include "types/root_typemanager.h" |
729 | +#include "zorbatypes/integer.h" |
730 | |
731 | #include <runtime/util/doc_uri_heuristics.h> |
732 | |
733 | |
734 | === modified file 'src/runtime/maths/pregenerated/maths.cpp' |
735 | --- src/runtime/maths/pregenerated/maths.cpp 2013-03-05 23:11:50 +0000 |
736 | +++ src/runtime/maths/pregenerated/maths.cpp 2013-05-08 15:05:31 +0000 |
737 | @@ -640,12 +640,12 @@ |
738 | |
739 | void ModfIteratorState::init(PlanState& planState) { |
740 | PlanIteratorState::init(planState); |
741 | - theDoubInteger = xs_double::zero(); |
742 | + theDoubInteger = numeric_consts<xs_double>::zero(); |
743 | } |
744 | |
745 | void ModfIteratorState::reset(PlanState& planState) { |
746 | PlanIteratorState::reset(planState); |
747 | - theDoubInteger = xs_double::zero(); |
748 | + theDoubInteger = numeric_consts<xs_double>::zero(); |
749 | } |
750 | // </ModfIterator> |
751 | |
752 | @@ -678,12 +678,12 @@ |
753 | |
754 | void FrexpIteratorState::init(PlanState& planState) { |
755 | PlanIteratorState::init(planState); |
756 | - theIntExponent = xs_integer::zero(); |
757 | + theIntExponent = numeric_consts<xs_integer>::zero(); |
758 | } |
759 | |
760 | void FrexpIteratorState::reset(PlanState& planState) { |
761 | PlanIteratorState::reset(planState); |
762 | - theIntExponent = xs_integer::zero(); |
763 | + theIntExponent = numeric_consts<xs_integer>::zero(); |
764 | } |
765 | // </FrexpIterator> |
766 | |
767 | |
768 | === modified file 'src/runtime/maths/pregenerated/maths.h' |
769 | --- src/runtime/maths/pregenerated/maths.h 2013-03-05 23:11:50 +0000 |
770 | +++ src/runtime/maths/pregenerated/maths.h 2013-05-08 15:05:31 +0000 |
771 | @@ -29,6 +29,7 @@ |
772 | #include "runtime/base/binarybase.h" |
773 | #include "runtime/base/noarybase.h" |
774 | |
775 | +#include "zorbatypes/integer.h" |
776 | #include "zorbatypes/schema_types.h" |
777 | |
778 | |
779 | |
780 | === modified file 'src/runtime/numerics/NumericsImpl.cpp' |
781 | --- src/runtime/numerics/NumericsImpl.cpp 2013-02-07 17:24:36 +0000 |
782 | +++ src/runtime/numerics/NumericsImpl.cpp 2013-05-08 15:05:31 +0000 |
783 | @@ -20,6 +20,8 @@ |
784 | #include "diagnostics/assert.h" |
785 | #include "diagnostics/util_macros.h" |
786 | #include "diagnostics/xquery_diagnostics.h" |
787 | +#include "zorbatypes/decimal.h" |
788 | +#include "zorbatypes/integer.h" |
789 | #include "zorbatypes/zorbatypes_decl.h" |
790 | |
791 | #include "system/globalenv.h" |
792 | @@ -393,7 +395,7 @@ |
793 | { |
794 | xs_decimal ld0 = i0->getDecimalValue(); |
795 | xs_decimal ld1 = i1->getDecimalValue(); |
796 | - if ( ld1 == Integer::zero() ) |
797 | + if ( ld1.sign() == 0 ) |
798 | { |
799 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
800 | } |
801 | @@ -412,7 +414,7 @@ |
802 | { |
803 | xs_decimal const ll0(i0->getIntegerValue()); |
804 | xs_decimal const ll1(i1->getIntegerValue()); |
805 | - if ( ll1 == Integer::zero() ) |
806 | + if ( ll1.sign() == 0 ) |
807 | { |
808 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
809 | } |
810 | @@ -435,7 +437,7 @@ |
811 | xs_double d0 = i0->getDoubleValue(); |
812 | xs_double d1 = i1->getDoubleValue(); |
813 | |
814 | - if ( d1 == xs_double::zero() ) |
815 | + if ( d1 == numeric_consts<xs_double>::zero() ) |
816 | { |
817 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
818 | } |
819 | @@ -455,7 +457,7 @@ |
820 | |
821 | if (i0->isPosOrNegInf()) { |
822 | // idiv with +-INF divisor has 0 as result |
823 | - return GENV_ITEMFACTORY->createInteger(result, Integer::zero()); |
824 | + return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
825 | } |
826 | |
827 | xs_integer const lInteger( d0 / d1 ); |
828 | @@ -474,7 +476,7 @@ |
829 | { |
830 | xs_float f0 = i0->getFloatValue(); |
831 | xs_float f1 = i1->getFloatValue(); |
832 | - if ( f1 == xs_float::zero() ) |
833 | + if ( f1 == numeric_consts<xs_float>::zero() ) |
834 | { |
835 | throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) ); |
836 | } |
837 | @@ -494,7 +496,7 @@ |
838 | if (i0->isPosOrNegInf()) |
839 | { |
840 | // idiv with +-INF divisor has 0 as result |
841 | - return GENV_ITEMFACTORY->createInteger(result, Integer::zero()); |
842 | + return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
843 | } |
844 | |
845 | xs_integer const lInteger( f0 / f1 ); |
846 | @@ -606,7 +608,7 @@ |
847 | xs_integer ll0 = i0->getIntegerValue(); |
848 | xs_integer ll1 = i1->getIntegerValue(); |
849 | |
850 | - if (ll1 == Integer::zero()) |
851 | + if ( ll1.sign() == 0 ) |
852 | { |
853 | throw XQUERY_EXCEPTION(err::FOAR0001, ERROR_LOC(loc)); |
854 | } |
855 | |
856 | === modified file 'src/runtime/numerics/format_integer.cpp' |
857 | --- src/runtime/numerics/format_integer.cpp 2013-05-04 20:27:31 +0000 |
858 | +++ src/runtime/numerics/format_integer.cpp 2013-05-08 15:05:31 +0000 |
859 | @@ -34,6 +34,7 @@ |
860 | #include "util/stream_util.h" |
861 | #include "util/unicode_util.h" |
862 | #include "util/utf8_string.h" |
863 | +#include "zorbatypes/integer.h" |
864 | #include "zorbatypes/numconversions.h" |
865 | |
866 | using namespace std; |
867 | |
868 | === modified file 'src/runtime/numerics/format_number.cpp' |
869 | --- src/runtime/numerics/format_number.cpp 2013-05-03 23:19:41 +0000 |
870 | +++ src/runtime/numerics/format_number.cpp 2013-05-08 15:05:31 +0000 |
871 | @@ -31,7 +31,8 @@ |
872 | #include "types/typeconstants.h" |
873 | #include "types/typeops.h" |
874 | #include "util/xml_util.h" |
875 | -#include "zorbatypes/zorbatypes_decl.h" |
876 | +#include "zorbatypes/floatimpl.h" |
877 | +#include "zorbatypes/integer.h" |
878 | |
879 | namespace zorba { |
880 | |
881 | @@ -258,7 +259,7 @@ |
882 | ); |
883 | |
884 | store::Item_t zero; |
885 | - GENV_ITEMFACTORY->createDouble( zero, xs_double::zero() ); |
886 | + GENV_ITEMFACTORY->createDouble( zero, numeric_consts<xs_double>::zero() ); |
887 | |
888 | // |
889 | // Ibid: [T]he positive sub-picture and its associated variables are used if |
890 | |
891 | === modified file 'src/runtime/numerics/numerics_impl.cpp' |
892 | --- src/runtime/numerics/numerics_impl.cpp 2013-04-11 17:37:16 +0000 |
893 | +++ src/runtime/numerics/numerics_impl.cpp 2013-05-08 15:05:31 +0000 |
894 | @@ -22,6 +22,8 @@ |
895 | #include "diagnostics/assert.h" |
896 | #include "diagnostics/util_macros.h" |
897 | #include "diagnostics/xquery_diagnostics.h" |
898 | +#include "zorbatypes/decimal.h" |
899 | +#include "zorbatypes/integer.h" |
900 | #include "zorbatypes/zorbatypes_decl.h" |
901 | |
902 | #include "system/globalenv.h" |
903 | @@ -97,7 +99,7 @@ |
904 | } |
905 | else if (TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE)) |
906 | { |
907 | - if (result->getIntegerValue() >= xs_decimal::zero()) |
908 | + if (result->getIntegerValue().sign() >= 0) |
909 | { |
910 | if ( !TypeOps::is_equal(tm, *type, *rtm.INTEGER_TYPE_ONE)) |
911 | GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue()); |
912 | @@ -109,7 +111,7 @@ |
913 | } |
914 | else if (TypeOps::is_subtype(tm, *type, *rtm.DECIMAL_TYPE_ONE)) |
915 | { |
916 | - if ( result->getDecimalValue() >= xs_decimal::zero()) |
917 | + if ( result->getDecimalValue().sign() >= 0) |
918 | { |
919 | if ( !TypeOps::is_equal(tm, *type, *rtm.DECIMAL_TYPE_ONE)) |
920 | GENV_ITEMFACTORY->createDecimal(result, result->getDecimalValue()); |
921 | @@ -301,7 +303,7 @@ |
922 | //item type is subtype of INTEGER |
923 | else if(TypeOps::is_subtype(tm, *type, *rtm.INTEGER_TYPE_ONE)) |
924 | { |
925 | - if(precision_integer < Integer::zero()) |
926 | + if(precision_integer.sign() < 0) |
927 | GENV_ITEMFACTORY->createInteger(result, result->getIntegerValue().round(precision_integer)); |
928 | } |
929 | |
930 | |
931 | === modified file 'src/runtime/random/pregenerated/random.h' |
932 | --- src/runtime/random/pregenerated/random.h 2013-03-05 23:11:50 +0000 |
933 | +++ src/runtime/random/pregenerated/random.h 2013-05-08 15:05:31 +0000 |
934 | @@ -29,6 +29,7 @@ |
935 | |
936 | |
937 | #include "runtime/base/narybase.h" |
938 | +#include "zorbatypes/integer.h" |
939 | |
940 | |
941 | namespace zorba { |
942 | |
943 | === modified file 'src/runtime/sequences/pregenerated/sequences.cpp' |
944 | --- src/runtime/sequences/pregenerated/sequences.cpp 2013-04-15 20:57:28 +0000 |
945 | +++ src/runtime/sequences/pregenerated/sequences.cpp 2013-05-08 15:05:31 +0000 |
946 | @@ -238,15 +238,15 @@ |
947 | |
948 | void FnInsertBeforeIteratorState::init(PlanState& planState) { |
949 | PlanIteratorState::init(planState); |
950 | - theCurrentPos = xs_integer::zero(); |
951 | - thePosition = xs_integer::zero(); |
952 | + theCurrentPos = numeric_consts<xs_integer>::zero(); |
953 | + thePosition = numeric_consts<xs_integer>::zero(); |
954 | theTargetItem = NULL; |
955 | } |
956 | |
957 | void FnInsertBeforeIteratorState::reset(PlanState& planState) { |
958 | PlanIteratorState::reset(planState); |
959 | - theCurrentPos = xs_integer::zero(); |
960 | - thePosition = xs_integer::zero(); |
961 | + theCurrentPos = numeric_consts<xs_integer>::zero(); |
962 | + thePosition = numeric_consts<xs_integer>::zero(); |
963 | theTargetItem = NULL; |
964 | } |
965 | // </FnInsertBeforeIterator> |
966 | @@ -284,15 +284,15 @@ |
967 | |
968 | void FnRemoveIteratorState::init(PlanState& planState) { |
969 | PlanIteratorState::init(planState); |
970 | - theCurrentPos = xs_integer::zero(); |
971 | - thePosition = xs_integer::zero(); |
972 | + theCurrentPos = numeric_consts<xs_integer>::zero(); |
973 | + thePosition = numeric_consts<xs_integer>::zero(); |
974 | theCollator = 0; |
975 | } |
976 | |
977 | void FnRemoveIteratorState::reset(PlanState& planState) { |
978 | PlanIteratorState::reset(planState); |
979 | - theCurrentPos = xs_integer::zero(); |
980 | - thePosition = xs_integer::zero(); |
981 | + theCurrentPos = numeric_consts<xs_integer>::zero(); |
982 | + thePosition = numeric_consts<xs_integer>::zero(); |
983 | theCollator = 0; |
984 | } |
985 | // </FnRemoveIterator> |
986 | @@ -863,16 +863,16 @@ |
987 | |
988 | void OpToIteratorState::init(PlanState& planState) { |
989 | PlanIteratorState::init(planState); |
990 | - theCurInt = xs_integer::zero(); |
991 | - theFirstVal = xs_integer::zero(); |
992 | - theLastVal = xs_integer::zero(); |
993 | + theCurInt = numeric_consts<xs_integer>::zero(); |
994 | + theFirstVal = numeric_consts<xs_integer>::zero(); |
995 | + theLastVal = numeric_consts<xs_integer>::zero(); |
996 | } |
997 | |
998 | void OpToIteratorState::reset(PlanState& planState) { |
999 | PlanIteratorState::reset(planState); |
1000 | - theCurInt = xs_integer::zero(); |
1001 | - theFirstVal = xs_integer::zero(); |
1002 | - theLastVal = xs_integer::zero(); |
1003 | + theCurInt = numeric_consts<xs_integer>::zero(); |
1004 | + theFirstVal = numeric_consts<xs_integer>::zero(); |
1005 | + theLastVal = numeric_consts<xs_integer>::zero(); |
1006 | } |
1007 | // </OpToIterator> |
1008 | |
1009 | |
1010 | === modified file 'src/runtime/sequences/pregenerated/sequences.h' |
1011 | --- src/runtime/sequences/pregenerated/sequences.h 2013-04-15 20:57:28 +0000 |
1012 | +++ src/runtime/sequences/pregenerated/sequences.h 2013-05-08 15:05:31 +0000 |
1013 | @@ -31,6 +31,7 @@ |
1014 | #include "runtime/base/narybase.h" |
1015 | #include "runtime/base/narybase.h" |
1016 | #include "runtime/core/path_iterators.h" |
1017 | +#include "zorbatypes/integer.h" |
1018 | |
1019 | |
1020 | namespace zorba { |
1021 | |
1022 | === modified file 'src/runtime/sequences/sequences_impl.cpp' |
1023 | --- src/runtime/sequences/sequences_impl.cpp 2013-05-01 23:06:33 +0000 |
1024 | +++ src/runtime/sequences/sequences_impl.cpp 2013-05-08 15:05:31 +0000 |
1025 | @@ -20,12 +20,13 @@ |
1026 | #include <vector> |
1027 | #include <sstream> |
1028 | |
1029 | -#include <zorbautils/fatal.h> |
1030 | #include "diagnostics/xquery_diagnostics.h" |
1031 | #include "diagnostics/util_macros.h" |
1032 | |
1033 | -#include <zorbatypes/URI.h> |
1034 | -#include <zorbamisc/ns_consts.h> |
1035 | +#include "zorbatypes/decimal.h" |
1036 | +#include "zorbatypes/URI.h" |
1037 | +#include "zorbamisc/ns_consts.h" |
1038 | +#include "zorbautils/fatal.h" |
1039 | |
1040 | // For timing |
1041 | #include <zorba/util/time.h> |
1042 | @@ -1599,7 +1600,10 @@ |
1043 | else |
1044 | { |
1045 | STACK_PUSH( |
1046 | - GENV_ITEMFACTORY->createInteger( result, Integer::zero() ), state |
1047 | + GENV_ITEMFACTORY->createInteger( |
1048 | + result, numeric_consts<xs_integer>::zero() |
1049 | + ), |
1050 | + state |
1051 | ); |
1052 | } |
1053 | } |
1054 | @@ -1648,7 +1652,7 @@ |
1055 | } |
1056 | else |
1057 | { |
1058 | - GENV_ITEMFACTORY->createInteger(result, Integer::zero()); |
1059 | + GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1060 | STACK_PUSH(true, state); |
1061 | } |
1062 | |
1063 | @@ -1697,7 +1701,7 @@ |
1064 | } |
1065 | else |
1066 | { |
1067 | - GENV_ITEMFACTORY->createInteger(result, Integer::zero()); |
1068 | + GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1069 | STACK_PUSH(true, state); |
1070 | } |
1071 | |
1072 | @@ -1745,7 +1749,7 @@ |
1073 | } |
1074 | else |
1075 | { |
1076 | - GENV_ITEMFACTORY->createInteger(result, Integer::zero()); |
1077 | + GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1078 | STACK_PUSH(true, state); |
1079 | } |
1080 | |
1081 | @@ -1803,7 +1807,7 @@ |
1082 | } |
1083 | else |
1084 | { |
1085 | - GENV_ITEMFACTORY->createInteger(result, Integer::zero()); |
1086 | + GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero()); |
1087 | STACK_PUSH(true, state); |
1088 | } |
1089 | |
1090 | |
1091 | === modified file 'src/runtime/spec/maths/maths.xml' |
1092 | --- src/runtime/spec/maths/maths.xml 2013-02-07 17:24:36 +0000 |
1093 | +++ src/runtime/spec/maths/maths.xml 2013-05-08 15:05:31 +0000 |
1094 | @@ -6,6 +6,7 @@ |
1095 | xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd"> |
1096 | |
1097 | <zorba:header> |
1098 | + <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include> |
1099 | <zorba:include form="Quoted">zorbatypes/schema_types.h</zorba:include> |
1100 | </zorba:header> |
1101 | |
1102 | @@ -462,7 +463,7 @@ |
1103 | </zorba:function> |
1104 | |
1105 | <zorba:state generateInit="true" generateReset="true"> |
1106 | - <zorba:member type="xs_double" name="theDoubInteger" defaultValue="xs_double::zero()" |
1107 | + <zorba:member type="xs_double" name="theDoubInteger" defaultValue="numeric_consts<xs_double>::zero()" |
1108 | brief=""/> |
1109 | </zorba:state> |
1110 | |
1111 | @@ -485,7 +486,7 @@ |
1112 | </zorba:function> |
1113 | |
1114 | <zorba:state generateInit="true" generateReset="true"> |
1115 | - <zorba:member type="xs_integer" name="theIntExponent" defaultValue="xs_integer::zero()" |
1116 | + <zorba:member type="xs_integer" name="theIntExponent" defaultValue="numeric_consts<xs_integer>::zero()" |
1117 | brief=""/> |
1118 | </zorba:state> |
1119 | |
1120 | |
1121 | === modified file 'src/runtime/spec/random/random.xml' |
1122 | --- src/runtime/spec/random/random.xml 2013-02-07 17:24:36 +0000 |
1123 | +++ src/runtime/spec/random/random.xml 2013-05-08 15:05:31 +0000 |
1124 | @@ -12,6 +12,10 @@ |
1125 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
1126 | xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd"> |
1127 | |
1128 | +<zorba:header> |
1129 | + <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include> |
1130 | +</zorba:header> |
1131 | + |
1132 | <!-- |
1133 | /******************************************************************************* |
1134 | ********************************************************************************/ |
1135 | |
1136 | === modified file 'src/runtime/spec/sequences/sequences.xml' |
1137 | --- src/runtime/spec/sequences/sequences.xml 2013-04-15 20:57:28 +0000 |
1138 | +++ src/runtime/spec/sequences/sequences.xml 2013-05-08 15:05:31 +0000 |
1139 | @@ -15,6 +15,7 @@ |
1140 | <zorba:header> |
1141 | <zorba:include form="Quoted">runtime/base/narybase.h</zorba:include> |
1142 | <zorba:include form="Quoted">runtime/core/path_iterators.h</zorba:include> |
1143 | + <zorba:include form="Quoted">zorbatypes/integer.h</zorba:include> |
1144 | <zorba:fwd-decl ns="zorba">NodeHandleHashSet</zorba:fwd-decl> |
1145 | <zorba:fwd-decl ns="zorba">AtomicItemHandleHashSet</zorba:fwd-decl> |
1146 | </zorba:header> |
1147 | @@ -283,10 +284,10 @@ |
1148 | |
1149 | <zorba:state> |
1150 | <zorba:member type="xs_integer" name="theCurrentPos" |
1151 | - defaultValue="xs_integer::zero()" brief="the current position in the sequence"/> |
1152 | + defaultValue="numeric_consts<xs_integer>::zero()" brief="the current position in the sequence"/> |
1153 | |
1154 | <zorba:member type="xs_integer" name="thePosition" |
1155 | - defaultValue="xs_integer::zero()" brief=""/> |
1156 | + defaultValue="numeric_consts<xs_integer>::zero()" brief=""/> |
1157 | |
1158 | <zorba:member type="store::Item_t" name="theTargetItem" |
1159 | defaultValue="NULL" brief=""/> |
1160 | @@ -328,10 +329,10 @@ |
1161 | |
1162 | <zorba:state> |
1163 | <zorba:member type="xs_integer" name="theCurrentPos" |
1164 | - defaultValue="xs_integer::zero()" brief="the current position in the sequence"/> |
1165 | + defaultValue="numeric_consts<xs_integer>::zero()" brief="the current position in the sequence"/> |
1166 | |
1167 | <zorba:member type="xs_integer" name="thePosition" |
1168 | - defaultValue="xs_integer::zero()" brief="the position to delete"/> |
1169 | + defaultValue="numeric_consts<xs_integer>::zero()" brief="the position to delete"/> |
1170 | |
1171 | <zorba:member type="XQPCollator*" name="theCollator" |
1172 | defaultValue="0" brief="the collator"/> |
1173 | @@ -952,12 +953,12 @@ |
1174 | |
1175 | <zorba:state> |
1176 | <zorba:member type="xs_integer" name="theCurInt" |
1177 | - defaultValue="xs_integer::zero()" brief="the current integer"/> |
1178 | + defaultValue="numeric_consts<xs_integer>::zero()" brief="the current integer"/> |
1179 | |
1180 | <zorba:member type="xs_integer" name="theFirstVal" |
1181 | - defaultValue="xs_integer::zero()" brief="first integer"/> |
1182 | + defaultValue="numeric_consts<xs_integer>::zero()" brief="first integer"/> |
1183 | |
1184 | - <zorba:member type="xs_integer" name="theLastVal" defaultValue="xs_integer::zero()" |
1185 | + <zorba:member type="xs_integer" name="theLastVal" defaultValue="numeric_consts<xs_integer>::zero()" |
1186 | brief="last integer"/> |
1187 | </zorba:state> |
1188 | |
1189 | |
1190 | === modified file 'src/runtime/store/maps_impl.cpp' |
1191 | --- src/runtime/store/maps_impl.cpp 2013-03-05 12:34:19 +0000 |
1192 | +++ src/runtime/store/maps_impl.cpp 2013-05-08 15:05:31 +0000 |
1193 | @@ -19,6 +19,7 @@ |
1194 | #include "diagnostics/util_macros.h" |
1195 | #include "diagnostics/xquery_diagnostics.h" |
1196 | |
1197 | +#include "zorbatypes/integer.h" |
1198 | #include "zorbatypes/URI.h" |
1199 | |
1200 | #include "system/globalenv.h" |
1201 | |
1202 | === modified file 'src/runtime/strings/strings_impl.cpp' |
1203 | --- src/runtime/strings/strings_impl.cpp 2013-05-04 20:20:05 +0000 |
1204 | +++ src/runtime/strings/strings_impl.cpp 2013-05-08 15:05:31 +0000 |
1205 | @@ -25,6 +25,7 @@ |
1206 | #include "diagnostics/xquery_diagnostics.h" |
1207 | #include "diagnostics/util_macros.h" |
1208 | |
1209 | +#include "zorbatypes/integer.h" |
1210 | #include "zorbatypes/numconversions.h" |
1211 | |
1212 | #include "system/globalenv.h" |
1213 | @@ -734,8 +735,12 @@ |
1214 | } |
1215 | else |
1216 | { |
1217 | - STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, xs_integer::zero()), |
1218 | - state); |
1219 | + STACK_PUSH( |
1220 | + GENV_ITEMFACTORY->createInteger( |
1221 | + result, numeric_consts<xs_integer>::zero() |
1222 | + ), |
1223 | + state |
1224 | + ); |
1225 | } |
1226 | STACK_END(state); |
1227 | } |
1228 | |
1229 | === modified file 'src/store/api/collection.h' |
1230 | --- src/store/api/collection.h 2013-02-07 17:24:36 +0000 |
1231 | +++ src/store/api/collection.h 2013-05-08 15:05:31 +0000 |
1232 | @@ -59,7 +59,7 @@ |
1233 | * @return Iterator |
1234 | */ |
1235 | virtual Iterator_t getIterator( |
1236 | - const xs_integer& aSkip = xs_integer::zero(), |
1237 | + const xs_integer& aSkip = numeric_consts<xs_integer>::zero(), |
1238 | const zstring& aStart = "") = 0; |
1239 | |
1240 | /** |
1241 | |
1242 | === modified file 'src/store/api/iterator.h' |
1243 | --- src/store/api/iterator.h 2013-03-05 00:45:43 +0000 |
1244 | +++ src/store/api/iterator.h 2013-05-08 15:05:31 +0000 |
1245 | @@ -177,7 +177,7 @@ |
1246 | virtual ~IndexProbeIterator() { } |
1247 | |
1248 | virtual void init(const IndexCondition_t& cond, |
1249 | - const xs_integer& aSkip = xs_integer::zero()) = 0; |
1250 | + const xs_integer& aSkip = numeric_consts<xs_integer>::zero()) = 0; |
1251 | |
1252 | virtual void open() = 0; |
1253 | |
1254 | |
1255 | === modified file 'src/store/naive/atomic_items.cpp' |
1256 | --- src/store/naive/atomic_items.cpp 2013-04-16 21:12:12 +0000 |
1257 | +++ src/store/naive/atomic_items.cpp 2013-05-08 15:05:31 +0000 |
1258 | @@ -2691,7 +2691,7 @@ |
1259 | |
1260 | bool DecimalItem::getEBV() const |
1261 | { |
1262 | - return ( theValue != xs_decimal::zero() ); |
1263 | + return !!theValue.sign(); |
1264 | } |
1265 | |
1266 | |
1267 | |
1268 | === modified file 'src/store/naive/atomic_items.h' |
1269 | --- src/store/naive/atomic_items.h 2013-04-08 08:45:18 +0000 |
1270 | +++ src/store/naive/atomic_items.h 2013-05-08 15:05:31 +0000 |
1271 | @@ -38,8 +38,11 @@ |
1272 | #include "naive_ft_token_iterator.h" |
1273 | #endif /* ZORBA_NO_FULL_TEXT */ |
1274 | |
1275 | +#include "zorbatypes/datetime.h" |
1276 | +#include "zorbatypes/decimal.h" |
1277 | +#include "zorbatypes/floatimpl.h" |
1278 | +#include "zorbatypes/integer.h" |
1279 | #include "zorbatypes/schema_types.h" |
1280 | -#include "zorbatypes/datetime.h" |
1281 | |
1282 | #include "diagnostics/xquery_diagnostics.h" |
1283 | #include "ordpath.h" |
1284 | |
1285 | === modified file 'src/store/naive/collection.h' |
1286 | --- src/store/naive/collection.h 2013-02-26 04:12:43 +0000 |
1287 | +++ src/store/naive/collection.h 2013-05-08 15:05:31 +0000 |
1288 | @@ -17,6 +17,7 @@ |
1289 | #define ZORBA_SIMPLESTORE_COLLECTION |
1290 | |
1291 | #include "store/api/collection.h" |
1292 | +#include "zorbatypes/integer.h" |
1293 | |
1294 | #include "shared_types.h" |
1295 | #include "tree_id.h" |
1296 | |
1297 | === modified file 'src/store/naive/collection_tree_info.h' |
1298 | --- src/store/naive/collection_tree_info.h 2013-02-06 18:52:32 +0000 |
1299 | +++ src/store/naive/collection_tree_info.h 2013-05-08 15:05:31 +0000 |
1300 | @@ -18,6 +18,7 @@ |
1301 | #define ZORBA_STORE_COLLECTION_TREE_INFO_H |
1302 | |
1303 | #include <zorba/config.h> |
1304 | +#include "zorbatypes/integer.h" |
1305 | |
1306 | namespace zorba |
1307 | { |
1308 | |
1309 | === modified file 'src/store/naive/pul_primitives.cpp' |
1310 | --- src/store/naive/pul_primitives.cpp 2013-02-26 04:12:43 +0000 |
1311 | +++ src/store/naive/pul_primitives.cpp 2013-05-08 15:05:31 +0000 |
1312 | @@ -1147,7 +1147,7 @@ |
1313 | |
1314 | assert(lColl); |
1315 | |
1316 | - xs_integer const zero( xs_integer::zero() ); |
1317 | + xs_integer const zero( numeric_consts<xs_integer>::zero() ); |
1318 | for (std::size_t i = 0; i < theNumApplied; ++i) |
1319 | { |
1320 | ZORBA_ASSERT(theNodes[i] == lColl->nodeAt(zero)); |
1321 | |
1322 | === modified file 'src/store/naive/simple_collection.cpp' |
1323 | --- src/store/naive/simple_collection.cpp 2013-04-16 21:12:12 +0000 |
1324 | +++ src/store/naive/simple_collection.cpp 2013-05-08 15:05:31 +0000 |
1325 | @@ -93,7 +93,7 @@ |
1326 | const zstring& startRef) |
1327 | { |
1328 | store::Item_t startNode; |
1329 | - xs_integer startPos = xs_integer::zero(); |
1330 | + xs_integer startPos; |
1331 | |
1332 | if (startRef.size() != 0 && |
1333 | (!GET_STORE().getNodeByReference(startNode, startRef) || |
1334 | @@ -511,7 +511,7 @@ |
1335 | |
1336 | if (num == 0 || pos >= theTrees.size()) |
1337 | { |
1338 | - return xs_integer::zero(); |
1339 | + return numeric_consts<xs_integer>::zero(); |
1340 | } |
1341 | else |
1342 | { |
1343 | |
1344 | === modified file 'src/store/naive/simple_index_value.h' |
1345 | --- src/store/naive/simple_index_value.h 2013-02-07 17:24:36 +0000 |
1346 | +++ src/store/naive/simple_index_value.h 2013-05-08 15:05:31 +0000 |
1347 | @@ -17,6 +17,7 @@ |
1348 | #define ZORBA_SIMPLE_STORE_INDEX_HASH_VALUE |
1349 | |
1350 | #include "simple_index.h" |
1351 | +#include "zorbatypes/integer.h" |
1352 | #include <map> |
1353 | |
1354 | namespace zorba |
1355 | |
1356 | === modified file 'src/store/naive/simple_lazy_temp_seq.cpp' |
1357 | --- src/store/naive/simple_lazy_temp_seq.cpp 2013-04-16 21:12:12 +0000 |
1358 | +++ src/store/naive/simple_lazy_temp_seq.cpp 2013-05-08 15:05:31 +0000 |
1359 | @@ -21,9 +21,9 @@ |
1360 | #include "diagnostics/dict.h" |
1361 | #include "diagnostics/util_macros.h" |
1362 | #include "diagnostics/xquery_exception.h" |
1363 | - |
1364 | +#include "simple_lazy_temp_seq.h" |
1365 | #include "store/api/item.h" |
1366 | -#include "simple_lazy_temp_seq.h" |
1367 | +#include "zorbatypes/integer.h" |
1368 | |
1369 | |
1370 | namespace zorba |
1371 | |
1372 | === modified file 'src/store/naive/simple_pul.cpp' |
1373 | --- src/store/naive/simple_pul.cpp 2013-04-17 18:37:33 +0000 |
1374 | +++ src/store/naive/simple_pul.cpp 2013-05-08 15:05:31 +0000 |
1375 | @@ -1419,8 +1419,7 @@ |
1376 | |
1377 | xs_integer pos = position->getIntegerValue(); |
1378 | |
1379 | - if (pos <= xs_integer::zero() || |
1380 | - arr->getArraySize() + 1 < pos) |
1381 | + if (pos.sign() <= 0 || arr->getArraySize() + 1 < pos) |
1382 | { |
1383 | RAISE_ERROR(jerr::JNUP0016, loc, |
1384 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); |
1385 | @@ -1557,8 +1556,7 @@ |
1386 | |
1387 | xs_integer pos = position->getIntegerValue(); |
1388 | |
1389 | - if (pos <= xs_integer::zero() || |
1390 | - arr->getArraySize() < pos) |
1391 | + if (pos.sign() <= 0 || arr->getArraySize() < pos) |
1392 | { |
1393 | RAISE_ERROR(jerr::JNUP0016, loc, |
1394 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); |
1395 | @@ -1623,8 +1621,7 @@ |
1396 | |
1397 | xs_integer pos = position->getIntegerValue(); |
1398 | |
1399 | - if (pos <= xs_integer::zero() || |
1400 | - arr->getArraySize() < pos) |
1401 | + if (pos.sign() <= 0 || arr->getArraySize() < pos) |
1402 | { |
1403 | RAISE_ERROR(jerr::JNUP0016, loc, |
1404 | ERROR_PARAMS(ZED(JNUP0016_Array), position->getStringValue())); |
1405 | |
1406 | === modified file 'src/store/naive/simple_temp_seq.cpp' |
1407 | --- src/store/naive/simple_temp_seq.cpp 2013-04-17 18:37:33 +0000 |
1408 | +++ src/store/naive/simple_temp_seq.cpp 2013-05-08 15:05:31 +0000 |
1409 | @@ -24,6 +24,7 @@ |
1410 | #include "store/api/item.h" |
1411 | #include "simple_temp_seq.h" |
1412 | #include "store/api/copymode.h" |
1413 | +#include "zorbatypes/integer.h" |
1414 | |
1415 | namespace zorba { namespace simplestore { |
1416 | |
1417 | |
1418 | === modified file 'src/system/globalenv.cpp' |
1419 | --- src/system/globalenv.cpp 2013-02-07 17:24:36 +0000 |
1420 | +++ src/system/globalenv.cpp 2013-05-08 15:05:31 +0000 |
1421 | @@ -42,6 +42,7 @@ |
1422 | |
1423 | #include "types/schema/schema.h" |
1424 | |
1425 | +#include "zorbatypes/m_apm.h" |
1426 | #include "zorbautils/condition.h" |
1427 | |
1428 | #include "store/api/collection.h" |
1429 | |
1430 | === modified file 'src/types/casting.cpp' |
1431 | --- src/types/casting.cpp 2013-05-02 00:18:56 +0000 |
1432 | +++ src/types/casting.cpp 2013-05-08 15:05:31 +0000 |
1433 | @@ -17,10 +17,13 @@ |
1434 | |
1435 | #include <vector> |
1436 | |
1437 | -#include "zorbatypes/numconversions.h" |
1438 | +#include "zorbatypes/chartype.h" |
1439 | #include "zorbatypes/datetime.h" |
1440 | +#include "zorbatypes/decimal.h" |
1441 | #include "zorbatypes/duration.h" |
1442 | -#include "zorbatypes/chartype.h" |
1443 | +#include "zorbatypes/floatimpl.h" |
1444 | +#include "zorbatypes/integer.h" |
1445 | +#include "zorbatypes/numconversions.h" |
1446 | #include "zorbatypes/URI.h" |
1447 | |
1448 | #include "diagnostics/xquery_diagnostics.h" |
1449 | @@ -1433,36 +1436,36 @@ |
1450 | T1_TO_T2(bool, flt) |
1451 | { |
1452 | if (aItem->getBooleanValue()) |
1453 | - aFactory->createFloat(result, xs_float::one()); |
1454 | + aFactory->createFloat(result, numeric_consts<xs_float>::one()); |
1455 | else |
1456 | - aFactory->createFloat(result, xs_float::zero()); |
1457 | + aFactory->createFloat(result, numeric_consts<xs_float>::zero()); |
1458 | } |
1459 | |
1460 | |
1461 | T1_TO_T2(bool, dbl) |
1462 | { |
1463 | if (aItem->getBooleanValue()) |
1464 | - aFactory->createDouble(result, xs_double::one()); |
1465 | + aFactory->createDouble(result, numeric_consts<xs_double>::one()); |
1466 | else |
1467 | - aFactory->createDouble(result, xs_double::zero()); |
1468 | + aFactory->createDouble(result, numeric_consts<xs_double>::zero()); |
1469 | } |
1470 | |
1471 | |
1472 | T1_TO_T2(bool, dec) |
1473 | { |
1474 | if (aItem->getBooleanValue()) |
1475 | - aFactory->createDecimal(result, xs_decimal::one()); |
1476 | + aFactory->createDecimal(result, numeric_consts<xs_decimal>::one()); |
1477 | else |
1478 | - aFactory->createDecimal(result, xs_decimal::zero()); |
1479 | + aFactory->createDecimal(result, numeric_consts<xs_decimal>::zero()); |
1480 | } |
1481 | |
1482 | |
1483 | T1_TO_T2(bool, int) |
1484 | { |
1485 | if (aItem->getBooleanValue()) |
1486 | - aFactory->createInteger(result, xs_integer::one()); |
1487 | + aFactory->createInteger(result, numeric_consts<xs_integer>::one()); |
1488 | else |
1489 | - aFactory->createInteger(result, xs_integer::zero()); |
1490 | + aFactory->createInteger(result, numeric_consts<xs_integer>::zero()); |
1491 | } |
1492 | |
1493 | |
1494 | @@ -1666,17 +1669,24 @@ |
1495 | |
1496 | T1_TO_T2(dec, uint) |
1497 | { |
1498 | - xs_nonNegativeInteger const n(aItem->getDecimalValue()); |
1499 | - aFactory->createNonNegativeInteger(result, n); |
1500 | + try |
1501 | + { |
1502 | + xs_nonNegativeInteger const n(aItem->getDecimalValue()); |
1503 | + aFactory->createNonNegativeInteger(result, n); |
1504 | + } |
1505 | + catch ( const std::exception& ) |
1506 | + { |
1507 | + throwFOCA0002Exception(aItem->getStringValue(), errInfo); |
1508 | + } |
1509 | } |
1510 | |
1511 | |
1512 | T1_TO_T2(bool, uint) |
1513 | { |
1514 | - if (aItem->getBooleanValue()) |
1515 | - aFactory->createNonNegativeInteger(result, xs_nonNegativeInteger::one()); |
1516 | - else |
1517 | - aFactory->createNonNegativeInteger(result, xs_nonNegativeInteger::zero()); |
1518 | + xs_nonNegativeInteger const &i = aItem->getBooleanValue() ? |
1519 | + numeric_consts<xs_nonNegativeInteger>::one() : |
1520 | + numeric_consts<xs_nonNegativeInteger>::zero(); |
1521 | + aFactory->createNonNegativeInteger(result, i ); |
1522 | } |
1523 | |
1524 | |
1525 | @@ -2024,12 +2034,16 @@ |
1526 | } |
1527 | case store::XS_POSITIVE_INTEGER: |
1528 | { |
1529 | - xs_positiveInteger const i = aItem->getUnsignedIntegerValue(); |
1530 | - if (i.sign() > 0) |
1531 | + try |
1532 | { |
1533 | - factory->createPositiveInteger(result, i); |
1534 | + xs_positiveInteger const n = aItem->getUnsignedIntegerValue(); |
1535 | + factory->createPositiveInteger(result, n); |
1536 | return; |
1537 | } |
1538 | + catch ( std::exception const& ) |
1539 | + { |
1540 | + // ignore |
1541 | + } |
1542 | break; |
1543 | } |
1544 | default: |
1545 | |
1546 | === modified file 'src/types/schema/XercesParseUtils.cpp' |
1547 | --- src/types/schema/XercesParseUtils.cpp 2013-03-05 12:34:19 +0000 |
1548 | +++ src/types/schema/XercesParseUtils.cpp 2013-05-08 15:05:31 +0000 |
1549 | @@ -28,15 +28,18 @@ |
1550 | #include "LoadSchemaErrorHandler.h" |
1551 | #include "PrintSchema.h" |
1552 | |
1553 | +#include "diagnostics/xquery_diagnostics.h" |
1554 | #include "store/api/item.h" |
1555 | #include "store/api/item_factory.h" |
1556 | +#include "system/globalenv.h" |
1557 | #include "types/typeimpl.h" |
1558 | -#include "diagnostics/xquery_diagnostics.h" |
1559 | -#include <zorbatypes/numconversions.h> |
1560 | -#include "system/globalenv.h" |
1561 | +#include "util/utf8_util.h" |
1562 | #include "zorbatypes/datetime.h" |
1563 | +#include "zorbatypes/decimal.h" |
1564 | #include "zorbatypes/duration.h" |
1565 | -#include "util/utf8_util.h" |
1566 | +#include "zorbatypes/floatimpl.h" |
1567 | +#include "zorbatypes/integer.h" |
1568 | +#include "zorbatypes/numconversions.h" |
1569 | |
1570 | using namespace std; |
1571 | XERCES_CPP_NAMESPACE_USE; |
1572 | |
1573 | === modified file 'src/util/stl_util.h' |
1574 | --- src/util/stl_util.h 2013-04-17 15:21:56 +0000 |
1575 | +++ src/util/stl_util.h 2013-05-08 15:05:31 +0000 |
1576 | @@ -421,6 +421,13 @@ |
1577 | return true; |
1578 | } |
1579 | |
1580 | +inline std::enable_if<!ZORBA_TR1_NS::is_signed<char>::value |
1581 | + && !ZORBA_TR1_NS::is_unsigned<char>::value, |
1582 | + bool>::type |
1583 | +ge0( char c ) { |
1584 | + return c >= 0; |
1585 | +} |
1586 | + |
1587 | template<typename NumericType> inline |
1588 | typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type |
1589 | lt0( NumericType n ) { |
1590 | @@ -433,6 +440,13 @@ |
1591 | return false; |
1592 | } |
1593 | |
1594 | +inline std::enable_if<!ZORBA_TR1_NS::is_signed<char>::value |
1595 | + && !ZORBA_TR1_NS::is_unsigned<char>::value, |
1596 | + bool>::type |
1597 | +lt0( char c ) { |
1598 | + return c < 0; |
1599 | +} |
1600 | + |
1601 | template<typename NumericType> inline |
1602 | typename std::enable_if<ZORBA_TR1_NS::is_signed<NumericType>::value,bool>::type |
1603 | le0( NumericType n ) { |
1604 | @@ -445,6 +459,10 @@ |
1605 | return n == 0; |
1606 | } |
1607 | |
1608 | +inline bool le0( char c ) { |
1609 | + return c <= 0; |
1610 | +} |
1611 | + |
1612 | /////////////////////////////////////////////////////////////////////////////// |
1613 | |
1614 | // |
1615 | |
1616 | === modified file 'src/zorbaserialization/serialize_basic_types.cpp' |
1617 | --- src/zorbaserialization/serialize_basic_types.cpp 2013-04-08 00:12:00 +0000 |
1618 | +++ src/zorbaserialization/serialize_basic_types.cpp 2013-05-08 15:05:31 +0000 |
1619 | @@ -22,6 +22,7 @@ |
1620 | #include "zorbaserialization/archiver.h" |
1621 | #include "zorbaserialization/base64impl.h" |
1622 | |
1623 | +#include "zorbatypes/m_apm.h" |
1624 | #include "zorbatypes/floatimpl.h" |
1625 | |
1626 | #include "diagnostics/xquery_diagnostics.h" |
1627 | |
1628 | === modified file 'src/zorbaserialization/serialize_zorba_types.cpp' |
1629 | --- src/zorbaserialization/serialize_zorba_types.cpp 2013-03-27 17:11:24 +0000 |
1630 | +++ src/zorbaserialization/serialize_zorba_types.cpp 2013-05-08 15:05:31 +0000 |
1631 | @@ -82,26 +82,21 @@ |
1632 | /******************************************************************************* |
1633 | |
1634 | ********************************************************************************/ |
1635 | -#ifdef ZORBA_WITH_BIG_INTEGER |
1636 | - |
1637 | -void operator&(serialization::Archiver& ar, IntegerImpl& obj) |
1638 | -{ |
1639 | - ar & obj.value_; |
1640 | -} |
1641 | - |
1642 | -#else |
1643 | - |
1644 | -void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj) |
1645 | -{ |
1646 | - ar & obj.value(); |
1647 | -} |
1648 | - |
1649 | -void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj) |
1650 | -{ |
1651 | - ar & obj.value(); |
1652 | -} |
1653 | - |
1654 | -#endif |
1655 | + |
1656 | +template<class T> |
1657 | +void operator&(serialization::Archiver& ar, IntegerImpl<T>& obj) |
1658 | +{ |
1659 | + ar & obj.value(); |
1660 | +} |
1661 | + |
1662 | +#define INSTANTIATE_INTEGER(I) \ |
1663 | + template void operator&<I::traits_type>(serialization::Archiver&, I&) |
1664 | + |
1665 | +INSTANTIATE_INTEGER( Integer ); |
1666 | +INSTANTIATE_INTEGER( NegativeInteger ); |
1667 | +INSTANTIATE_INTEGER( NonNegativeInteger ); |
1668 | +INSTANTIATE_INTEGER( NonPositiveInteger ); |
1669 | +INSTANTIATE_INTEGER( PositiveInteger ); |
1670 | |
1671 | |
1672 | /******************************************************************************* |
1673 | |
1674 | === modified file 'src/zorbaserialization/serialize_zorba_types.h' |
1675 | --- src/zorbaserialization/serialize_zorba_types.h 2013-02-07 17:24:36 +0000 |
1676 | +++ src/zorbaserialization/serialize_zorba_types.h 2013-05-08 15:05:31 +0000 |
1677 | @@ -23,6 +23,7 @@ |
1678 | #include "zorbatypes/rchandle.h" |
1679 | #include "zorbatypes/m_apm.h" |
1680 | #include "zorbatypes/floatimpl.h" |
1681 | +#include "zorbatypes/zorbatypes_decl.h" |
1682 | |
1683 | #include "zorbautils/checked_vector.h" |
1684 | |
1685 | @@ -37,24 +38,16 @@ |
1686 | |
1687 | namespace zorba |
1688 | { |
1689 | - class Decimal; |
1690 | - class Duration; |
1691 | - class Timezone; |
1692 | - class DateTime; |
1693 | class Base16; |
1694 | class Base64; |
1695 | - class QueryLoc; |
1696 | + class Diagnostic; |
1697 | + class function; |
1698 | class HashMapItemPointerCmp; |
1699 | class HashMapZStringCmp; |
1700 | + class QueryLoc; |
1701 | + class Timezone; |
1702 | class XQType; |
1703 | - class function; |
1704 | - class Diagnostic; |
1705 | class ZorbaException; |
1706 | -#ifdef ZORBA_WITH_BIG_INTEGER |
1707 | - class IntegerImpl; |
1708 | -#else |
1709 | - template<typename IntType> class IntegerImpl; |
1710 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
1711 | |
1712 | namespace serialization |
1713 | { |
1714 | @@ -65,12 +58,8 @@ |
1715 | |
1716 | void operator&(Archiver& ar, const XQType*& obj); |
1717 | |
1718 | -#ifdef ZORBA_WITH_BIG_INTEGER |
1719 | -void operator&(Archiver& ar, IntegerImpl& obj); |
1720 | -#else |
1721 | -void operator&(serialization::Archiver& ar, IntegerImpl<long long>& obj); |
1722 | -void operator&(serialization::Archiver& ar, IntegerImpl<unsigned long long>& obj); |
1723 | -#endif |
1724 | +template<class C> |
1725 | +void operator&(Archiver& ar, IntegerImpl<C>& obj); |
1726 | |
1727 | void operator&(Archiver& ar, Decimal& obj); |
1728 | |
1729 | |
1730 | === modified file 'src/zorbatypes/CMakeLists.txt' |
1731 | --- src/zorbatypes/CMakeLists.txt 2013-02-07 17:24:36 +0000 |
1732 | +++ src/zorbatypes/CMakeLists.txt 2013-05-08 15:05:31 +0000 |
1733 | @@ -17,6 +17,7 @@ |
1734 | floatimpl.cpp |
1735 | integer.cpp |
1736 | numconversions.cpp |
1737 | + numeric_types.cpp |
1738 | binary.cpp |
1739 | URI.cpp |
1740 | collation_manager.cpp |
1741 | |
1742 | === modified file 'src/zorbatypes/datetime.h' |
1743 | --- src/zorbatypes/datetime.h 2013-04-23 06:09:42 +0000 |
1744 | +++ src/zorbatypes/datetime.h 2013-05-08 15:05:31 +0000 |
1745 | @@ -20,11 +20,10 @@ |
1746 | #include <iostream> |
1747 | |
1748 | #include <zorba/config.h> |
1749 | -#include "zorbatypes/timezone.h" |
1750 | -#include "zorbatypes/duration.h" |
1751 | - |
1752 | #include "util/ascii_util.h" |
1753 | |
1754 | +#include "timezone.h" |
1755 | +#include "duration.h" |
1756 | |
1757 | namespace zorba |
1758 | { |
1759 | @@ -301,7 +300,7 @@ |
1760 | |
1761 | int getMinutes() const; |
1762 | |
1763 | - xs_decimal getSeconds() const; |
1764 | + Decimal getSeconds() const; |
1765 | |
1766 | int getIntSeconds() const; |
1767 | |
1768 | |
1769 | === modified file 'src/zorbatypes/datetime/datetimetype.cpp' |
1770 | --- src/zorbatypes/datetime/datetimetype.cpp 2013-04-24 17:26:02 +0000 |
1771 | +++ src/zorbatypes/datetime/datetimetype.cpp 2013-05-08 15:05:31 +0000 |
1772 | @@ -29,14 +29,15 @@ |
1773 | #include <time.h> |
1774 | #endif |
1775 | |
1776 | +#include "zorbatypes/datetime.h" |
1777 | +#include "zorbatypes/datetime/parse.h" |
1778 | +#include "zorbatypes/decimal.h" |
1779 | +#include "zorbatypes/duration.h" |
1780 | +#include "zorbatypes/integer.h" |
1781 | +#include "zorbatypes/timezone.h" |
1782 | +#include "zorbatypes/zorbatypes_decl.h" |
1783 | +#include "zorbatypes/zstring.h" |
1784 | #include "zorbautils/hashfun.h" |
1785 | -#include <zorbatypes/datetime.h> |
1786 | -#include <zorbatypes/duration.h> |
1787 | -#include <zorbatypes/timezone.h> |
1788 | -#include <zorbatypes/zorbatypes_decl.h> |
1789 | -#include <zorbatypes/zstring.h> |
1790 | - |
1791 | -#include "zorbatypes/datetime/parse.h" |
1792 | |
1793 | #include "util/ascii_util.h" |
1794 | #include "util/time_util.h" |
1795 | @@ -1325,7 +1326,7 @@ |
1796 | // validate timezone value (-14 .. +14 H) |
1797 | if (d->getYears() != 0 || d->getMonths() != 0 || |
1798 | d->getDays() != 0 || |
1799 | - d->getSeconds() != Integer::zero() || |
1800 | + d->getSeconds().sign() != 0 || |
1801 | d->getHours()*3600 + d->getMinutes()*60 > 14*3600 || |
1802 | d->getHours()*3600 + d->getMinutes()*60 < -14*3600) |
1803 | throw InvalidTimezoneException( d->getHours()*3600 + d->getMinutes()*60 ); |
1804 | |
1805 | === modified file 'src/zorbatypes/datetime/duration.cpp' |
1806 | --- src/zorbatypes/datetime/duration.cpp 2013-04-16 21:12:12 +0000 |
1807 | +++ src/zorbatypes/datetime/duration.cpp 2013-05-08 15:05:31 +0000 |
1808 | @@ -19,11 +19,14 @@ |
1809 | #include <memory> |
1810 | #include <string> |
1811 | |
1812 | -#include "zorbautils/hashfun.h" |
1813 | +#include "zorbatypes/datetime.h" |
1814 | +#include "zorbatypes/datetime/parse.h" |
1815 | +#include "zorbatypes/decimal.h" |
1816 | #include "zorbatypes/duration.h" |
1817 | -#include "zorbatypes/datetime/parse.h" |
1818 | +#include "zorbatypes/floatimpl.h" |
1819 | +#include "zorbatypes/integer.h" |
1820 | #include "zorbatypes/numconversions.h" |
1821 | -#include "zorbatypes/datetime.h" |
1822 | +#include "zorbautils/hashfun.h" |
1823 | |
1824 | #include "diagnostics/xquery_diagnostics.h" |
1825 | |
1826 | @@ -597,7 +600,8 @@ |
1827 | |
1828 | xs_double Duration::getTotalSeconds() const |
1829 | { |
1830 | - return (is_negative ? xs_double::neg_one() : xs_double::one()) |
1831 | + return (is_negative ? |
1832 | + numeric_consts<xs_double>::neg_one() : numeric_consts<xs_double>::one()) |
1833 | * ((((((((xs_double(data[YEAR_DATA]) * 12 |
1834 | + xs_double(data[MONTH_DATA])) * 30) |
1835 | + xs_double(data[DAY_DATA])) * 24) |
1836 | |
1837 | === modified file 'src/zorbatypes/datetime/timezone.cpp' |
1838 | --- src/zorbatypes/datetime/timezone.cpp 2013-03-13 16:19:33 +0000 |
1839 | +++ src/zorbatypes/datetime/timezone.cpp 2013-05-08 15:05:31 +0000 |
1840 | @@ -22,6 +22,7 @@ |
1841 | #include <zorbatypes/timezone.h> |
1842 | |
1843 | #include "zorbatypes/datetime/parse.h" |
1844 | +#include "zorbatypes/decimal.h" |
1845 | |
1846 | #include "zorbautils/hashfun.h" |
1847 | |
1848 | |
1849 | === modified file 'src/zorbatypes/decimal.cpp' |
1850 | --- src/zorbatypes/decimal.cpp 2013-04-11 18:13:48 +0000 |
1851 | +++ src/zorbatypes/decimal.cpp 2013-05-08 15:05:31 +0000 |
1852 | @@ -23,19 +23,10 @@ |
1853 | #include "util/ascii_util.h" |
1854 | |
1855 | #include "decimal.h" |
1856 | +#include "floatimpl.h" |
1857 | #include "integer.h" |
1858 | #include "numconversions.h" |
1859 | |
1860 | -#ifdef ZORBA_WITH_BIG_INTEGER |
1861 | -# define TEMPLATE_DECL(T) /* nothing */ |
1862 | -# define INTEGER_IMPL(I) IntegerImpl |
1863 | -#else |
1864 | -# define TEMPLATE_DECL(T) template<typename T> /* spacer */ |
1865 | -# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ |
1866 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
1867 | -#define INTEGER_IMPL_LL INTEGER_IMPL(long long) |
1868 | -#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) |
1869 | - |
1870 | namespace zorba { |
1871 | |
1872 | /////////////////////////////////////////////////////////////////////////////// |
1873 | @@ -79,7 +70,6 @@ |
1874 | delete[] copy; |
1875 | } else |
1876 | *result = first_non_ws; |
1877 | - |
1878 | } |
1879 | |
1880 | /** |
1881 | @@ -178,7 +168,6 @@ |
1882 | } |
1883 | } |
1884 | |
1885 | - |
1886 | ////////// constructors /////////////////////////////////////////////////////// |
1887 | |
1888 | Decimal::Decimal( long long n ) { |
1889 | @@ -224,14 +213,16 @@ |
1890 | value_ = f.getNumber(); |
1891 | } |
1892 | |
1893 | -TEMPLATE_DECL(I) |
1894 | -Decimal::Decimal( INTEGER_IMPL(I) const &i ) : |
1895 | - value_( i.itod() ) { |
1896 | +template<class T> |
1897 | +Decimal::Decimal( IntegerImpl<T> const &i ) : value_( i.itod() ) { |
1898 | } |
1899 | -#ifndef ZORBA_WITH_BIG_INTEGER |
1900 | -template Decimal::Decimal( INTEGER_IMPL_LL const& ); |
1901 | -template Decimal::Decimal( INTEGER_IMPL_ULL const& ); |
1902 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
1903 | + |
1904 | +// instantiate Decimal-from-Integer constructors |
1905 | +template Decimal::Decimal( Integer const& ); |
1906 | +template Decimal::Decimal( NegativeInteger const& ); |
1907 | +template Decimal::Decimal( NonNegativeInteger const& ); |
1908 | +template Decimal::Decimal( NonPositiveInteger const& ); |
1909 | +template Decimal::Decimal( PositiveInteger const& ); |
1910 | |
1911 | ////////// assignment operators /////////////////////////////////////////////// |
1912 | |
1913 | @@ -247,15 +238,17 @@ |
1914 | return *this; |
1915 | } |
1916 | |
1917 | -TEMPLATE_DECL(I) |
1918 | -Decimal& Decimal::operator=( INTEGER_IMPL(I) const &i ) { |
1919 | +template<class T> |
1920 | +Decimal& Decimal::operator=( IntegerImpl<T> const &i ) { |
1921 | value_ = i.itod(); |
1922 | return *this; |
1923 | } |
1924 | -#ifndef ZORBA_WITH_BIG_INTEGER |
1925 | -template Decimal& Decimal::operator=( INTEGER_IMPL_LL const& ); |
1926 | -template Decimal& Decimal::operator=( INTEGER_IMPL_ULL const& ); |
1927 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
1928 | + |
1929 | +template Decimal& Decimal::operator=( Integer const& ); |
1930 | +template Decimal& Decimal::operator=( NegativeInteger const& ); |
1931 | +template Decimal& Decimal::operator=( NonNegativeInteger const& ); |
1932 | +template Decimal& Decimal::operator=( NonPositiveInteger const& ); |
1933 | +template Decimal& Decimal::operator=( PositiveInteger const& ); |
1934 | |
1935 | Decimal& Decimal::operator=( Double const &d ) { |
1936 | if ( !d.isFinite() ) |
1937 | @@ -273,20 +266,19 @@ |
1938 | |
1939 | ////////// arithmetic operators /////////////////////////////////////////////// |
1940 | |
1941 | -#ifdef ZORBA_WITH_BIG_INTEGER |
1942 | -# define ZORBA_INSTANTIATE(OP) /* nothing */ |
1943 | -#else |
1944 | -# define ZORBA_INSTANTIATE(OP) \ |
1945 | - template Decimal operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \ |
1946 | - template Decimal operator OP( Decimal const&, INTEGER_IMPL_ULL const& ) |
1947 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
1948 | +#define ZORBA_INSTANTIATE(OP,I) \ |
1949 | + template Decimal operator OP( Decimal const&, I const& ) |
1950 | |
1951 | #define ZORBA_DECIMAL_OP(OP) \ |
1952 | - TEMPLATE_DECL(I) \ |
1953 | - Decimal operator OP( Decimal const &d, INTEGER_IMPL(I) const &i ) { \ |
1954 | + template<class T> inline \ |
1955 | + Decimal operator OP( Decimal const &d, IntegerImpl<T> const &i ) { \ |
1956 | return d.value_ OP i.itod(); \ |
1957 | } \ |
1958 | - ZORBA_INSTANTIATE(OP) |
1959 | + ZORBA_INSTANTIATE(OP,Integer); \ |
1960 | + ZORBA_INSTANTIATE(OP,NegativeInteger); \ |
1961 | + ZORBA_INSTANTIATE(OP,NonNegativeInteger); \ |
1962 | + ZORBA_INSTANTIATE(OP,NonPositiveInteger); \ |
1963 | + ZORBA_INSTANTIATE(OP,PositiveInteger); |
1964 | |
1965 | ZORBA_DECIMAL_OP(+); |
1966 | ZORBA_DECIMAL_OP(-); |
1967 | @@ -298,20 +290,19 @@ |
1968 | |
1969 | ////////// relational operators /////////////////////////////////////////////// |
1970 | |
1971 | -#ifdef ZORBA_WITH_BIG_INTEGER |
1972 | -# define ZORBA_INSTANTIATE(OP) /* nothing */ |
1973 | -#else |
1974 | -# define ZORBA_INSTANTIATE(OP) \ |
1975 | - template bool operator OP( Decimal const&, INTEGER_IMPL_LL const& ); \ |
1976 | - template bool operator OP( Decimal const&, INTEGER_IMPL_ULL const& ) |
1977 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
1978 | +#define ZORBA_INSTANTIATE(OP,I) \ |
1979 | + template bool operator OP( Decimal const&, I const& ) |
1980 | |
1981 | -#define ZORBA_DECIMAL_OP(OP) \ |
1982 | - TEMPLATE_DECL(I) \ |
1983 | - bool operator OP( Decimal const &d, INTEGER_IMPL(I) const &i ) { \ |
1984 | - return d.value_ OP i.itod(); \ |
1985 | - } \ |
1986 | - ZORBA_INSTANTIATE(OP) |
1987 | +#define ZORBA_DECIMAL_OP(OP) \ |
1988 | + template<class T> inline \ |
1989 | + bool operator OP( Decimal const &d, IntegerImpl<T> const &i ) { \ |
1990 | + return d.value_ OP i.itod(); \ |
1991 | + } \ |
1992 | + ZORBA_INSTANTIATE( OP, Integer ); \ |
1993 | + ZORBA_INSTANTIATE( OP, NegativeInteger ); \ |
1994 | + ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \ |
1995 | + ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \ |
1996 | + ZORBA_INSTANTIATE( OP, PositiveInteger ); |
1997 | |
1998 | ZORBA_DECIMAL_OP(==); |
1999 | ZORBA_DECIMAL_OP(!=); |
2000 | @@ -325,17 +316,19 @@ |
2001 | ////////// math functions ///////////////////////////////////////////////////// |
2002 | |
2003 | Decimal Decimal::round() const { |
2004 | - return round( INTEGER_IMPL_LL::zero() ); |
2005 | + return round( numeric_consts<xs_integer>::zero() ); |
2006 | } |
2007 | |
2008 | -TEMPLATE_DECL(I) |
2009 | -Decimal Decimal::round( INTEGER_IMPL(I) const &precision ) const { |
2010 | +template<class T> |
2011 | +Decimal Decimal::round( IntegerImpl<T> const &precision ) const { |
2012 | return round2( value_, precision.itod() ); |
2013 | } |
2014 | -#ifndef ZORBA_WITH_BIG_INTEGER |
2015 | -template Decimal Decimal::round( INTEGER_IMPL_LL const& ) const; |
2016 | -template Decimal Decimal::round( INTEGER_IMPL_ULL const& ) const; |
2017 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2018 | + |
2019 | +template Decimal Decimal::round( Integer const& ) const; |
2020 | +template Decimal Decimal::round( NegativeInteger const& ) const; |
2021 | +template Decimal Decimal::round( NonNegativeInteger const& ) const; |
2022 | +template Decimal Decimal::round( NonPositiveInteger const& ) const; |
2023 | +template Decimal Decimal::round( PositiveInteger const& ) const; |
2024 | |
2025 | Decimal::value_type Decimal::round2( value_type const &v, |
2026 | value_type const &precision ) { |
2027 | @@ -352,14 +345,16 @@ |
2028 | return result; |
2029 | } |
2030 | |
2031 | -TEMPLATE_DECL(I) |
2032 | -Decimal Decimal::roundHalfToEven( INTEGER_IMPL(I) const &precision ) const { |
2033 | +template<class T> |
2034 | +Decimal Decimal::roundHalfToEven( IntegerImpl<T> const &precision ) const { |
2035 | return roundHalfToEven2( value_, precision.itod() ); |
2036 | } |
2037 | -#ifndef ZORBA_WITH_BIG_INTEGER |
2038 | -template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_LL const& ) const; |
2039 | -template Decimal Decimal::roundHalfToEven( INTEGER_IMPL_ULL const& ) const; |
2040 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2041 | + |
2042 | +template Decimal Decimal::roundHalfToEven( Integer const& ) const; |
2043 | +template Decimal Decimal::roundHalfToEven( NegativeInteger const& ) const; |
2044 | +template Decimal Decimal::roundHalfToEven( NonNegativeInteger const& ) const; |
2045 | +template Decimal Decimal::roundHalfToEven( NonPositiveInteger const& ) const; |
2046 | +template Decimal Decimal::roundHalfToEven( PositiveInteger const& ) const; |
2047 | |
2048 | Decimal::value_type Decimal::roundHalfToEven2( value_type const &v, |
2049 | value_type const &precision ) { |
2050 | @@ -425,21 +420,15 @@ |
2051 | return static_cast<uint32_t>( n ); |
2052 | } |
2053 | |
2054 | -Decimal const& Decimal::one() { |
2055 | - static Decimal d(1); |
2056 | - return d; |
2057 | -} |
2058 | - |
2059 | -zstring Decimal::toString( value_type const &value, int precision ) { |
2060 | - return toString(value, false, precision); |
2061 | -} |
2062 | - |
2063 | -zstring Decimal::toString( value_type const &value, bool minusZero, int precision ) { |
2064 | +zstring Decimal::toString( value_type const &value, bool minusZero, |
2065 | + int precision ) { |
2066 | char buf[ 1024 ]; |
2067 | |
2068 | - if ( minusZero ) |
2069 | - { |
2070 | - buf[0] = '-'; |
2071 | + if ( minusZero ) { |
2072 | + if ( value.sign() == 0 ) |
2073 | + buf[0] = '-'; |
2074 | + else |
2075 | + minusZero = false; |
2076 | } |
2077 | |
2078 | value.toFixPtString( buf + minusZero, precision ); |
2079 | @@ -464,11 +453,6 @@ |
2080 | return buf; |
2081 | } |
2082 | |
2083 | -Decimal const& Decimal::zero() { |
2084 | - static Decimal d(0); |
2085 | - return d; |
2086 | -} |
2087 | - |
2088 | /////////////////////////////////////////////////////////////////////////////// |
2089 | |
2090 | } // namespace zorba |
2091 | |
2092 | === modified file 'src/zorbatypes/decimal.h' |
2093 | --- src/zorbatypes/decimal.h 2013-04-11 18:13:48 +0000 |
2094 | +++ src/zorbatypes/decimal.h 2013-05-08 15:05:31 +0000 |
2095 | @@ -28,14 +28,6 @@ |
2096 | #include "zorbatypes_decl.h" |
2097 | #include "zstring.h" |
2098 | |
2099 | -#ifdef ZORBA_WITH_BIG_INTEGER |
2100 | -# define TEMPLATE_DECL(I) /* nothing */ |
2101 | -# define INTEGER_IMPL(I) IntegerImpl |
2102 | -#else |
2103 | -# define TEMPLATE_DECL(I) template<typename I> /* spacer */ |
2104 | -# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ |
2105 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2106 | - |
2107 | namespace zorba { |
2108 | |
2109 | class Decimal; |
2110 | @@ -72,8 +64,8 @@ |
2111 | explicit Decimal( float n ); |
2112 | explicit Decimal( double n ); |
2113 | |
2114 | - TEMPLATE_DECL(I) |
2115 | - explicit Decimal( INTEGER_IMPL(I) const &i ); |
2116 | + template<class T> |
2117 | + explicit Decimal( IntegerImpl<T> const &i ); |
2118 | |
2119 | /** |
2120 | * Constructs a %Decimal from a C string. |
2121 | @@ -133,8 +125,8 @@ |
2122 | Decimal& operator=( Double const &d ); |
2123 | Decimal& operator=( Float const &f ); |
2124 | |
2125 | - TEMPLATE_DECL(I) |
2126 | - Decimal& operator=( INTEGER_IMPL(I) const &i ); |
2127 | + template<class T> |
2128 | + Decimal& operator=( IntegerImpl<T> const &i ); |
2129 | |
2130 | ////////// arithmetic operators ///////////////////////////////////////////// |
2131 | |
2132 | @@ -145,11 +137,11 @@ |
2133 | friend Decimal operator%( Decimal const&, Decimal const& ); |
2134 | |
2135 | #define ZORBA_DECIMAL_OP(OP) \ |
2136 | - TEMPLATE_DECL(I) \ |
2137 | - friend Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \ |
2138 | + template<class T> \ |
2139 | + friend Decimal operator OP( Decimal const&, IntegerImpl<T> const& ); \ |
2140 | \ |
2141 | - TEMPLATE_DECL(I) \ |
2142 | - friend Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ) |
2143 | + template<class T> \ |
2144 | + friend Decimal operator OP( IntegerImpl<T> const&, Decimal const& ) |
2145 | |
2146 | ZORBA_DECIMAL_OP(+); |
2147 | ZORBA_DECIMAL_OP(-); |
2148 | @@ -165,7 +157,7 @@ |
2149 | Decimal& operator%=( Decimal const& ); |
2150 | |
2151 | #define ZORBA_DECIMAL_OP(OP) \ |
2152 | - TEMPLATE_DECL(I) Decimal& operator OP( INTEGER_IMPL(I) const& ) |
2153 | + template<class T> Decimal& operator OP( IntegerImpl<T> const& ) |
2154 | |
2155 | ZORBA_DECIMAL_OP(+=); |
2156 | ZORBA_DECIMAL_OP(-=); |
2157 | @@ -178,12 +170,12 @@ |
2158 | |
2159 | ////////// relational operators ///////////////////////////////////////////// |
2160 | |
2161 | -#define ZORBA_DECIMAL_OP(OP) \ |
2162 | - friend bool operator OP( Decimal const&, Decimal const& ); \ |
2163 | - TEMPLATE_DECL(I) \ |
2164 | - friend bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ); \ |
2165 | - TEMPLATE_DECL(I) \ |
2166 | - friend bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ) |
2167 | +#define ZORBA_DECIMAL_OP(OP) \ |
2168 | + friend bool operator OP( Decimal const&, Decimal const& ); \ |
2169 | + template<class T> \ |
2170 | + friend bool operator OP( Decimal const&, IntegerImpl<T> const& ); \ |
2171 | + template<class T> \ |
2172 | + friend bool operator OP( IntegerImpl<T> const&, Decimal const& ) |
2173 | |
2174 | ZORBA_DECIMAL_OP(==); |
2175 | ZORBA_DECIMAL_OP(!=); |
2176 | @@ -201,11 +193,11 @@ |
2177 | Decimal floor() const; |
2178 | Decimal round() const; |
2179 | |
2180 | - TEMPLATE_DECL(I) |
2181 | - Decimal round( INTEGER_IMPL(I) const &precision ) const; |
2182 | + template<class T> |
2183 | + Decimal round( IntegerImpl<T> const &precision ) const; |
2184 | |
2185 | - TEMPLATE_DECL(I) |
2186 | - Decimal roundHalfToEven( INTEGER_IMPL(I) const &precision ) const; |
2187 | + template<class T> |
2188 | + Decimal roundHalfToEven( IntegerImpl<T> const &precision ) const; |
2189 | |
2190 | Decimal sqrt() const; |
2191 | |
2192 | @@ -223,9 +215,6 @@ |
2193 | |
2194 | zstring toString( int precision = ZORBA_FLOAT_POINT_PRECISION ) const; |
2195 | |
2196 | - static Decimal const& one(); |
2197 | - static Decimal const& zero(); |
2198 | - |
2199 | ///////////////////////////////////////////////////////////////////////////// |
2200 | |
2201 | private: |
2202 | @@ -254,13 +243,15 @@ |
2203 | static value_type roundHalfToEven2( value_type const &v, |
2204 | value_type const &precision ); |
2205 | |
2206 | - static zstring toString( value_type const&, |
2207 | - int precision = ZORBA_FLOAT_POINT_PRECISION ); |
2208 | + static zstring toString( value_type const &value, |
2209 | + int precision = ZORBA_FLOAT_POINT_PRECISION ) { |
2210 | + return toString( value, false, precision ); |
2211 | + } |
2212 | |
2213 | static zstring toString( value_type const&, bool, |
2214 | int precision = ZORBA_FLOAT_POINT_PRECISION ); |
2215 | |
2216 | - TEMPLATE_DECL(I) friend class IntegerImpl; |
2217 | + template<class T> friend class IntegerImpl; |
2218 | template<typename F> friend class FloatImpl; |
2219 | |
2220 | friend xs_long to_xs_long( Decimal const& ); |
2221 | @@ -429,9 +420,6 @@ |
2222 | |
2223 | } // namespace zorba |
2224 | |
2225 | -#undef TEMPLATE_DECL |
2226 | -#undef INTEGER_IMPL |
2227 | - |
2228 | #endif /* ZORBA_DECIMAL_H */ |
2229 | /* |
2230 | * Local variables: |
2231 | |
2232 | === modified file 'src/zorbatypes/duration.h' |
2233 | --- src/zorbatypes/duration.h 2013-02-07 17:24:36 +0000 |
2234 | +++ src/zorbatypes/duration.h 2013-05-08 15:05:31 +0000 |
2235 | @@ -18,10 +18,10 @@ |
2236 | #define ZORBA_TYPES_DURATION_H |
2237 | |
2238 | #include <zorba/config.h> |
2239 | -#include "zorbatypes/zorbatypes_decl.h" |
2240 | -#include "zorbatypes/schema_types.h" |
2241 | +#include "zorbatypes_decl.h" |
2242 | |
2243 | #include "util/ascii_util.h" |
2244 | +#include "zorbatypes/zstring.h" |
2245 | |
2246 | namespace zorba |
2247 | { |
2248 | @@ -175,9 +175,9 @@ |
2249 | |
2250 | Duration* operator-(const Duration& d) const; |
2251 | |
2252 | - Duration* operator*(const xs_double& value) const; |
2253 | + Duration* operator*(const Double& value) const; |
2254 | |
2255 | - Duration* operator/(const xs_double& value) const; |
2256 | + Duration* operator/(const Double& value) const; |
2257 | |
2258 | Decimal operator/(const Duration& d) const; |
2259 | |
2260 | @@ -195,13 +195,13 @@ |
2261 | |
2262 | virtual long getMinutes() const; |
2263 | |
2264 | - virtual xs_decimal getSeconds() const; |
2265 | + virtual Decimal getSeconds() const; |
2266 | |
2267 | virtual long getFractionalSeconds() const; |
2268 | |
2269 | virtual long getIntSeconds() const; |
2270 | |
2271 | - xs_double getTotalSeconds() const; |
2272 | + Double getTotalSeconds() const; |
2273 | |
2274 | long getTotalMilliseconds() const; |
2275 | |
2276 | |
2277 | === modified file 'src/zorbatypes/floatimpl.cpp' |
2278 | --- src/zorbatypes/floatimpl.cpp 2013-04-02 21:31:04 +0000 |
2279 | +++ src/zorbatypes/floatimpl.cpp 2013-05-08 15:05:31 +0000 |
2280 | @@ -30,16 +30,6 @@ |
2281 | #include "zorbaserialization/serialize_zorba_types.h" |
2282 | #include "zorbaserialization/serialize_template_types.h" |
2283 | |
2284 | -#ifdef ZORBA_WITH_BIG_INTEGER |
2285 | -# define TEMPLATE_DECL(T) /* nothing */ |
2286 | -# define INTEGER_IMPL(I) IntegerImpl |
2287 | -#else |
2288 | -# define TEMPLATE_DECL(T) template<typename T> /* spacer */ |
2289 | -# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ |
2290 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2291 | -#define INTEGER_IMPL_LL INTEGER_IMPL(long long) |
2292 | -#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) |
2293 | - |
2294 | /////////////////////////////////////////////////////////////////////////////// |
2295 | |
2296 | namespace zorba { |
2297 | @@ -72,8 +62,8 @@ |
2298 | } |
2299 | } |
2300 | |
2301 | -template<typename FloatType> |
2302 | -void FloatImpl<FloatType>::parse( char const *s ) { |
2303 | +template<typename F> |
2304 | +void FloatImpl<F>::parse( char const *s ) { |
2305 | if ( !*s ) |
2306 | throw std::invalid_argument( "empty string" ); |
2307 | |
2308 | @@ -151,80 +141,87 @@ |
2309 | |
2310 | ////////// constructors /////////////////////////////////////////////////////// |
2311 | |
2312 | -template<typename FloatType> |
2313 | -FloatImpl<FloatType>::FloatImpl( Decimal const &d ) { |
2314 | +template<typename F> |
2315 | +FloatImpl<F>::FloatImpl( Decimal const &d ) { |
2316 | zstring const temp( d.toString() ); |
2317 | parse( temp.c_str() ); |
2318 | } |
2319 | |
2320 | -template<typename FloatType> |
2321 | -TEMPLATE_DECL(IntType) |
2322 | -FloatImpl<FloatType>::FloatImpl( INTEGER_IMPL(IntType) const &i ) { |
2323 | +template<typename F> |
2324 | +template<class T> |
2325 | +FloatImpl<F>::FloatImpl( IntegerImpl<T> const &i ) { |
2326 | zstring const temp( i.toString() ); |
2327 | parse( temp.c_str() ); |
2328 | } |
2329 | |
2330 | -#ifndef ZORBA_WITH_BIG_INTEGER |
2331 | -template FloatImpl<float>::FloatImpl( INTEGER_IMPL_LL const& ); |
2332 | -template FloatImpl<float>::FloatImpl( INTEGER_IMPL_ULL const& ); |
2333 | +template FloatImpl<float>::FloatImpl( Integer const& ); |
2334 | +template FloatImpl<float>::FloatImpl( NegativeInteger const& ); |
2335 | +template FloatImpl<float>::FloatImpl( NonNegativeInteger const& ); |
2336 | +template FloatImpl<float>::FloatImpl( NonPositiveInteger const& ); |
2337 | +template FloatImpl<float>::FloatImpl( PositiveInteger const& ); |
2338 | |
2339 | -template FloatImpl<double>::FloatImpl( INTEGER_IMPL_LL const& ); |
2340 | -template FloatImpl<double>::FloatImpl( INTEGER_IMPL_ULL const& ); |
2341 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2342 | +template FloatImpl<double>::FloatImpl( Integer const& ); |
2343 | +template FloatImpl<double>::FloatImpl( NegativeInteger const& ); |
2344 | +template FloatImpl<double>::FloatImpl( NonNegativeInteger const& ); |
2345 | +template FloatImpl<double>::FloatImpl( NonPositiveInteger const& ); |
2346 | +template FloatImpl<double>::FloatImpl( PositiveInteger const& ); |
2347 | |
2348 | ////////// assignment operators /////////////////////////////////////////////// |
2349 | |
2350 | -template<typename FloatType> |
2351 | -FloatImpl<FloatType>& FloatImpl<FloatType>::operator=( Decimal const &d ) { |
2352 | +template<typename F> |
2353 | +FloatImpl<F>& FloatImpl<F>::operator=( Decimal const &d ) { |
2354 | zstring const temp( d.toString() ); |
2355 | parse( temp.c_str() ); |
2356 | return *this; |
2357 | } |
2358 | |
2359 | -template<typename FloatType> |
2360 | -TEMPLATE_DECL(IntType) |
2361 | -FloatImpl<FloatType>& |
2362 | -FloatImpl<FloatType>::operator=( INTEGER_IMPL(IntType) const &i ) { |
2363 | +template<typename F> |
2364 | +template<class T> |
2365 | +FloatImpl<F>& FloatImpl<F>::operator=( IntegerImpl<T> const &i ) { |
2366 | zstring const temp( i.toString() ); |
2367 | parse( temp.c_str() ); |
2368 | return *this; |
2369 | } |
2370 | |
2371 | -#ifndef ZORBA_WITH_BIG_INTEGER |
2372 | -template |
2373 | -FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_LL const& ); |
2374 | - |
2375 | -template |
2376 | -FloatImpl<float>& FloatImpl<float>::operator=( INTEGER_IMPL_ULL const& ); |
2377 | - |
2378 | -template |
2379 | -FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_LL const& ); |
2380 | - |
2381 | -template |
2382 | -FloatImpl<double>& FloatImpl<double>::operator=( INTEGER_IMPL_ULL const& ); |
2383 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2384 | +#define ZORBA_INSTANTIATE(F,I) \ |
2385 | + template FloatImpl<F>& FloatImpl<F>::operator=( I const& ) |
2386 | + |
2387 | +ZORBA_INSTANTIATE(float,Integer); |
2388 | +ZORBA_INSTANTIATE(float,NegativeInteger); |
2389 | +ZORBA_INSTANTIATE(float,NonNegativeInteger); |
2390 | +ZORBA_INSTANTIATE(float,NonPositiveInteger); |
2391 | +ZORBA_INSTANTIATE(float,PositiveInteger); |
2392 | + |
2393 | +ZORBA_INSTANTIATE(double,Integer); |
2394 | +ZORBA_INSTANTIATE(double,NegativeInteger); |
2395 | +ZORBA_INSTANTIATE(double,NonNegativeInteger); |
2396 | +ZORBA_INSTANTIATE(double,NonPositiveInteger); |
2397 | +ZORBA_INSTANTIATE(double,PositiveInteger); |
2398 | +#undef ZORBA_INSTANTIATE |
2399 | |
2400 | ////////// math functions ///////////////////////////////////////////////////// |
2401 | |
2402 | -template<typename FloatType> |
2403 | -FloatImpl<FloatType> FloatImpl<FloatType>::acos() const { |
2404 | - if ( *this < neg_one() || *this > one() ) |
2405 | +template<typename F> |
2406 | +FloatImpl<F> FloatImpl<F>::acos() const { |
2407 | + if ( *this < numeric_consts<FloatImpl>::neg_one() || |
2408 | + *this > numeric_consts<FloatImpl>::one() ) |
2409 | return nan(); |
2410 | - return FloatImpl<FloatType>( |
2411 | - isNegZero() ? -std::acos( value_ ): std::acos( value_ ) |
2412 | + return FloatImpl<F>( |
2413 | + isNegZero() ? -std::acos( value_ ) : std::acos( value_ ) |
2414 | ); |
2415 | } |
2416 | |
2417 | -template<typename FloatType> |
2418 | -FloatImpl<FloatType> FloatImpl<FloatType>::asin() const { |
2419 | - if ( *this < neg_one() || *this > one() ) |
2420 | +template<typename F> |
2421 | +FloatImpl<F> FloatImpl<F>::asin() const { |
2422 | + if ( *this < numeric_consts<FloatImpl>::neg_one() || |
2423 | + *this > numeric_consts<FloatImpl>::one() ) |
2424 | return nan(); |
2425 | - return FloatImpl<FloatType>( std::asin( value_ ) ); |
2426 | + return FloatImpl<F>( std::asin( value_ ) ); |
2427 | } |
2428 | |
2429 | -template<typename FloatType> |
2430 | -void FloatImpl<FloatType>::frexp( FloatImpl<FloatType> &out_mantissa, |
2431 | - Integer &out_exponent ) const { |
2432 | +template<typename F> |
2433 | +void FloatImpl<F>::frexp( FloatImpl<F> &out_mantissa, |
2434 | + Integer &out_exponent ) const { |
2435 | int expint; |
2436 | out_mantissa = FloatImpl( ::frexp( value_, &expint ) ); |
2437 | out_exponent = Integer( expint ); |
2438 | @@ -246,13 +243,13 @@ |
2439 | out_integer = int_part; |
2440 | } |
2441 | |
2442 | -template<typename FloatType> |
2443 | -FloatImpl<FloatType> FloatImpl<FloatType>::round() const { |
2444 | - return round( Integer::zero() ); |
2445 | +template<typename F> |
2446 | +FloatImpl<F> FloatImpl<F>::round() const { |
2447 | + return round( numeric_consts<xs_integer>::zero() ); |
2448 | } |
2449 | |
2450 | -template<typename FloatType> |
2451 | -FloatImpl<FloatType> FloatImpl<FloatType>::round( Integer const &precision ) const { |
2452 | +template<typename F> |
2453 | +FloatImpl<F> FloatImpl<F>::round( Integer const &precision ) const { |
2454 | FloatImpl result; |
2455 | if ( isFinite() && !isZero() ) { |
2456 | MAPM m( |
2457 | @@ -274,8 +271,8 @@ |
2458 | return result; |
2459 | } |
2460 | |
2461 | -template<typename FloatType> FloatImpl<FloatType> |
2462 | -FloatImpl<FloatType>::roundHalfToEven( Integer const &precision) const { |
2463 | +template<typename F> |
2464 | +FloatImpl<F> FloatImpl<F>::roundHalfToEven( Integer const &precision ) const { |
2465 | FloatImpl result; |
2466 | if ( isFinite() && !isZero() ) { |
2467 | MAPM m( |
2468 | @@ -318,48 +315,32 @@ |
2469 | return false; |
2470 | } |
2471 | |
2472 | -template<typename FloatType> |
2473 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::nan() { |
2474 | - static FloatImpl<FloatType> const value( std::sqrt( -1.0 ) ); |
2475 | - return value; |
2476 | -} |
2477 | - |
2478 | -template<typename FloatType> |
2479 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_inf() { |
2480 | - static FloatImpl<FloatType> const value( |
2481 | - -std::numeric_limits<FloatType>::infinity() |
2482 | - ); |
2483 | - return value; |
2484 | -} |
2485 | - |
2486 | -template<typename FloatType> |
2487 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_one() { |
2488 | - static FloatImpl<FloatType> const value( -1 ); |
2489 | - return value; |
2490 | -} |
2491 | - |
2492 | -template<typename FloatType> |
2493 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::neg_zero() { |
2494 | - static FloatImpl<FloatType> const value( -0.0 ); |
2495 | - return value; |
2496 | -} |
2497 | - |
2498 | -template<typename FloatType> |
2499 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::one() { |
2500 | - static FloatImpl<FloatType> const value( 1 ); |
2501 | - return value; |
2502 | -} |
2503 | - |
2504 | -template<typename FloatType> |
2505 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::pos_inf() { |
2506 | - static FloatImpl<FloatType> const value( |
2507 | - std::numeric_limits<FloatType>::infinity() |
2508 | - ); |
2509 | - return value; |
2510 | -} |
2511 | - |
2512 | -template<typename FloatType> |
2513 | -zstring FloatImpl<FloatType>::toIntegerString() const { |
2514 | +template<typename F> |
2515 | +FloatImpl<F> const& FloatImpl<F>::nan() { |
2516 | + static FloatImpl<F> const value( std::sqrt( -1.0 ) ); |
2517 | + return value; |
2518 | +} |
2519 | + |
2520 | +template<typename F> |
2521 | +FloatImpl<F> const& FloatImpl<F>::neg_inf() { |
2522 | + static FloatImpl<F> const value( -std::numeric_limits<F>::infinity() ); |
2523 | + return value; |
2524 | +} |
2525 | + |
2526 | +template<typename F> |
2527 | +FloatImpl<F> const& FloatImpl<F>::neg_zero() { |
2528 | + static FloatImpl<F> const value( -0.0 ); |
2529 | + return value; |
2530 | +} |
2531 | + |
2532 | +template<typename F> |
2533 | +FloatImpl<F> const& FloatImpl<F>::pos_inf() { |
2534 | + static FloatImpl<F> const value( std::numeric_limits<F>::infinity() ); |
2535 | + return value; |
2536 | +} |
2537 | + |
2538 | +template<typename F> |
2539 | +zstring FloatImpl<F>::toIntegerString() const { |
2540 | if ( isNaN() ) |
2541 | return nan_str(); |
2542 | if (isPosInf() ) |
2543 | @@ -377,8 +358,8 @@ |
2544 | return buf; |
2545 | } |
2546 | |
2547 | -template<typename FloatType> |
2548 | -zstring FloatImpl<FloatType>::toString( bool no_scientific_format ) const { |
2549 | +template<typename F> |
2550 | +zstring FloatImpl<F>::toString( bool no_scientific_format ) const { |
2551 | if ( isNaN() ) |
2552 | return nan_str(); |
2553 | if ( isPosInf() ) |
2554 | @@ -390,17 +371,17 @@ |
2555 | if ( isNegZero() ) |
2556 | return "-0"; |
2557 | |
2558 | - FloatType const absVal = fabs( value_ ); |
2559 | - FloatType const lower = 0.000001f, upper = 1000000.0f; |
2560 | + value_type const abs_val = fabs( value_ ); |
2561 | + value_type const lower = 0.000001f, upper = 1000000.0f; |
2562 | |
2563 | - if (no_scientific_format || (absVal < upper && absVal >= lower) || absVal == 0) |
2564 | - { |
2565 | + if ( no_scientific_format || (abs_val >= lower && abs_val < upper) || |
2566 | + abs_val == 0 ) { |
2567 | #if 1 |
2568 | // This is the "spec" implementation, i.e., it is an exact application of |
2569 | // the spec in http://www.w3.org/TR/xpath-functions/#casting |
2570 | MAPM decimal_mapm( value_ ); |
2571 | decimal_mapm = decimal_mapm.round( precision_ ); |
2572 | - return Decimal::toString(decimal_mapm, isNegZero(), max_precision()); |
2573 | + return Decimal::toString( decimal_mapm, isNegZero(), max_precision() ); |
2574 | #else |
2575 | std::stringstream stream; |
2576 | stream.precision(7); |
2577 | @@ -471,12 +452,6 @@ |
2578 | } |
2579 | } |
2580 | |
2581 | -template<typename FloatType> |
2582 | -FloatImpl<FloatType> const& FloatImpl<FloatType>::zero() { |
2583 | - static FloatImpl<FloatType> const value( 0 ); |
2584 | - return value; |
2585 | -} |
2586 | - |
2587 | /////////////////////////////////////////////////////////////////////////////// |
2588 | |
2589 | template class FloatImpl<double>; |
2590 | |
2591 | === modified file 'src/zorbatypes/floatimpl.h' |
2592 | --- src/zorbatypes/floatimpl.h 2013-04-09 01:29:36 +0000 |
2593 | +++ src/zorbatypes/floatimpl.h 2013-05-08 15:05:31 +0000 |
2594 | @@ -29,14 +29,6 @@ |
2595 | #include "schema_types.h" |
2596 | #include "zorbatypes_decl.h" |
2597 | |
2598 | -#ifdef ZORBA_WITH_BIG_INTEGER |
2599 | -# define TEMPLATE_DECL(I) /* nothing */ |
2600 | -# define INTEGER_IMPL(I) IntegerImpl |
2601 | -#else |
2602 | -# define TEMPLATE_DECL(I) template<typename I> /* spacer */ |
2603 | -# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ |
2604 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2605 | - |
2606 | namespace zorba { |
2607 | |
2608 | template<typename FloatType> |
2609 | @@ -71,8 +63,8 @@ |
2610 | explicit FloatImpl( double n ); |
2611 | explicit FloatImpl( Decimal const &d ); |
2612 | |
2613 | - TEMPLATE_DECL(IntType) |
2614 | - explicit FloatImpl( INTEGER_IMPL(IntType) const &i ); |
2615 | + template<class T> |
2616 | + explicit FloatImpl( IntegerImpl<T> const &i ); |
2617 | |
2618 | /** |
2619 | * Constructs a %FloatImpl from a C string. |
2620 | @@ -126,8 +118,8 @@ |
2621 | FloatImpl& operator=( char const *s ); |
2622 | FloatImpl& operator=( Decimal const &d ); |
2623 | |
2624 | - TEMPLATE_DECL(I) |
2625 | - FloatImpl& operator=( INTEGER_IMPL(I) const &i ); |
2626 | + template<class T> |
2627 | + FloatImpl& operator=( IntegerImpl<T> const &i ); |
2628 | |
2629 | ////////// arithmetic operators ///////////////////////////////////////////// |
2630 | |
2631 | @@ -269,11 +261,9 @@ |
2632 | bool isPosZero() const; |
2633 | bool isNegZero() const; |
2634 | bool isInteger() const; |
2635 | + int sign() const; |
2636 | |
2637 | - static FloatImpl const& zero(); |
2638 | static FloatImpl const& neg_zero(); |
2639 | - static FloatImpl const& one(); |
2640 | - static FloatImpl const& neg_one(); |
2641 | static FloatImpl const& nan(); |
2642 | static FloatImpl const& pos_inf(); |
2643 | static FloatImpl const& neg_inf(); |
2644 | @@ -283,7 +273,6 @@ |
2645 | } |
2646 | |
2647 | zstring toIntegerString() const; |
2648 | - |
2649 | zstring toString( bool no_scientific_mode = false ) const; |
2650 | |
2651 | ///////////////////////////////////////////////////////////////////////////// |
2652 | @@ -298,14 +287,12 @@ |
2653 | value_type value_; |
2654 | precision_type precision_; |
2655 | |
2656 | - FloatImpl( value_type v, precision_type p ); |
2657 | - |
2658 | static precision_type max_precision(); |
2659 | |
2660 | void parse( char const* ); |
2661 | bool parse_etc( char const* ); |
2662 | |
2663 | - TEMPLATE_DECL(I) friend class IntegerImpl; |
2664 | + template<class T> friend class IntegerImpl; |
2665 | friend class Decimal; |
2666 | |
2667 | friend class FloatImpl<float>; |
2668 | @@ -412,24 +399,19 @@ |
2669 | parse( s ); |
2670 | } |
2671 | |
2672 | -template<typename F> template<typename G> |
2673 | +template<typename F> |
2674 | +template<typename G> |
2675 | inline FloatImpl<F>::FloatImpl( FloatImpl<G> const &f ) : |
2676 | value_( static_cast<F>( f.value_ ) ), precision_( max_precision() ) |
2677 | { |
2678 | } |
2679 | |
2680 | -template<typename F> |
2681 | -inline FloatImpl<F>::FloatImpl( value_type v, precision_type p ) : |
2682 | - value_( v ), precision_( p ) |
2683 | -{ |
2684 | -} |
2685 | - |
2686 | ////////// assignment operators /////////////////////////////////////////////// |
2687 | |
2688 | -template<typename F> template<typename G> |
2689 | +template<typename F> |
2690 | +template<typename G> |
2691 | inline FloatImpl<F>& FloatImpl<F>::operator=( FloatImpl<G> const &f ) { |
2692 | value_ = static_cast<F>( f.value_ ); |
2693 | - precision_ = max_precision(); |
2694 | return *this; |
2695 | } |
2696 | |
2697 | @@ -437,7 +419,6 @@ |
2698 | template<typename F> \ |
2699 | inline FloatImpl<F>& FloatImpl<F>::operator=( T n ) { \ |
2700 | value_ = static_cast<F>( n ); \ |
2701 | - precision_ = max_precision(); \ |
2702 | return *this; \ |
2703 | } |
2704 | |
2705 | @@ -668,7 +649,8 @@ |
2706 | ZORBA_FLOAT_OP(/=) |
2707 | #undef ZORBA_FLOAT_OP |
2708 | |
2709 | -template<typename F> template<typename G> |
2710 | +template<typename F> |
2711 | +template<typename G> |
2712 | inline FloatImpl<F>& FloatImpl<F>::operator%=( FloatImpl<G> const &f ) { |
2713 | value_ = std::fmod( value_, static_cast<F>( f.value_ ) ); |
2714 | return *this; |
2715 | @@ -676,7 +658,7 @@ |
2716 | |
2717 | template<typename F> |
2718 | inline FloatImpl<F> FloatImpl<F>::operator-() const { |
2719 | - return FloatImpl<F>( -value_, precision_ ); |
2720 | + return FloatImpl<F>( -value_ ); |
2721 | } |
2722 | |
2723 | #define ZORBA_FLOAT_OP(OP) \ |
2724 | @@ -932,7 +914,8 @@ |
2725 | |
2726 | ////////// miscellaneous ////////////////////////////////////////////////////// |
2727 | |
2728 | -template<typename F> template<typename G> |
2729 | +template<typename F> |
2730 | +template<typename G> |
2731 | inline int FloatImpl<F>::compare( FloatImpl<G> const &f ) const { |
2732 | return value_ < f.value_ ? -1 : value_ > f.value_ ? 1 : 0; |
2733 | } |
2734 | @@ -987,12 +970,17 @@ |
2735 | return isFinite() && ::floor( value_ ) == value_; |
2736 | } |
2737 | |
2738 | -template <typename F> |
2739 | +template<typename F> |
2740 | inline bool FloatImpl<F>::isZero() const { |
2741 | return value_ == 0; |
2742 | } |
2743 | |
2744 | template<typename F> |
2745 | +inline int FloatImpl<F>::sign() const { |
2746 | + return value_ > 0 ? 1 : value_ < 0 ? -1 : 0; |
2747 | +} |
2748 | + |
2749 | +template<typename F> |
2750 | inline std::ostream& operator<<( std::ostream &os, FloatImpl<F> const &f ) { |
2751 | return os << f.toString(); |
2752 | } |
2753 | @@ -1001,9 +989,6 @@ |
2754 | |
2755 | } // namespace zorba |
2756 | |
2757 | -#undef TEMPLATE_DECL |
2758 | -#undef INTEGER_IMPL |
2759 | - |
2760 | #endif // ZORBA_FLOATIMPL_H |
2761 | /* |
2762 | * Local variables: |
2763 | |
2764 | === modified file 'src/zorbatypes/integer.cpp' |
2765 | --- src/zorbatypes/integer.cpp 2013-04-09 22:38:19 +0000 |
2766 | +++ src/zorbatypes/integer.cpp 2013-05-08 15:05:31 +0000 |
2767 | @@ -16,166 +16,185 @@ |
2768 | |
2769 | #include "stdafx.h" |
2770 | |
2771 | +// standard |
2772 | #include <cerrno> |
2773 | #include <cstdlib> |
2774 | +#include <sstream> |
2775 | |
2776 | +// Zorba |
2777 | #include <zorba/internal/unique_ptr.h> |
2778 | #include "util/cxx_util.h" |
2779 | #include "util/string_util.h" |
2780 | |
2781 | -#include "integer.h" |
2782 | +// local |
2783 | #include "decimal.h" |
2784 | #include "floatimpl.h" |
2785 | +#include "integer.h" |
2786 | #include "numconversions.h" |
2787 | |
2788 | -#ifdef ZORBA_WITH_BIG_INTEGER |
2789 | -# define TEMPLATE_DECL(T) /* nothing */ |
2790 | -# define INTEGER_IMPL(T) IntegerImpl |
2791 | -#else |
2792 | -# define TEMPLATE_DECL(T) template<typename T> /* spacer */ |
2793 | -# define INTEGER_IMPL(T) IntegerImpl<T> /* spacer */ |
2794 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2795 | -#define INTEGER_IMPL_LL INTEGER_IMPL(long long) |
2796 | -#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) |
2797 | - |
2798 | using namespace std; |
2799 | |
2800 | -#ifndef ZORBA_WITH_BIG_INTEGER |
2801 | -unsigned long long MaxUIntegerValue = ~0ull >> 1; |
2802 | - |
2803 | -inline bool is_too_big( long long ) { |
2804 | - return false; |
2805 | -} |
2806 | - |
2807 | -inline bool is_too_big( unsigned long long n ) { |
2808 | - return n > MaxUIntegerValue; |
2809 | -} |
2810 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
2811 | - |
2812 | namespace zorba { |
2813 | |
2814 | /////////////////////////////////////////////////////////////////////////////// |
2815 | |
2816 | -TEMPLATE_DECL(I) |
2817 | -void INTEGER_IMPL(I)::parse( char const *s ) { |
2818 | +ostream& operator<<( ostream &o, MAPM const &m ) { |
2819 | + unique_ptr<char[]> const buf( new char[ m.exponent() + 3 ] ); |
2820 | + m.toIntegerString( buf.get() ); |
2821 | + return o << buf.get(); |
2822 | +} |
2823 | + |
2824 | +void integer_traits::throw_error( string const &what, bool throw_range_error ) { |
2825 | + if ( throw_range_error ) |
2826 | + throw range_error( what ); |
2827 | + throw invalid_argument( what ); |
2828 | +} |
2829 | + |
2830 | +void integer_traits::throw_error( MAPM const &n, char const *op, |
2831 | + bool throw_range_error ) { |
2832 | + ostringstream oss; |
2833 | + oss << n; |
2834 | + string const what( BUILD_STRING( oss.str(), ": not ", op, " 0" ) ); |
2835 | + throw_error( what, throw_range_error ); |
2836 | +} |
2837 | + |
2838 | +/////////////////////////////////////////////////////////////////////////////// |
2839 | + |
2840 | +template<class T> |
2841 | +void IntegerImpl<T>::parse( char const *s, bool throw_range_error ) { |
2842 | #ifdef ZORBA_WITH_BIG_INTEGER |
2843 | Decimal::parse( s, &value_, Decimal::parse_integer ); |
2844 | #else |
2845 | - value_type const temp( ztd::aton<value_type>( s ) ); |
2846 | - if ( is_too_big( temp ) ) |
2847 | - throw std::invalid_argument( |
2848 | - BUILD_STRING( '"', temp, "\": unsigned integer too big" ) |
2849 | - ); |
2850 | - value_ = temp; |
2851 | + try { |
2852 | + value_ = ztd::aton<value_type>( s ); |
2853 | + } |
2854 | + catch ( std::range_error const &e ) { |
2855 | + if ( throw_range_error ) |
2856 | + throw; |
2857 | + throw invalid_argument( e.what() ); |
2858 | + } |
2859 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2860 | + T::check_value( value_, throw_range_error ); |
2861 | } |
2862 | |
2863 | ////////// constructors /////////////////////////////////////////////////////// |
2864 | |
2865 | #ifdef ZORBA_WITH_BIG_INTEGER |
2866 | -IntegerImpl::IntegerImpl( long long n ) { |
2867 | +template<class T> |
2868 | +IntegerImpl<T>::IntegerImpl( long long n ) { |
2869 | ascii::itoa_buf_type buf; |
2870 | value_ = ascii::itoa( n, buf ); |
2871 | + T::check_value( value_, false ); |
2872 | } |
2873 | |
2874 | #if ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG |
2875 | -TEMPLATE_DECL(T) |
2876 | -INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) { |
2877 | +template<class T> |
2878 | +IntegerImpl<T>::IntegerImpl( unsigned int n ) { |
2879 | ascii::itoa_buf_type buf; |
2880 | value_ = ascii::itoa( n, buf ); |
2881 | + T::check_value( value_, false ); |
2882 | } |
2883 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ |
2884 | |
2885 | -IntegerImpl::IntegerImpl( unsigned long n ) { |
2886 | +template<class T> |
2887 | +IntegerImpl<T>::IntegerImpl( unsigned long n ) { |
2888 | ascii::itoa_buf_type buf; |
2889 | value_ = ascii::itoa( n, buf ); |
2890 | + T::check_value( value_, false ); |
2891 | } |
2892 | |
2893 | -IntegerImpl::IntegerImpl( unsigned long long n ) { |
2894 | +template<class T> |
2895 | +IntegerImpl<T>::IntegerImpl( unsigned long long n ) { |
2896 | ascii::itoa_buf_type buf; |
2897 | value_ = ascii::itoa( n, buf ); |
2898 | + T::check_value( value_, false ); |
2899 | } |
2900 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2901 | |
2902 | -TEMPLATE_DECL(T) |
2903 | -INTEGER_IMPL(T)::IntegerImpl( Decimal const &d ) { |
2904 | - value_ = ftoi( d.value_ ); |
2905 | +template<class T> |
2906 | +IntegerImpl<T>::IntegerImpl( Decimal const &d ) { |
2907 | + value_ = T::check_value( ftoi( d.value_ ), false ); |
2908 | } |
2909 | |
2910 | -TEMPLATE_DECL(T) |
2911 | -INTEGER_IMPL(T)::IntegerImpl( Double const &d ) { |
2912 | +template<class T> |
2913 | +IntegerImpl<T>::IntegerImpl( Double const &d ) { |
2914 | if ( !d.isFinite() ) |
2915 | throw std::invalid_argument( "not finite" ); |
2916 | - value_ = ftoi( d.getNumber() ); |
2917 | + value_ = T::check_value( ftoi( d.getNumber() ), false ); |
2918 | } |
2919 | |
2920 | -TEMPLATE_DECL(T) |
2921 | -INTEGER_IMPL(T)::IntegerImpl( Float const &f ) { |
2922 | +template<class T> |
2923 | +IntegerImpl<T>::IntegerImpl( Float const &f ) { |
2924 | if ( !f.isFinite() ) |
2925 | throw std::invalid_argument( "not finite" ); |
2926 | - value_ = ftoi( f.getNumber() ); |
2927 | + value_ = T::check_value( ftoi( f.getNumber() ), false ); |
2928 | } |
2929 | |
2930 | ////////// assignment operators /////////////////////////////////////////////// |
2931 | |
2932 | #ifdef ZORBA_WITH_BIG_INTEGER |
2933 | -IntegerImpl& IntegerImpl::operator=( long long n ) { |
2934 | - ascii::itoa_buf_type buf; |
2935 | - value_ = ascii::itoa( n, buf ); |
2936 | - return *this; |
2937 | -} |
2938 | - |
2939 | -IntegerImpl& IntegerImpl::operator=( unsigned long n ) { |
2940 | - ascii::itoa_buf_type buf; |
2941 | - value_ = ascii::itoa( n, buf ); |
2942 | - return *this; |
2943 | -} |
2944 | - |
2945 | -IntegerImpl& IntegerImpl::operator=( unsigned long long n ) { |
2946 | - ascii::itoa_buf_type buf; |
2947 | - value_ = ascii::itoa( n, buf ); |
2948 | +template<class T> |
2949 | +IntegerImpl<T>& IntegerImpl<T>::operator=( long long n ) { |
2950 | + ascii::itoa_buf_type buf; |
2951 | + value_ = ascii::itoa( n, buf ); |
2952 | + T::check_value( value_, true ); |
2953 | + return *this; |
2954 | +} |
2955 | + |
2956 | +template<class T> |
2957 | +IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long n ) { |
2958 | + ascii::itoa_buf_type buf; |
2959 | + value_ = ascii::itoa( n, buf ); |
2960 | + T::check_value( value_, true ); |
2961 | + return *this; |
2962 | +} |
2963 | + |
2964 | +template<class T> |
2965 | +IntegerImpl<T>& IntegerImpl<T>::operator=( unsigned long long n ) { |
2966 | + ascii::itoa_buf_type buf; |
2967 | + value_ = ascii::itoa( n, buf ); |
2968 | + T::check_value( value_, true ); |
2969 | return *this; |
2970 | } |
2971 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
2972 | |
2973 | -TEMPLATE_DECL(T) |
2974 | -INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Decimal const &d ) { |
2975 | - value_ = ftoi( d.value_ ); |
2976 | +template<class T> |
2977 | +IntegerImpl<T>& IntegerImpl<T>::operator=( Decimal const &d ) { |
2978 | + value_ = T::check_value( ftoi( d.value_ ), true ); |
2979 | return *this; |
2980 | } |
2981 | |
2982 | -TEMPLATE_DECL(T) |
2983 | -INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Double const &d ) { |
2984 | +template<class T> |
2985 | +IntegerImpl<T>& IntegerImpl<T>::operator=( Double const &d ) { |
2986 | if ( !d.isFinite() ) |
2987 | throw std::invalid_argument( "not finite" ); |
2988 | - value_ = ftoi( d.getNumber() ); |
2989 | + value_ = T::check_value( ftoi( d.getNumber() ), true ); |
2990 | return *this; |
2991 | } |
2992 | |
2993 | -TEMPLATE_DECL(T) |
2994 | -INTEGER_IMPL(T)& INTEGER_IMPL(T)::operator=( Float const &f ) { |
2995 | +template<class T> |
2996 | +IntegerImpl<T>& IntegerImpl<T>::operator=( Float const &f ) { |
2997 | if ( !f.isFinite() ) |
2998 | throw std::invalid_argument( "not finite" ); |
2999 | - value_ = ftoi( f.getNumber() ); |
3000 | + value_ = T::check_value( ftoi( f.getNumber() ), true ); |
3001 | return *this; |
3002 | } |
3003 | |
3004 | ////////// arithmetic operators /////////////////////////////////////////////// |
3005 | |
3006 | -#ifdef ZORBA_WITH_BIG_INTEGER |
3007 | -# define ZORBA_INSTANTIATE(OP) /* nothing */ |
3008 | -#else |
3009 | -# define ZORBA_INSTANTIATE(OP) \ |
3010 | - template Decimal operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \ |
3011 | - template Decimal operator OP( INTEGER_IMPL_ULL const&, Decimal const& ); |
3012 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
3013 | +#define ZORBA_INSTANTIATE(OP,I) \ |
3014 | + template Decimal operator OP( I const&, Decimal const& ); |
3015 | |
3016 | #define ZORBA_INTEGER_OP(OP) \ |
3017 | - TEMPLATE_DECL(T) \ |
3018 | - Decimal operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \ |
3019 | + template<class T> \ |
3020 | + Decimal operator OP( IntegerImpl<T> const &i, Decimal const &d ) { \ |
3021 | return i.itod() OP d.value_; \ |
3022 | } \ |
3023 | - ZORBA_INSTANTIATE(OP) |
3024 | + ZORBA_INSTANTIATE( OP, Integer ); \ |
3025 | + ZORBA_INSTANTIATE( OP, NegativeInteger ); \ |
3026 | + ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \ |
3027 | + ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \ |
3028 | + ZORBA_INSTANTIATE( OP, PositiveInteger ); |
3029 | |
3030 | ZORBA_INTEGER_OP(+) |
3031 | ZORBA_INTEGER_OP(-) |
3032 | @@ -187,15 +206,26 @@ |
3033 | |
3034 | #ifdef ZORBA_WITH_BIG_INTEGER |
3035 | |
3036 | -#define ZORBA_INTEGER_OP(OP,T) \ |
3037 | - IntegerImpl operator OP( IntegerImpl const &i, T n ) { \ |
3038 | - ascii::itoa_buf_type buf; \ |
3039 | - return i.value_ OP IntegerImpl::value_type( ascii::itoa( n, buf ) ); \ |
3040 | - } \ |
3041 | - IntegerImpl operator OP( T n, IntegerImpl const &i ) { \ |
3042 | - ascii::itoa_buf_type buf; \ |
3043 | - return IntegerImpl::value_type( ascii::itoa( n, buf ) ) OP i.value_; \ |
3044 | - } |
3045 | +#define ZORBA_INSTANTIATE(OP,I,N) \ |
3046 | + template Integer operator OP( I const&, N ); \ |
3047 | + template Integer operator OP( N, I const& ) |
3048 | + |
3049 | +#define ZORBA_INTEGER_OP(OP,N) \ |
3050 | + template<class T> \ |
3051 | + Integer operator OP( IntegerImpl<T> const &i, N n ) { \ |
3052 | + ascii::itoa_buf_type buf; \ |
3053 | + return i.value_ OP MAPM( ascii::itoa( n, buf ) ); \ |
3054 | + } \ |
3055 | + template<class T> \ |
3056 | + Integer operator OP( N n, IntegerImpl<T> const &i ) { \ |
3057 | + ascii::itoa_buf_type buf; \ |
3058 | + return MAPM( ascii::itoa( n, buf ) ) OP i.value_; \ |
3059 | + } \ |
3060 | + ZORBA_INSTANTIATE( OP, Integer, N ); \ |
3061 | + ZORBA_INSTANTIATE( OP, NegativeInteger, N ); \ |
3062 | + ZORBA_INSTANTIATE( OP, NonNegativeInteger, N ); \ |
3063 | + ZORBA_INSTANTIATE( OP, NonPositiveInteger, N ); \ |
3064 | + ZORBA_INSTANTIATE( OP, PositiveInteger, N ); |
3065 | |
3066 | ZORBA_INTEGER_OP(+,long long) |
3067 | ZORBA_INTEGER_OP(-,long long) |
3068 | @@ -210,30 +240,44 @@ |
3069 | ZORBA_INTEGER_OP(*,unsigned long long) |
3070 | ZORBA_INTEGER_OP(%,unsigned long long) |
3071 | #undef ZORBA_INTEGER_OP |
3072 | - |
3073 | -#define ZORBA_INTEGER_OP(T) \ |
3074 | - IntegerImpl operator/( IntegerImpl const &i, T n ) { \ |
3075 | - ascii::itoa_buf_type buf; \ |
3076 | - IntegerImpl::value_type const temp( ascii::itoa( n, buf ) ); \ |
3077 | - return IntegerImpl::ftoi( i.value_ / temp ); \ |
3078 | - } \ |
3079 | - IntegerImpl operator/( T n, IntegerImpl const &i ) { \ |
3080 | - ascii::itoa_buf_type buf; \ |
3081 | - IntegerImpl::value_type const temp( ascii::itoa( n, buf ) ); \ |
3082 | - return IntegerImpl::ftoi( temp / i.value_ ); \ |
3083 | - } |
3084 | +#undef ZORBA_INSTANTIATE |
3085 | + |
3086 | +#define ZORBA_INSTANTIATE(I,N) \ |
3087 | + template Integer operator/( I const&, N ); \ |
3088 | + template Integer operator/( N, I const& ) |
3089 | + |
3090 | +#define ZORBA_INTEGER_OP(N) \ |
3091 | + template<class T> \ |
3092 | + Integer operator/( IntegerImpl<T> const &i, N n ) { \ |
3093 | + ascii::itoa_buf_type buf; \ |
3094 | + MAPM const temp( ascii::itoa( n, buf ) ); \ |
3095 | + return Integer::ftoi( i.value_ / temp ); \ |
3096 | + } \ |
3097 | + template<class T> \ |
3098 | + Integer operator/( N n, IntegerImpl<T> const &i ) { \ |
3099 | + ascii::itoa_buf_type buf; \ |
3100 | + MAPM const temp( ascii::itoa( n, buf ) ); \ |
3101 | + return Integer::ftoi( temp / i.value_ ); \ |
3102 | + } \ |
3103 | + ZORBA_INSTANTIATE( Integer, N ); \ |
3104 | + ZORBA_INSTANTIATE( NegativeInteger, N ); \ |
3105 | + ZORBA_INSTANTIATE( NonNegativeInteger, N ); \ |
3106 | + ZORBA_INSTANTIATE( NonPositiveInteger, N ); \ |
3107 | + ZORBA_INSTANTIATE( PositiveInteger, N ); |
3108 | |
3109 | ZORBA_INTEGER_OP(long long) |
3110 | ZORBA_INTEGER_OP(unsigned long) |
3111 | ZORBA_INTEGER_OP(unsigned long long) |
3112 | #undef ZORBA_INTEGER_OP |
3113 | +#undef ZORBA_INSTANTIATE |
3114 | |
3115 | -#define ZORBA_INTEGER_OP(OP,T) \ |
3116 | - IntegerImpl& IntegerImpl::operator OP( T n ) { \ |
3117 | - ascii::itoa_buf_type buf; \ |
3118 | - value_type const temp( ascii::itoa( n, buf ) ); \ |
3119 | - value_ OP temp; \ |
3120 | - return *this; \ |
3121 | +#define ZORBA_INTEGER_OP(OP,N) \ |
3122 | + template<class T> \ |
3123 | + IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ |
3124 | + ascii::itoa_buf_type buf; \ |
3125 | + value_type const temp( ascii::itoa( n, buf ) ); \ |
3126 | + T::check_value( value_ OP temp, true ); \ |
3127 | + return *this; \ |
3128 | } |
3129 | |
3130 | ZORBA_INTEGER_OP(+=,long long) |
3131 | @@ -250,12 +294,13 @@ |
3132 | ZORBA_INTEGER_OP(%=,unsigned long long) |
3133 | #undef ZORBA_INTEGER_OP |
3134 | |
3135 | -#define ZORBA_INTEGER_OP(T) \ |
3136 | - IntegerImpl& IntegerImpl::operator/=( T n ) { \ |
3137 | - ascii::itoa_buf_type buf; \ |
3138 | - value_type const temp( ascii::itoa( n, buf ) ); \ |
3139 | - value_ = ftoi( value_ / temp ); \ |
3140 | - return *this; \ |
3141 | +#define ZORBA_INTEGER_OP(N) \ |
3142 | + template<class T> \ |
3143 | + IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ |
3144 | + ascii::itoa_buf_type buf; \ |
3145 | + value_type const temp( ascii::itoa( n, buf ) ); \ |
3146 | + T::check_value( value_ = ftoi( value_ / temp ), true ); \ |
3147 | + return *this; \ |
3148 | } |
3149 | |
3150 | ZORBA_INTEGER_OP(long long) |
3151 | @@ -266,36 +311,63 @@ |
3152 | |
3153 | ////////// relational operators /////////////////////////////////////////////// |
3154 | |
3155 | -TEMPLATE_DECL(T) |
3156 | -bool operator==( INTEGER_IMPL(T) const &i, Decimal const &d ) { |
3157 | +#define ZORBA_INSTANTIATE(OP,I) \ |
3158 | + template bool operator OP( I const&, Decimal const& ) |
3159 | + |
3160 | +template<class T> |
3161 | +bool operator==( IntegerImpl<T> const &i, Decimal const &d ) { |
3162 | return d.is_xs_integer() && i.itod() == d.value_; |
3163 | } |
3164 | |
3165 | -#define ZORBA_INTEGER_OP(OP) \ |
3166 | - TEMPLATE_DECL(T) \ |
3167 | - bool operator OP( INTEGER_IMPL(T) const &i, Decimal const &d ) { \ |
3168 | - return i.itod() OP d.value_; \ |
3169 | - } |
3170 | +ZORBA_INSTANTIATE( ==, Integer ); |
3171 | +ZORBA_INSTANTIATE( ==, NegativeInteger ); |
3172 | +ZORBA_INSTANTIATE( ==, NonNegativeInteger ); |
3173 | +ZORBA_INSTANTIATE( ==, NonPositiveInteger ); |
3174 | +ZORBA_INSTANTIATE( ==, PositiveInteger ); |
3175 | + |
3176 | +#define ZORBA_INTEGER_OP(OP) \ |
3177 | + template<class T> \ |
3178 | + bool operator OP( IntegerImpl<T> const &i, Decimal const &d ) { \ |
3179 | + return i.itod() OP d.value_; \ |
3180 | + } \ |
3181 | + ZORBA_INSTANTIATE( OP, Integer ); \ |
3182 | + ZORBA_INSTANTIATE( OP, NegativeInteger ); \ |
3183 | + ZORBA_INSTANTIATE( OP, NonNegativeInteger ); \ |
3184 | + ZORBA_INSTANTIATE( OP, NonPositiveInteger ); \ |
3185 | + ZORBA_INSTANTIATE( OP, PositiveInteger ); |
3186 | |
3187 | ZORBA_INTEGER_OP(!=) |
3188 | ZORBA_INTEGER_OP(< ) |
3189 | ZORBA_INTEGER_OP(<=) |
3190 | ZORBA_INTEGER_OP(> ) |
3191 | ZORBA_INTEGER_OP(>=) |
3192 | +#undef ZORBA_INSTANTIATE |
3193 | #undef ZORBA_INTEGER_OP |
3194 | |
3195 | #ifdef ZORBA_WITH_BIG_INTEGER |
3196 | |
3197 | -#define ZORBA_INTEGER_OP(OP,T) \ |
3198 | - bool operator OP( IntegerImpl const &i, T n ) { \ |
3199 | - ascii::itoa_buf_type buf; \ |
3200 | - return i.value_ OP IntegerImpl::value_type( ascii::itoa( n, buf ) ); \ |
3201 | - } \ |
3202 | - \ |
3203 | - bool operator OP( T n, IntegerImpl const &i ) { \ |
3204 | - ascii::itoa_buf_type buf; \ |
3205 | - return IntegerImpl::value_type( ascii::itoa( n, buf ) ) OP i.value_; \ |
3206 | - } |
3207 | +#define ZORBA_INSTANTIATE(OP,I,N) \ |
3208 | + template bool operator OP( I const&, N ); \ |
3209 | + template bool operator OP( N, I const& ) |
3210 | + |
3211 | +#define ZORBA_INTEGER_OP(OP,N) \ |
3212 | + template<class T> \ |
3213 | + bool operator OP( IntegerImpl<T> const &i, N n ) { \ |
3214 | + ascii::itoa_buf_type buf; \ |
3215 | + return i.value_ OP MAPM( ascii::itoa( n, buf ) ); \ |
3216 | + } \ |
3217 | + \ |
3218 | + template<class T> \ |
3219 | + bool operator OP( N n, IntegerImpl<T> const &i ) { \ |
3220 | + ascii::itoa_buf_type buf; \ |
3221 | + return MAPM( ascii::itoa( n, buf ) ) OP i.value_; \ |
3222 | + } \ |
3223 | + \ |
3224 | + ZORBA_INSTANTIATE( OP, Integer, N ); \ |
3225 | + ZORBA_INSTANTIATE( OP, NegativeInteger, N ); \ |
3226 | + ZORBA_INSTANTIATE( OP, NonNegativeInteger, N ); \ |
3227 | + ZORBA_INSTANTIATE( OP, NonPositiveInteger, N ); \ |
3228 | + ZORBA_INSTANTIATE( OP, PositiveInteger, N ); |
3229 | |
3230 | ZORBA_INTEGER_OP(==,long long) |
3231 | ZORBA_INTEGER_OP(!=,long long) |
3232 | @@ -315,27 +387,14 @@ |
3233 | ZORBA_INTEGER_OP(<=,unsigned long long) |
3234 | ZORBA_INTEGER_OP(> ,unsigned long long) |
3235 | ZORBA_INTEGER_OP(>=,unsigned long long) |
3236 | - |
3237 | -#else /* ZORBA_WITH_BIG_INTEGER */ |
3238 | - |
3239 | -#define ZORBA_INSTANTIATE(OP) \ |
3240 | - template bool operator OP( INTEGER_IMPL_LL const&, Decimal const& ); \ |
3241 | - template bool operator OP( INTEGER_IMPL_ULL const&, Decimal const& ) |
3242 | - |
3243 | -ZORBA_INSTANTIATE(==); |
3244 | -ZORBA_INSTANTIATE(!=); |
3245 | -ZORBA_INSTANTIATE(< ); |
3246 | -ZORBA_INSTANTIATE(<=); |
3247 | -ZORBA_INSTANTIATE(> ); |
3248 | -ZORBA_INSTANTIATE(>=); |
3249 | #undef ZORBA_INSTANTIATE |
3250 | |
3251 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3252 | |
3253 | ////////// math functions ///////////////////////////////////////////////////// |
3254 | |
3255 | -TEMPLATE_DECL(T) |
3256 | -Double INTEGER_IMPL(T)::pow( INTEGER_IMPL(T) const &power ) const { |
3257 | +template<class T> |
3258 | +Double IntegerImpl<T>::pow( IntegerImpl<T> const &power ) const { |
3259 | #ifdef ZORBA_WITH_BIG_INTEGER |
3260 | value_type const result( value_.pow( power.value_, 15 ) ); |
3261 | char buf[300]; |
3262 | @@ -349,30 +408,30 @@ |
3263 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3264 | } |
3265 | |
3266 | -TEMPLATE_DECL(T) |
3267 | -INTEGER_IMPL(T) INTEGER_IMPL(T)::round( IntegerImpl const &precision ) const { |
3268 | +template<class T> |
3269 | +IntegerImpl<T> IntegerImpl<T>::round( IntegerImpl<T> const &precision ) const { |
3270 | return IntegerImpl( Decimal::round2( itod(), precision.itod() ) ); |
3271 | } |
3272 | |
3273 | -TEMPLATE_DECL(T) |
3274 | -INTEGER_IMPL(T) |
3275 | -INTEGER_IMPL(T)::roundHalfToEven( IntegerImpl const &precision ) const { |
3276 | +template<class T> |
3277 | +IntegerImpl<T> |
3278 | +IntegerImpl<T>::roundHalfToEven( IntegerImpl const &precision ) const { |
3279 | return IntegerImpl( Decimal::roundHalfToEven2( itod(), precision.itod() ) ); |
3280 | } |
3281 | |
3282 | ////////// miscellaneous ////////////////////////////////////////////////////// |
3283 | |
3284 | #ifndef ZORBA_WITH_BIG_INTEGER |
3285 | -TEMPLATE_DECL(T) |
3286 | -typename INTEGER_IMPL(T)::value_type INTEGER_IMPL(T)::ftoi( MAPM const &d ) { |
3287 | +template<class T> |
3288 | +typename IntegerImpl<T>::value_type IntegerImpl<T>::ftoi( MAPM const &d ) { |
3289 | MAPM const temp( d.sign() >= 0 ? d.floor() : d.ceil() ); |
3290 | unique_ptr<char[]> const buf( new char[ temp.exponent() + 3 ] ); |
3291 | temp.toIntegerString( buf.get() ); |
3292 | return ztd::aton<value_type>( buf.get() ); |
3293 | } |
3294 | |
3295 | -TEMPLATE_DECL(T) |
3296 | -MAPM INTEGER_IMPL(T)::itod() const { |
3297 | +template<class T> |
3298 | +MAPM IntegerImpl<T>::itod() const { |
3299 | if ( is_cxx_long() ) |
3300 | return static_cast<long>( value_ ); |
3301 | ascii::itoa_buf_type buf; |
3302 | @@ -381,77 +440,79 @@ |
3303 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3304 | |
3305 | #ifdef ZORBA_WITH_BIG_INTEGER |
3306 | -size_t IntegerImpl::alloc_size() const { |
3307 | + |
3308 | +static MAPM xs_byte_min( "-128" ); |
3309 | +static MAPM xs_byte_max( "127" ); |
3310 | +static MAPM xs_short_min( "-32768" ); |
3311 | +static MAPM xs_short_max( "32767" ); |
3312 | +static MAPM xs_unsignedByte_max( "256" ); |
3313 | +static MAPM xs_unsignedInt_max( "4294967295" ); |
3314 | +static MAPM xs_unsignedLong_max( "18446744073709551615" ); |
3315 | +static MAPM xs_unsignedShort_max( "65536" ); |
3316 | + |
3317 | +template<class T> |
3318 | +size_t IntegerImpl<T>::alloc_size() const { |
3319 | return value_.significant_digits(); |
3320 | } |
3321 | |
3322 | -uint32_t IntegerImpl::hash() const { |
3323 | +template<class T> |
3324 | +uint32_t IntegerImpl<T>::hash() const { |
3325 | return Decimal::hash( value_ ); |
3326 | } |
3327 | |
3328 | -bool IntegerImpl::is_xs_byte() const { |
3329 | - static MAPM xs_byte_min( "-128" ); |
3330 | - static MAPM xs_byte_max( "127" ); |
3331 | +template<class T> |
3332 | +bool IntegerImpl<T>::is_xs_byte() const { |
3333 | return value_ >= xs_byte_min && value_ <= xs_byte_max; |
3334 | } |
3335 | |
3336 | -bool IntegerImpl::is_xs_short() const { |
3337 | - static MAPM xs_short_min( "-32768" ); |
3338 | - static MAPM xs_short_max( "32767" ); |
3339 | +template<class T> |
3340 | +bool IntegerImpl<T>::is_xs_short() const { |
3341 | return value_ >= xs_short_min && value_ <= xs_short_max; |
3342 | } |
3343 | |
3344 | -bool IntegerImpl::is_xs_unsignedByte() const { |
3345 | - static MAPM xs_unsignedByte_max( "256" ); |
3346 | +template<class T> |
3347 | +bool IntegerImpl<T>::is_xs_unsignedByte() const { |
3348 | return value_.sign() >= 0 && value_ <= xs_unsignedByte_max; |
3349 | } |
3350 | |
3351 | -bool IntegerImpl::is_xs_unsignedInt() const { |
3352 | - static MAPM xs_unsignedInt_max( "4294967295" ); |
3353 | +template<class T> |
3354 | +bool IntegerImpl<T>::is_xs_unsignedInt() const { |
3355 | return value_.sign() >= 0 && value_ <= xs_unsignedInt_max; |
3356 | } |
3357 | |
3358 | -bool IntegerImpl::is_xs_unsignedLong() const { |
3359 | - static MAPM xs_unsignedLong_max( "18446744073709551615" ); |
3360 | +template<class T> |
3361 | +bool IntegerImpl<T>::is_xs_unsignedLong() const { |
3362 | return value_.sign() >= 0 && value_ <= xs_unsignedLong_max; |
3363 | } |
3364 | |
3365 | -bool IntegerImpl::is_xs_unsignedShort() const { |
3366 | - static MAPM xs_unsignedShort_max( "65536" ); |
3367 | +template<class T> |
3368 | +bool IntegerImpl<T>::is_xs_unsignedShort() const { |
3369 | return value_.sign() >= 0 && value_ <= xs_unsignedShort_max; |
3370 | } |
3371 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3372 | |
3373 | -TEMPLATE_DECL(T) |
3374 | -INTEGER_IMPL(T) const& INTEGER_IMPL(T)::one() { |
3375 | - static INTEGER_IMPL(T) const i(1); |
3376 | - return i; |
3377 | -} |
3378 | - |
3379 | -TEMPLATE_DECL(T) |
3380 | -zstring INTEGER_IMPL(T)::toString() const { |
3381 | +template<class T> |
3382 | +zstring IntegerImpl<T>::toString() const { |
3383 | #ifdef ZORBA_WITH_BIG_INTEGER |
3384 | - unique_ptr<char[]> const buf( new char[ value_.exponent() + 3 ] ); |
3385 | - value_.toIntegerString( buf.get() ); |
3386 | - return buf.get(); |
3387 | + ostringstream oss; |
3388 | + oss << value_; |
3389 | + return oss.str(); |
3390 | #else |
3391 | ascii::itoa_buf_type buf; |
3392 | return ascii::itoa( value_, buf ); |
3393 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3394 | } |
3395 | |
3396 | -TEMPLATE_DECL(T) |
3397 | -INTEGER_IMPL(T) const& INTEGER_IMPL(T)::zero() { |
3398 | - static INTEGER_IMPL(T) const i(0); |
3399 | - return i; |
3400 | -} |
3401 | - |
3402 | -/////////////////////////////////////////////////////////////////////////////// |
3403 | - |
3404 | -#ifndef ZORBA_WITH_BIG_INTEGER |
3405 | -template class IntegerImpl<long long>; |
3406 | -template class IntegerImpl<unsigned long long>; |
3407 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
3408 | +/////////////////////////////////////////////////////////////////////////////// |
3409 | + |
3410 | +// instantiate integer types |
3411 | +template class IntegerImpl<integer_traits>; |
3412 | +template class IntegerImpl<negative_traits>; |
3413 | +template class IntegerImpl<nonNegative_traits>; |
3414 | +template class IntegerImpl<nonPositive_traits>; |
3415 | +template class IntegerImpl<positive_traits>; |
3416 | + |
3417 | +/////////////////////////////////////////////////////////////////////////////// |
3418 | |
3419 | } // namespace zorba |
3420 | /* vim:set et sw=2 ts=2: */ |
3421 | |
3422 | === modified file 'src/zorbatypes/integer.h' |
3423 | --- src/zorbatypes/integer.h 2013-02-26 04:12:43 +0000 |
3424 | +++ src/zorbatypes/integer.h 2013-05-08 15:05:31 +0000 |
3425 | @@ -18,60 +18,142 @@ |
3426 | #ifndef ZORBA_INTEGER_H |
3427 | #define ZORBA_INTEGER_H |
3428 | |
3429 | +// standard |
3430 | #include <cmath> |
3431 | #include <limits> |
3432 | +#include <string> |
3433 | |
3434 | +// Zorba |
3435 | #include <zorba/config.h> |
3436 | - |
3437 | #include "common/common.h" |
3438 | #include "util/stl_util.h" |
3439 | +#include "util/string_util.h" |
3440 | |
3441 | +// local |
3442 | #include "m_apm.h" |
3443 | +#include "numeric_types.h" |
3444 | #include "schema_types_base.h" |
3445 | #include "zorbatypes_decl.h" |
3446 | #include "zstring.h" |
3447 | |
3448 | -#ifdef ZORBA_WITH_BIG_INTEGER |
3449 | -# define TEMPLATE_DECL(I) /* nothing */ |
3450 | -# define INTEGER_IMPL(I) IntegerImpl |
3451 | -# define TEMPLATE_TYPENAME /* nothing */ |
3452 | -#else |
3453 | -# define TEMPLATE_DECL(I) template<typename I> /* spacer */ |
3454 | -# define INTEGER_IMPL(I) IntegerImpl<I> /* spacer */ |
3455 | -# define TEMPLATE_TYPENAME typename |
3456 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
3457 | -#define INTEGER_IMPL_LL INTEGER_IMPL(long long) |
3458 | -#define INTEGER_IMPL_ULL INTEGER_IMPL(unsigned long long) |
3459 | - |
3460 | namespace zorba { |
3461 | |
3462 | -TEMPLATE_DECL(I) |
3463 | +template<class TraitsType> |
3464 | class IntegerImpl; |
3465 | |
3466 | -namespace serialization |
3467 | -{ |
3468 | +namespace serialization { |
3469 | class Archiver; |
3470 | - TEMPLATE_DECL(I) void operator&( Archiver&, INTEGER_IMPL(I)& ); |
3471 | + |
3472 | + template<class T> |
3473 | + void operator&( Archiver&, IntegerImpl<T>& ); |
3474 | } |
3475 | |
3476 | /////////////////////////////////////////////////////////////////////////////// |
3477 | |
3478 | -TEMPLATE_DECL(IntType) |
3479 | -class IntegerImpl |
3480 | -{ |
3481 | +std::ostream& operator<<( std::ostream&, MAPM const& ); |
3482 | + |
3483 | +struct integer_traits { |
3484 | + static int const default_value = 0; |
3485 | + |
3486 | + template<typename ValueType> |
3487 | + static ValueType check_value( ValueType n, bool ) { |
3488 | + return n; |
3489 | + } |
3490 | + |
3491 | + static MAPM const& check_value( MAPM const &n, bool ) { |
3492 | + return n; |
3493 | + } |
3494 | + |
3495 | +protected: |
3496 | + static void throw_error( std::string const&, bool ); |
3497 | + |
3498 | + template<typename ValueType> |
3499 | + static void throw_error( ValueType n, char const *op, |
3500 | + bool throw_range_error ) { |
3501 | + std::string const what( BUILD_STRING( n, ": not ", op, " 0" ) ); |
3502 | + throw_error( what, throw_range_error ); |
3503 | + } |
3504 | + |
3505 | + static void throw_error( MAPM const &n, char const *op, |
3506 | + bool throw_range_error ); |
3507 | +}; |
3508 | + |
3509 | +struct nonPositive_traits : integer_traits { |
3510 | + template<typename ValueType> |
3511 | + static ValueType check_value( ValueType n, bool throw_range_error ) { |
3512 | + if ( !ztd::le0( n ) ) |
3513 | + throw_error( n, "<=", throw_range_error ); |
3514 | + return n; |
3515 | + } |
3516 | + static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { |
3517 | + if ( !(n.sign() <= 0) ) |
3518 | + throw_error( n, "<=", throw_range_error ); |
3519 | + return n; |
3520 | + } |
3521 | +}; |
3522 | + |
3523 | +struct negative_traits : nonPositive_traits { |
3524 | + static int const default_value = -1; |
3525 | + |
3526 | + template<typename ValueType> |
3527 | + static ValueType check_value( ValueType n, bool throw_range_error ) { |
3528 | + if ( !ztd::lt0( n ) ) |
3529 | + throw_error( n, "<", throw_range_error ); |
3530 | + return n; |
3531 | + } |
3532 | + static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { |
3533 | + if ( !(n.sign() < 0) ) |
3534 | + throw_error( n, "<", throw_range_error ); |
3535 | + return n; |
3536 | + } |
3537 | +}; |
3538 | + |
3539 | +struct nonNegative_traits : integer_traits { |
3540 | + template<typename ValueType> |
3541 | + static ValueType check_value( ValueType n, bool throw_range_error ) { |
3542 | + if ( !ztd::ge0( n ) ) |
3543 | + throw_error( n, ">=", throw_range_error ); |
3544 | + return n; |
3545 | + } |
3546 | + static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { |
3547 | + if ( !(n.sign() >= 0) ) |
3548 | + throw_error( n, ">=", throw_range_error ); |
3549 | + return n; |
3550 | + } |
3551 | +}; |
3552 | + |
3553 | +struct positive_traits : nonNegative_traits { |
3554 | + static int const default_value = 1; |
3555 | + |
3556 | + template<typename ValueType> |
3557 | + static ValueType check_value( ValueType n, bool throw_range_error ) { |
3558 | + if ( !ztd::gt0( n ) ) |
3559 | + throw_error( n, ">", throw_range_error ); |
3560 | + return n; |
3561 | + } |
3562 | + static MAPM const& check_value( MAPM const &n, bool throw_range_error ) { |
3563 | + if ( !(n.sign() > 0) ) |
3564 | + throw_error( n, ">", throw_range_error ); |
3565 | + return n; |
3566 | + } |
3567 | +}; |
3568 | + |
3569 | +template<class TraitsType> |
3570 | +class IntegerImpl { |
3571 | public: |
3572 | #ifdef ZORBA_WITH_BIG_INTEGER |
3573 | typedef MAPM value_type; |
3574 | #else |
3575 | - typedef IntType value_type; |
3576 | + typedef long long value_type; |
3577 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3578 | + typedef TraitsType traits_type; |
3579 | |
3580 | ////////// constructors ///////////////////////////////////////////////////// |
3581 | |
3582 | explicit IntegerImpl( char c ); |
3583 | explicit IntegerImpl( signed char c ); |
3584 | explicit IntegerImpl( short n ); |
3585 | - explicit IntegerImpl( int n = 0 ); |
3586 | + explicit IntegerImpl( int n = traits_type::default_value ); |
3587 | explicit IntegerImpl( long n ); |
3588 | explicit IntegerImpl( long long n ); |
3589 | explicit IntegerImpl( unsigned char c ); |
3590 | @@ -112,27 +194,27 @@ |
3591 | explicit IntegerImpl( Float const &f ); |
3592 | |
3593 | /** |
3594 | - * Constructs from another %IntegerImpl even if its \c IntType is different. |
3595 | - * (This subsumes the conventional copy constructor.) |
3596 | + * Constructs from another %IntegerImpl even if its \c TraitsType is |
3597 | + * different. (This subsumes the conventional copy constructor.) |
3598 | * |
3599 | - * @tparam IntType2 the integer type of \a i. |
3600 | + * @tparam TraitsType2 The traits type of \a i. |
3601 | * @param i The %IntegerImpl to copy from. |
3602 | */ |
3603 | - TEMPLATE_DECL(IntType2) |
3604 | - IntegerImpl( INTEGER_IMPL(IntType2) const &i ); |
3605 | + template<class TraitsType2> |
3606 | + IntegerImpl( IntegerImpl<TraitsType2> const &i ); |
3607 | |
3608 | ////////// assignment operators ///////////////////////////////////////////// |
3609 | |
3610 | /** |
3611 | - * Assign from an %IntegerImpl even if its \c IntType is different. |
3612 | + * Assign from an %IntegerImpl even if its \c TraitsType is different. |
3613 | * (This subsumes the conventional assignment operator.) |
3614 | * |
3615 | - * @tparam IntType2 the integer type of \a i. |
3616 | + * @tparam TraitsType2 The traits type of \a i. |
3617 | * @param i The %IntegerImpl to assign from. |
3618 | * @return Returns \c *this. |
3619 | */ |
3620 | - TEMPLATE_DECL(IntType2) |
3621 | - IntegerImpl& operator=( INTEGER_IMPL(IntType2) const &i ); |
3622 | + template<class TraitsType2> |
3623 | + IntegerImpl& operator=( IntegerImpl<TraitsType2> const &i ); |
3624 | |
3625 | IntegerImpl& operator=( char c ); |
3626 | IntegerImpl& operator=( signed char c ); |
3627 | @@ -155,16 +237,15 @@ |
3628 | |
3629 | ////////// arithmetic operators ///////////////////////////////////////////// |
3630 | |
3631 | -#define ZORBA_INTEGER_OP(OP) \ |
3632 | - TEMPLATE_DECL(I) friend \ |
3633 | - INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, \ |
3634 | - INTEGER_IMPL(I) const& ); \ |
3635 | - \ |
3636 | - TEMPLATE_DECL(I) friend \ |
3637 | - Decimal operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \ |
3638 | - \ |
3639 | - TEMPLATE_DECL(I) friend \ |
3640 | - Decimal operator OP( Decimal const&, INTEGER_IMPL(I) const& ) |
3641 | +#define ZORBA_INTEGER_OP(OP) \ |
3642 | + template<class T,class U> friend \ |
3643 | + Integer operator OP( IntegerImpl<T> const&, IntegerImpl<U> const& ); \ |
3644 | + \ |
3645 | + template<class T> friend \ |
3646 | + Decimal operator OP( IntegerImpl<T> const&, Decimal const& ); \ |
3647 | + \ |
3648 | + template<class T> friend \ |
3649 | + Decimal operator OP( Decimal const&, IntegerImpl<T> const& ) |
3650 | |
3651 | ZORBA_INTEGER_OP(+); |
3652 | ZORBA_INTEGER_OP(-); |
3653 | @@ -173,12 +254,12 @@ |
3654 | ZORBA_INTEGER_OP(%); |
3655 | #undef ZORBA_INTEGER_OP |
3656 | |
3657 | -#define ZORBA_INTEGER_OP(OP,T) \ |
3658 | - TEMPLATE_DECL(I) friend \ |
3659 | - INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const&, T ); \ |
3660 | - \ |
3661 | - TEMPLATE_DECL(I) friend \ |
3662 | - INTEGER_IMPL(I) operator OP( T, INTEGER_IMPL(I) const& ) |
3663 | +#define ZORBA_INTEGER_OP(OP,N) \ |
3664 | + template<class T> friend \ |
3665 | + Integer operator OP( IntegerImpl<T> const&, N ); \ |
3666 | + \ |
3667 | + template<class T> friend \ |
3668 | + Integer operator OP( N, IntegerImpl<T> const& ) |
3669 | |
3670 | ZORBA_INTEGER_OP(+,char); |
3671 | ZORBA_INTEGER_OP(-,char); |
3672 | @@ -247,19 +328,14 @@ |
3673 | ZORBA_INTEGER_OP(%,double); |
3674 | #undef ZORBA_INTEGER_OP |
3675 | |
3676 | -#define ZORBA_INTEGER_OP(OP,TYPE) \ |
3677 | - IntegerImpl& operator OP( TYPE ) |
3678 | +#define ZORBA_INTEGER_OP(OP,T) \ |
3679 | + IntegerImpl& operator OP( T ) |
3680 | |
3681 | ZORBA_INTEGER_OP(+=,IntegerImpl const&); |
3682 | ZORBA_INTEGER_OP(-=,IntegerImpl const&); |
3683 | ZORBA_INTEGER_OP(*=,IntegerImpl const&); |
3684 | ZORBA_INTEGER_OP(/=,IntegerImpl const&); |
3685 | ZORBA_INTEGER_OP(%=,IntegerImpl const&); |
3686 | -#undef ZORBA_INTEGER_OP |
3687 | - |
3688 | -#define ZORBA_INTEGER_OP(OP,T) \ |
3689 | - IntegerImpl& operator OP( T ) |
3690 | - |
3691 | ZORBA_INTEGER_OP(+=,char); |
3692 | ZORBA_INTEGER_OP(-=,char); |
3693 | ZORBA_INTEGER_OP(*=,char); |
3694 | @@ -327,7 +403,7 @@ |
3695 | ZORBA_INTEGER_OP(%=,double); |
3696 | #undef ZORBA_INTEGER_OP |
3697 | |
3698 | - IntegerImpl operator-() const; |
3699 | + Integer operator-() const; |
3700 | |
3701 | IntegerImpl& operator++(); |
3702 | IntegerImpl operator++(int); |
3703 | @@ -336,107 +412,107 @@ |
3704 | |
3705 | ////////// relational operators ///////////////////////////////////////////// |
3706 | |
3707 | -#define ZORBA_INTEGER_OP(OP) \ |
3708 | - TEMPLATE_DECL(I) friend \ |
3709 | - bool operator OP( INTEGER_IMPL(I) const&, INTEGER_IMPL(I) const& ); \ |
3710 | - \ |
3711 | - TEMPLATE_DECL(I) friend \ |
3712 | - bool operator OP( INTEGER_IMPL(I) const&, Decimal const& ); \ |
3713 | - \ |
3714 | - TEMPLATE_DECL(I) friend \ |
3715 | - bool operator OP( Decimal const&, INTEGER_IMPL(I) const& ) |
3716 | - |
3717 | - ZORBA_INTEGER_OP(==); |
3718 | - ZORBA_INTEGER_OP(!=); |
3719 | - ZORBA_INTEGER_OP(< ); |
3720 | - ZORBA_INTEGER_OP(<=); |
3721 | - ZORBA_INTEGER_OP(> ); |
3722 | - ZORBA_INTEGER_OP(>=); |
3723 | -#undef ZORBA_INTEGER_OP |
3724 | - |
3725 | -#define ZORBA_INTEGER_OP(OP,T) \ |
3726 | - TEMPLATE_DECL(I) friend bool operator OP( INTEGER_IMPL(I) const&, T ); \ |
3727 | - TEMPLATE_DECL(I) friend bool operator OP( T, INTEGER_IMPL(I) const& ) |
3728 | - |
3729 | - ZORBA_INTEGER_OP(==,char); |
3730 | - ZORBA_INTEGER_OP(!=,char); |
3731 | - ZORBA_INTEGER_OP(< ,char); |
3732 | - ZORBA_INTEGER_OP(<=,char); |
3733 | - ZORBA_INTEGER_OP(> ,char); |
3734 | - ZORBA_INTEGER_OP(>=,char); |
3735 | - ZORBA_INTEGER_OP(==,signed char); |
3736 | - ZORBA_INTEGER_OP(!=,signed char); |
3737 | - ZORBA_INTEGER_OP(< ,signed char); |
3738 | - ZORBA_INTEGER_OP(<=,signed char); |
3739 | - ZORBA_INTEGER_OP(> ,signed char); |
3740 | - ZORBA_INTEGER_OP(>=,signed char); |
3741 | - ZORBA_INTEGER_OP(==,short); |
3742 | - ZORBA_INTEGER_OP(!=,short); |
3743 | - ZORBA_INTEGER_OP(< ,short); |
3744 | - ZORBA_INTEGER_OP(<=,short); |
3745 | - ZORBA_INTEGER_OP(> ,short); |
3746 | - ZORBA_INTEGER_OP(>=,short); |
3747 | - ZORBA_INTEGER_OP(==,int); |
3748 | - ZORBA_INTEGER_OP(!=,int); |
3749 | - ZORBA_INTEGER_OP(< ,int); |
3750 | - ZORBA_INTEGER_OP(<=,int); |
3751 | - ZORBA_INTEGER_OP(> ,int); |
3752 | - ZORBA_INTEGER_OP(>=,int); |
3753 | - ZORBA_INTEGER_OP(==,long); |
3754 | - ZORBA_INTEGER_OP(!=,long); |
3755 | - ZORBA_INTEGER_OP(< ,long); |
3756 | - ZORBA_INTEGER_OP(<=,long); |
3757 | - ZORBA_INTEGER_OP(> ,long); |
3758 | - ZORBA_INTEGER_OP(>=,long); |
3759 | - ZORBA_INTEGER_OP(==,long long); |
3760 | - ZORBA_INTEGER_OP(!=,long long); |
3761 | - ZORBA_INTEGER_OP(< ,long long); |
3762 | - ZORBA_INTEGER_OP(<=,long long); |
3763 | - ZORBA_INTEGER_OP(> ,long long); |
3764 | - ZORBA_INTEGER_OP(>=,long long); |
3765 | - ZORBA_INTEGER_OP(==,unsigned char); |
3766 | - ZORBA_INTEGER_OP(!=,unsigned char); |
3767 | - ZORBA_INTEGER_OP(< ,unsigned char); |
3768 | - ZORBA_INTEGER_OP(<=,unsigned char); |
3769 | - ZORBA_INTEGER_OP(> ,unsigned char); |
3770 | - ZORBA_INTEGER_OP(>=,unsigned char); |
3771 | - ZORBA_INTEGER_OP(==,unsigned short); |
3772 | - ZORBA_INTEGER_OP(!=,unsigned short); |
3773 | - ZORBA_INTEGER_OP(< ,unsigned short); |
3774 | - ZORBA_INTEGER_OP(<=,unsigned short); |
3775 | - ZORBA_INTEGER_OP(> ,unsigned short); |
3776 | - ZORBA_INTEGER_OP(>=,unsigned short); |
3777 | - ZORBA_INTEGER_OP(==,unsigned int); |
3778 | - ZORBA_INTEGER_OP(!=,unsigned int); |
3779 | - ZORBA_INTEGER_OP(< ,unsigned int); |
3780 | - ZORBA_INTEGER_OP(<=,unsigned int); |
3781 | - ZORBA_INTEGER_OP(> ,unsigned int); |
3782 | - ZORBA_INTEGER_OP(>=,unsigned int); |
3783 | - ZORBA_INTEGER_OP(==,unsigned long); |
3784 | - ZORBA_INTEGER_OP(!=,unsigned long); |
3785 | - ZORBA_INTEGER_OP(< ,unsigned long); |
3786 | - ZORBA_INTEGER_OP(<=,unsigned long); |
3787 | - ZORBA_INTEGER_OP(> ,unsigned long); |
3788 | - ZORBA_INTEGER_OP(>=,unsigned long); |
3789 | - ZORBA_INTEGER_OP(==,unsigned long long); |
3790 | - ZORBA_INTEGER_OP(!=,unsigned long long); |
3791 | - ZORBA_INTEGER_OP(< ,unsigned long long); |
3792 | - ZORBA_INTEGER_OP(<=,unsigned long long); |
3793 | - ZORBA_INTEGER_OP(> ,unsigned long long); |
3794 | - ZORBA_INTEGER_OP(>=,unsigned long long); |
3795 | - ZORBA_INTEGER_OP(==,float); |
3796 | - ZORBA_INTEGER_OP(!=,float); |
3797 | - ZORBA_INTEGER_OP(< ,float); |
3798 | - ZORBA_INTEGER_OP(<=,float); |
3799 | - ZORBA_INTEGER_OP(> ,float); |
3800 | - ZORBA_INTEGER_OP(>=,float); |
3801 | - ZORBA_INTEGER_OP(==,double); |
3802 | - ZORBA_INTEGER_OP(!=,double); |
3803 | - ZORBA_INTEGER_OP(< ,double); |
3804 | - ZORBA_INTEGER_OP(<=,double); |
3805 | - ZORBA_INTEGER_OP(> ,double); |
3806 | - ZORBA_INTEGER_OP(>=,double); |
3807 | -#undef ZORBA_INTEGER_OP |
3808 | +#define ZORBA_REL_OP(OP) \ |
3809 | + template<class T,class U> friend \ |
3810 | + bool operator OP( IntegerImpl<T> const&, IntegerImpl<U> const& ); \ |
3811 | + \ |
3812 | + template<class T> friend \ |
3813 | + bool operator OP( IntegerImpl<T> const&, Decimal const& ); \ |
3814 | + \ |
3815 | + template<class T> friend \ |
3816 | + bool operator OP( Decimal const&, IntegerImpl<T> const& ) |
3817 | + |
3818 | + ZORBA_REL_OP(==); |
3819 | + ZORBA_REL_OP(!=); |
3820 | + ZORBA_REL_OP(< ); |
3821 | + ZORBA_REL_OP(<=); |
3822 | + ZORBA_REL_OP(> ); |
3823 | + ZORBA_REL_OP(>=); |
3824 | +#undef ZORBA_REL_OP |
3825 | + |
3826 | +#define ZORBA_REL_OP(OP,N) \ |
3827 | + template<class T> friend bool operator OP( IntegerImpl<T> const&, N ); \ |
3828 | + template<class T> friend bool operator OP( N, IntegerImpl<T> const& ) |
3829 | + |
3830 | + ZORBA_REL_OP(==,char); |
3831 | + ZORBA_REL_OP(!=,char); |
3832 | + ZORBA_REL_OP(< ,char); |
3833 | + ZORBA_REL_OP(<=,char); |
3834 | + ZORBA_REL_OP(> ,char); |
3835 | + ZORBA_REL_OP(>=,char); |
3836 | + ZORBA_REL_OP(==,signed char); |
3837 | + ZORBA_REL_OP(!=,signed char); |
3838 | + ZORBA_REL_OP(< ,signed char); |
3839 | + ZORBA_REL_OP(<=,signed char); |
3840 | + ZORBA_REL_OP(> ,signed char); |
3841 | + ZORBA_REL_OP(>=,signed char); |
3842 | + ZORBA_REL_OP(==,short); |
3843 | + ZORBA_REL_OP(!=,short); |
3844 | + ZORBA_REL_OP(< ,short); |
3845 | + ZORBA_REL_OP(<=,short); |
3846 | + ZORBA_REL_OP(> ,short); |
3847 | + ZORBA_REL_OP(>=,short); |
3848 | + ZORBA_REL_OP(==,int); |
3849 | + ZORBA_REL_OP(!=,int); |
3850 | + ZORBA_REL_OP(< ,int); |
3851 | + ZORBA_REL_OP(<=,int); |
3852 | + ZORBA_REL_OP(> ,int); |
3853 | + ZORBA_REL_OP(>=,int); |
3854 | + ZORBA_REL_OP(==,long); |
3855 | + ZORBA_REL_OP(!=,long); |
3856 | + ZORBA_REL_OP(< ,long); |
3857 | + ZORBA_REL_OP(<=,long); |
3858 | + ZORBA_REL_OP(> ,long); |
3859 | + ZORBA_REL_OP(>=,long); |
3860 | + ZORBA_REL_OP(==,long long); |
3861 | + ZORBA_REL_OP(!=,long long); |
3862 | + ZORBA_REL_OP(< ,long long); |
3863 | + ZORBA_REL_OP(<=,long long); |
3864 | + ZORBA_REL_OP(> ,long long); |
3865 | + ZORBA_REL_OP(>=,long long); |
3866 | + ZORBA_REL_OP(==,unsigned char); |
3867 | + ZORBA_REL_OP(!=,unsigned char); |
3868 | + ZORBA_REL_OP(< ,unsigned char); |
3869 | + ZORBA_REL_OP(<=,unsigned char); |
3870 | + ZORBA_REL_OP(> ,unsigned char); |
3871 | + ZORBA_REL_OP(>=,unsigned char); |
3872 | + ZORBA_REL_OP(==,unsigned short); |
3873 | + ZORBA_REL_OP(!=,unsigned short); |
3874 | + ZORBA_REL_OP(< ,unsigned short); |
3875 | + ZORBA_REL_OP(<=,unsigned short); |
3876 | + ZORBA_REL_OP(> ,unsigned short); |
3877 | + ZORBA_REL_OP(>=,unsigned short); |
3878 | + ZORBA_REL_OP(==,unsigned int); |
3879 | + ZORBA_REL_OP(!=,unsigned int); |
3880 | + ZORBA_REL_OP(< ,unsigned int); |
3881 | + ZORBA_REL_OP(<=,unsigned int); |
3882 | + ZORBA_REL_OP(> ,unsigned int); |
3883 | + ZORBA_REL_OP(>=,unsigned int); |
3884 | + ZORBA_REL_OP(==,unsigned long); |
3885 | + ZORBA_REL_OP(!=,unsigned long); |
3886 | + ZORBA_REL_OP(< ,unsigned long); |
3887 | + ZORBA_REL_OP(<=,unsigned long); |
3888 | + ZORBA_REL_OP(> ,unsigned long); |
3889 | + ZORBA_REL_OP(>=,unsigned long); |
3890 | + ZORBA_REL_OP(==,unsigned long long); |
3891 | + ZORBA_REL_OP(!=,unsigned long long); |
3892 | + ZORBA_REL_OP(< ,unsigned long long); |
3893 | + ZORBA_REL_OP(<=,unsigned long long); |
3894 | + ZORBA_REL_OP(> ,unsigned long long); |
3895 | + ZORBA_REL_OP(>=,unsigned long long); |
3896 | + ZORBA_REL_OP(==,float); |
3897 | + ZORBA_REL_OP(!=,float); |
3898 | + ZORBA_REL_OP(< ,float); |
3899 | + ZORBA_REL_OP(<=,float); |
3900 | + ZORBA_REL_OP(> ,float); |
3901 | + ZORBA_REL_OP(>=,float); |
3902 | + ZORBA_REL_OP(==,double); |
3903 | + ZORBA_REL_OP(!=,double); |
3904 | + ZORBA_REL_OP(< ,double); |
3905 | + ZORBA_REL_OP(<=,double); |
3906 | + ZORBA_REL_OP(> ,double); |
3907 | + ZORBA_REL_OP(>=,double); |
3908 | +#undef ZORBA_REL_OP |
3909 | |
3910 | ////////// math functions /////////////////////////////////////////////////// |
3911 | |
3912 | @@ -464,8 +540,6 @@ |
3913 | zstring toString() const; |
3914 | value_type& value(); |
3915 | value_type const& value() const; |
3916 | - static IntegerImpl const& one(); |
3917 | - static IntegerImpl const& zero(); |
3918 | |
3919 | ///////////////////////////////////////////////////////////////////////////// |
3920 | |
3921 | @@ -473,20 +547,18 @@ |
3922 | #ifdef ZORBA_WITH_BIG_INTEGER |
3923 | typedef long int_cast_type; |
3924 | #else |
3925 | - typedef IntType int_cast_type; |
3926 | + typedef value_type int_cast_type; |
3927 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3928 | |
3929 | value_type value_; |
3930 | |
3931 | -#ifdef ZORBA_WITH_BIG_INTEGER |
3932 | - IntegerImpl( value_type const &v ) : value_( v ) { } |
3933 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
3934 | - |
3935 | static value_type ftoi( double d ) { |
3936 | return value_type( d >= 0 ? floor( d ) : ceil( d ) ); |
3937 | } |
3938 | |
3939 | #ifdef ZORBA_WITH_BIG_INTEGER |
3940 | + IntegerImpl( value_type const &v ) : value_( v ) { } |
3941 | + |
3942 | static value_type ftoi( MAPM const &d ) { |
3943 | return d.sign() >= 0 ? d.floor() : d.ceil(); |
3944 | } |
3945 | @@ -499,7 +571,6 @@ |
3946 | static value_type make_value_type( T n ) { |
3947 | return value_type( static_cast<int_cast_type>( n ) ); |
3948 | } |
3949 | - |
3950 | #else /* ZORBA_WITH_BIG_INTEGER */ |
3951 | |
3952 | static value_type ftoi( value_type v ) { |
3953 | @@ -516,148 +587,149 @@ |
3954 | } |
3955 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
3956 | |
3957 | - void parse( char const *s ); |
3958 | + void parse( char const *s, bool throw_range_error ); |
3959 | |
3960 | friend class Decimal; |
3961 | - template<typename T> friend class FloatImpl; |
3962 | - |
3963 | -#ifndef ZORBA_WITH_BIG_INTEGER |
3964 | - template<typename T> friend class IntegerImpl; |
3965 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
3966 | - |
3967 | - friend xs_int to_xs_int( INTEGER_IMPL_LL const& ); |
3968 | - friend xs_long to_xs_long( INTEGER_IMPL_LL const& ); |
3969 | - friend xs_unsignedByte to_xs_unsignedByte( INTEGER_IMPL_LL const& ); |
3970 | - friend xs_unsignedShort to_xs_unsignedShort( INTEGER_IMPL_LL const& ); |
3971 | - friend xs_unsignedInt to_xs_unsignedInt( INTEGER_IMPL_LL const& ); |
3972 | - friend xs_unsignedLong to_xs_unsignedLong( INTEGER_IMPL_LL const& ); |
3973 | - |
3974 | - TEMPLATE_DECL(I) friend |
3975 | - void serialization::operator&( serialization::Archiver&, INTEGER_IMPL(I)& ); |
3976 | + template<typename F> friend class FloatImpl; |
3977 | + template<class T> friend class IntegerImpl; |
3978 | + |
3979 | + friend xs_int to_xs_int( Integer const& ); |
3980 | + friend xs_long to_xs_long( Integer const& ); |
3981 | + friend xs_unsignedByte to_xs_unsignedByte( Integer const& ); |
3982 | + friend xs_unsignedShort to_xs_unsignedShort( Integer const& ); |
3983 | + friend xs_unsignedInt to_xs_unsignedInt( Integer const& ); |
3984 | + friend xs_unsignedLong to_xs_unsignedLong( Integer const& ); |
3985 | + |
3986 | + template<class T> friend |
3987 | + void serialization::operator&( serialization::Archiver&, IntegerImpl<T>& ); |
3988 | }; |
3989 | |
3990 | -typedef INTEGER_IMPL_LL Integer; |
3991 | -typedef INTEGER_IMPL_ULL UInteger; |
3992 | +typedef IntegerImpl<integer_traits> Integer; |
3993 | +typedef IntegerImpl<negative_traits> NegativeInteger; |
3994 | +typedef IntegerImpl<nonNegative_traits> NonNegativeInteger; |
3995 | +typedef IntegerImpl<nonPositive_traits> NonPositiveInteger; |
3996 | +typedef IntegerImpl<positive_traits> PositiveInteger; |
3997 | |
3998 | ////////// constructors /////////////////////////////////////////////////////// |
3999 | |
4000 | -TEMPLATE_DECL(I) |
4001 | -inline INTEGER_IMPL(I)::IntegerImpl( char c ) : |
4002 | - value_( static_cast<long>( c ) ) |
4003 | -{ |
4004 | -} |
4005 | - |
4006 | -TEMPLATE_DECL(I) |
4007 | -inline INTEGER_IMPL(I)::IntegerImpl( signed char c ) : |
4008 | - value_( static_cast<long>( c ) ) |
4009 | -{ |
4010 | -} |
4011 | - |
4012 | -TEMPLATE_DECL(I) |
4013 | -inline INTEGER_IMPL(I)::IntegerImpl( short n ) : |
4014 | - value_( static_cast<long>( n ) ) |
4015 | -{ |
4016 | -} |
4017 | - |
4018 | -TEMPLATE_DECL(I) |
4019 | -inline INTEGER_IMPL(I)::IntegerImpl( int n ) : |
4020 | - value_( static_cast<long>( n ) ) |
4021 | -{ |
4022 | -} |
4023 | - |
4024 | -TEMPLATE_DECL(I) |
4025 | -inline INTEGER_IMPL(I)::IntegerImpl( long n ) : |
4026 | - value_( n ) |
4027 | +template<class T> |
4028 | +inline IntegerImpl<T>::IntegerImpl( char c ) : |
4029 | + value_( static_cast<long>( T::check_value( c, false ) ) ) |
4030 | +{ |
4031 | +} |
4032 | + |
4033 | +template<class T> |
4034 | +inline IntegerImpl<T>::IntegerImpl( signed char c ) : |
4035 | + value_( static_cast<long>( T::check_value( c, false ) ) ) |
4036 | +{ |
4037 | +} |
4038 | + |
4039 | +template<class T> |
4040 | +inline IntegerImpl<T>::IntegerImpl( short n ) : |
4041 | + value_( static_cast<long>( T::check_value( n, false ) ) ) |
4042 | +{ |
4043 | +} |
4044 | + |
4045 | +template<class T> |
4046 | +inline IntegerImpl<T>::IntegerImpl( int n ) : |
4047 | + value_( static_cast<long>( T::check_value( n, false ) ) ) |
4048 | +{ |
4049 | +} |
4050 | + |
4051 | +template<class T> |
4052 | +inline IntegerImpl<T>::IntegerImpl( long n ) : |
4053 | + value_( T::check_value( n, false ) ) |
4054 | { |
4055 | } |
4056 | |
4057 | #ifndef ZORBA_WITH_BIG_INTEGER |
4058 | -TEMPLATE_DECL(I) |
4059 | -inline INTEGER_IMPL(I)::IntegerImpl( long long n ) : |
4060 | - value_( n ) |
4061 | +template<class T> |
4062 | +inline IntegerImpl<T>::IntegerImpl( long long n ) : |
4063 | + value_( T::check_value( n, false ) ) |
4064 | { |
4065 | } |
4066 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4067 | |
4068 | -TEMPLATE_DECL(I) |
4069 | -inline INTEGER_IMPL(I)::IntegerImpl( unsigned char c ) : |
4070 | - value_( static_cast<long>( (unsigned long)c ) ) |
4071 | +template<class T> |
4072 | +inline IntegerImpl<T>::IntegerImpl( unsigned char c ) : |
4073 | + value_( static_cast<long>( (unsigned long)T::check_value( c, false ) ) ) |
4074 | { |
4075 | } |
4076 | |
4077 | -TEMPLATE_DECL(I) |
4078 | -inline INTEGER_IMPL(I)::IntegerImpl( unsigned short n ) : |
4079 | - value_( static_cast<long>( (unsigned long)n ) ) |
4080 | +template<class T> |
4081 | +inline IntegerImpl<T>::IntegerImpl( unsigned short n ) : |
4082 | + value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) ) |
4083 | { |
4084 | } |
4085 | |
4086 | #ifdef ZORBA_WITH_BIG_INTEGER |
4087 | #if ZORBA_SIZEOF_INT != ZORBA_SIZEOF_LONG |
4088 | -TEMPLATE_DECL(T) |
4089 | -inline INTEGER_IMPL(T)::IntegerImpl( unsigned int n ) : |
4090 | - value_( static_cast<long>( (unsigned long)n ) ) |
4091 | +template<class T> |
4092 | +inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : |
4093 | + value_( static_cast<long>( (unsigned long)T::check_value( n, false ) ) ) |
4094 | { |
4095 | } |
4096 | #endif /* ZORBA_SIZEOF_INT == ZORBA_SIZEOF_LONG */ |
4097 | #else /* ZORBA_WITH_BIG_INTEGER */ |
4098 | -TEMPLATE_DECL(I) |
4099 | -inline INTEGER_IMPL(I)::IntegerImpl( unsigned int n ) : |
4100 | - value_( static_cast<value_type>( n ) ) |
4101 | -{ |
4102 | -} |
4103 | - |
4104 | -TEMPLATE_DECL(I) |
4105 | -inline INTEGER_IMPL(I)::IntegerImpl( unsigned long n ) : |
4106 | - value_( static_cast<value_type>( n ) ) |
4107 | -{ |
4108 | -} |
4109 | - |
4110 | -TEMPLATE_DECL(I) |
4111 | -inline INTEGER_IMPL(I)::IntegerImpl( unsigned long long n ) : |
4112 | - value_( static_cast<value_type>( n ) ) |
4113 | -{ |
4114 | -} |
4115 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
4116 | - |
4117 | -TEMPLATE_DECL(I) |
4118 | -inline INTEGER_IMPL(I)::IntegerImpl( float n ) : |
4119 | -#ifdef ZORBA_WITH_BIG_INTEGER |
4120 | - value_( static_cast<double>( n ) ) |
4121 | -#else |
4122 | - value_( static_cast<value_type>( n ) ) |
4123 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
4124 | -{ |
4125 | -} |
4126 | - |
4127 | -TEMPLATE_DECL(I) |
4128 | -inline INTEGER_IMPL(I)::IntegerImpl( double n ) : |
4129 | -#ifdef ZORBA_WITH_BIG_INTEGER |
4130 | - value_( n ) |
4131 | -#else |
4132 | - value_( static_cast<value_type>( n ) ) |
4133 | -#endif /* ZORBA_WITH_BIG_INTEGER */ |
4134 | -{ |
4135 | -} |
4136 | - |
4137 | -TEMPLATE_DECL(I) |
4138 | -inline INTEGER_IMPL(I)::IntegerImpl( char const *s ) { |
4139 | - parse( s ); |
4140 | -} |
4141 | - |
4142 | -TEMPLATE_DECL(I) |
4143 | -TEMPLATE_DECL(J) |
4144 | -inline INTEGER_IMPL(I)::IntegerImpl( INTEGER_IMPL(J) const &i ) : |
4145 | - value_( i.value_ ) |
4146 | + |
4147 | +template<class T> |
4148 | +inline IntegerImpl<T>::IntegerImpl( unsigned int n ) : |
4149 | + value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4150 | +{ |
4151 | +} |
4152 | + |
4153 | +template<class T> |
4154 | +inline IntegerImpl<T>::IntegerImpl( unsigned long n ) : |
4155 | + value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4156 | +{ |
4157 | +} |
4158 | + |
4159 | +template<class T> |
4160 | +inline IntegerImpl<T>::IntegerImpl( unsigned long long n ) : |
4161 | + value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4162 | +{ |
4163 | +} |
4164 | +#endif /* ZORBA_WITH_BIG_INTEGER */ |
4165 | + |
4166 | +template<class T> |
4167 | +inline IntegerImpl<T>::IntegerImpl( float n ) : |
4168 | +#ifdef ZORBA_WITH_BIG_INTEGER |
4169 | + value_( static_cast<double>( T::check_value( n, false ) ) ) |
4170 | +#else |
4171 | + value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4172 | +#endif /* ZORBA_WITH_BIG_INTEGER */ |
4173 | +{ |
4174 | +} |
4175 | + |
4176 | +template<class T> |
4177 | +inline IntegerImpl<T>::IntegerImpl( double n ) : |
4178 | +#ifdef ZORBA_WITH_BIG_INTEGER |
4179 | + value_( T::check_value( n, false ) ) |
4180 | +#else |
4181 | + value_( static_cast<value_type>( T::check_value( n, false ) ) ) |
4182 | +#endif /* ZORBA_WITH_BIG_INTEGER */ |
4183 | +{ |
4184 | +} |
4185 | + |
4186 | +template<class T> |
4187 | +inline IntegerImpl<T>::IntegerImpl( char const *s ) { |
4188 | + parse( s, false ); |
4189 | +} |
4190 | + |
4191 | +template<class T> |
4192 | +template<class U> |
4193 | +inline IntegerImpl<T>::IntegerImpl( IntegerImpl<U> const &i ) : |
4194 | + value_( T::check_value( i.value_, false ) ) |
4195 | { |
4196 | } |
4197 | |
4198 | ////////// assignment operators /////////////////////////////////////////////// |
4199 | |
4200 | -#define ZORBA_ASSIGN_OP(T) \ |
4201 | - TEMPLATE_DECL(I) inline \ |
4202 | - INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( T n ) { \ |
4203 | - value_ = static_cast<int_cast_type>( n ); \ |
4204 | - return *this; \ |
4205 | +#define ZORBA_ASSIGN_OP(N) \ |
4206 | + template<class T> inline \ |
4207 | + IntegerImpl<T>& IntegerImpl<T>::operator=( N n ) { \ |
4208 | + value_ = static_cast<int_cast_type>( T::check_value( n, false ) ); \ |
4209 | + return *this; \ |
4210 | } |
4211 | |
4212 | ZORBA_ASSIGN_OP(char) |
4213 | @@ -677,25 +749,25 @@ |
4214 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4215 | #undef ZORBA_ASSIGN_OP |
4216 | |
4217 | -TEMPLATE_DECL(I) |
4218 | -inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( char const *s ) { |
4219 | - parse( s ); |
4220 | +template<class T> |
4221 | +inline IntegerImpl<T>& IntegerImpl<T>::operator=( char const *s ) { |
4222 | + parse( s, false ); |
4223 | return *this; |
4224 | } |
4225 | |
4226 | -TEMPLATE_DECL(I) TEMPLATE_DECL(J) |
4227 | -inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator=( INTEGER_IMPL(J) const &i ) { |
4228 | - value_ = i.value_; |
4229 | +template<class T> |
4230 | +template<class U> |
4231 | +inline IntegerImpl<T>& IntegerImpl<T>::operator=( IntegerImpl<U> const &i ) { |
4232 | + T::check_value( value_ = i.value_, false ); |
4233 | return *this; |
4234 | } |
4235 | |
4236 | ////////// arithmetic operators /////////////////////////////////////////////// |
4237 | |
4238 | -#define ZORBA_INTEGER_OP(OP) \ |
4239 | - TEMPLATE_DECL(I) inline \ |
4240 | - INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, \ |
4241 | - INTEGER_IMPL(I) const &j ) { \ |
4242 | - return INTEGER_IMPL(I)( i.value_ OP j.value_ ); \ |
4243 | +#define ZORBA_INTEGER_OP(OP) \ |
4244 | + template<class T,class U> inline \ |
4245 | + Integer operator OP( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { \ |
4246 | + return Integer( i.value_ OP j.value_ ); \ |
4247 | } |
4248 | |
4249 | ZORBA_INTEGER_OP(+) |
4250 | @@ -704,21 +776,20 @@ |
4251 | ZORBA_INTEGER_OP(%) |
4252 | #undef ZORBA_INTEGER_OP |
4253 | |
4254 | -TEMPLATE_DECL(I) inline |
4255 | -INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i, |
4256 | - INTEGER_IMPL(I) const &j ) { |
4257 | - return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / j.value_ ) ); |
4258 | +template<class T,class U> |
4259 | +inline Integer operator/( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { |
4260 | + return Integer( Integer::ftoi( i.value_ / j.value_ ) ); |
4261 | } |
4262 | |
4263 | -#define ZORBA_INTEGER_OP(OP,T) \ |
4264 | - TEMPLATE_DECL(I) inline \ |
4265 | - INTEGER_IMPL(I) operator OP( INTEGER_IMPL(I) const &i, T n ) { \ |
4266 | - return INTEGER_IMPL(I)( i.value_ OP INTEGER_IMPL(I)::make_value_type( n ) ); \ |
4267 | +#define ZORBA_INTEGER_OP(OP,N) \ |
4268 | + template<class T> inline \ |
4269 | + Integer operator OP( IntegerImpl<T> const &i, N n ) { \ |
4270 | + return Integer( i.value_ OP Integer::make_value_type( n ) ); \ |
4271 | } \ |
4272 | \ |
4273 | - TEMPLATE_DECL(I) inline \ |
4274 | - INTEGER_IMPL(I) operator OP( T n, INTEGER_IMPL(I) const &i ) { \ |
4275 | - return INTEGER_IMPL(I)( INTEGER_IMPL(I)::make_value_type( n ) OP i.value_ ); \ |
4276 | + template<class T> inline \ |
4277 | + Integer operator OP( N n, IntegerImpl<T> const &i ) { \ |
4278 | + return Integer( Integer::make_value_type( n ) OP i.value_ ); \ |
4279 | } |
4280 | |
4281 | ZORBA_INTEGER_OP(+,char) |
4282 | @@ -777,15 +848,15 @@ |
4283 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4284 | #undef ZORBA_INTEGER_OP |
4285 | |
4286 | -#define ZORBA_INTEGER_OP(T) \ |
4287 | - TEMPLATE_DECL(I) inline \ |
4288 | - INTEGER_IMPL(I) operator/( INTEGER_IMPL(I) const &i, T n ) { \ |
4289 | - return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( i.value_ / INTEGER_IMPL(I)::make_value_type( n ) ) ); \ |
4290 | - } \ |
4291 | - \ |
4292 | - TEMPLATE_DECL(I) inline \ |
4293 | - INTEGER_IMPL(I) operator/( T n, INTEGER_IMPL(I) const &i ) { \ |
4294 | - return INTEGER_IMPL(I)( INTEGER_IMPL(I)::ftoi( INTEGER_IMPL(I)::make_value_type( n ) / i.value_ ) ); \ |
4295 | +#define ZORBA_INTEGER_OP(N) \ |
4296 | + template<class T> inline \ |
4297 | + Integer operator/( IntegerImpl<T> const &i, N n ) { \ |
4298 | + return Integer( Integer::ftoi( i.value_ / Integer::make_value_type( n ) ) ); \ |
4299 | + } \ |
4300 | + \ |
4301 | + template<class T> inline \ |
4302 | + Integer operator/( N n, IntegerImpl<T> const &i ) { \ |
4303 | + return Integer( Integer::ftoi( Integer::make_value_type( n ) / i.value_ ) ); \ |
4304 | } |
4305 | |
4306 | ZORBA_INTEGER_OP(signed char) |
4307 | @@ -805,11 +876,11 @@ |
4308 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4309 | #undef ZORBA_INTEGER_OP |
4310 | |
4311 | -#define ZORBA_INTEGER_OP(OP) \ |
4312 | - TEMPLATE_DECL(I) inline \ |
4313 | - INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( IntegerImpl const &i ) { \ |
4314 | - value_ OP i.value_; \ |
4315 | - return *this; \ |
4316 | +#define ZORBA_INTEGER_OP(OP) \ |
4317 | + template<class T> inline \ |
4318 | + IntegerImpl<T>& IntegerImpl<T>::operator OP( IntegerImpl<T> const &i ) { \ |
4319 | + T::check_value( value_ OP i.value_, true ); \ |
4320 | + return *this; \ |
4321 | } |
4322 | |
4323 | ZORBA_INTEGER_OP(+=) |
4324 | @@ -818,17 +889,17 @@ |
4325 | ZORBA_INTEGER_OP(%=) |
4326 | #undef ZORBA_INTEGER_OP |
4327 | |
4328 | -TEMPLATE_DECL(I) |
4329 | -inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( IntegerImpl const &i ) { |
4330 | - value_ = ftoi( value_ / i.value_ ); |
4331 | +template<class T> |
4332 | +inline IntegerImpl<T>& IntegerImpl<T>::operator/=( IntegerImpl<T> const &i ) { |
4333 | + value_ = T::check_value( ftoi( value_ / i.value_ ), true ); |
4334 | return *this; |
4335 | } |
4336 | |
4337 | -#define ZORBA_INTEGER_OP(OP,T) \ |
4338 | - TEMPLATE_DECL(I) inline \ |
4339 | - INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator OP( T n ) { \ |
4340 | - value_ OP make_value_type( n ); \ |
4341 | - return *this; \ |
4342 | +#define ZORBA_INTEGER_OP(OP,N) \ |
4343 | + template<class T> inline \ |
4344 | + IntegerImpl<T>& IntegerImpl<T>::operator OP( N n ) { \ |
4345 | + T::check_value( value_ OP make_value_type( n ), true ); \ |
4346 | + return *this; \ |
4347 | } |
4348 | |
4349 | ZORBA_INTEGER_OP(+=,char) |
4350 | @@ -887,11 +958,11 @@ |
4351 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4352 | #undef ZORBA_INTEGER_OP |
4353 | |
4354 | -#define ZORBA_INTEGER_OP(T) \ |
4355 | - TEMPLATE_DECL(I) inline \ |
4356 | - INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator/=( T n ) { \ |
4357 | - value_ = ftoi( value_ / make_value_type( n ) ); \ |
4358 | - return *this; \ |
4359 | +#define ZORBA_INTEGER_OP(N) \ |
4360 | + template<class T> inline \ |
4361 | + IntegerImpl<T>& IntegerImpl<T>::operator/=( N n ) { \ |
4362 | + value_ = T::check_value( ftoi( value_ / make_value_type( n ) ), true ); \ |
4363 | + return *this; \ |
4364 | } |
4365 | |
4366 | ZORBA_INTEGER_OP(char) |
4367 | @@ -911,243 +982,247 @@ |
4368 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4369 | #undef ZORBA_INTEGER_OP |
4370 | |
4371 | -TEMPLATE_DECL(I) |
4372 | -inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator-() const { |
4373 | - return INTEGER_IMPL(I)( -value_ ); |
4374 | +template<class T> |
4375 | +inline Integer IntegerImpl<T>::operator-() const { |
4376 | + return Integer( -value_ ); |
4377 | } |
4378 | |
4379 | -TEMPLATE_DECL(I) |
4380 | -inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator++() { |
4381 | - ++value_; |
4382 | +template<class T> |
4383 | +inline IntegerImpl<T>& IntegerImpl<T>::operator++() { |
4384 | + T::check_value( ++value_, true ); |
4385 | return *this; |
4386 | } |
4387 | |
4388 | -TEMPLATE_DECL(I) |
4389 | -inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator++(int) { |
4390 | - INTEGER_IMPL(I) const result( *this ); |
4391 | - ++value_; |
4392 | +template<class T> |
4393 | +inline IntegerImpl<T> IntegerImpl<T>::operator++(int) { |
4394 | + IntegerImpl<T> const result( *this ); |
4395 | + T::check_value( ++value_, true ); |
4396 | return result; |
4397 | } |
4398 | |
4399 | -TEMPLATE_DECL(I) |
4400 | -inline INTEGER_IMPL(I)& INTEGER_IMPL(I)::operator--() { |
4401 | - --value_; |
4402 | +template<class T> |
4403 | +inline IntegerImpl<T>& IntegerImpl<T>::operator--() { |
4404 | + T::check_value( --value_, true ); |
4405 | return *this; |
4406 | } |
4407 | |
4408 | -TEMPLATE_DECL(I) |
4409 | -inline INTEGER_IMPL(I) INTEGER_IMPL(I)::operator--(int) { |
4410 | - INTEGER_IMPL(I) const result( *this ); |
4411 | - --value_; |
4412 | +template<class T> |
4413 | +inline IntegerImpl<T> IntegerImpl<T>::operator--(int) { |
4414 | + IntegerImpl<T> const result( *this ); |
4415 | + T::check_value( --value_, true ); |
4416 | return result; |
4417 | } |
4418 | |
4419 | ////////// relational operators /////////////////////////////////////////////// |
4420 | |
4421 | -#define ZORBA_INTEGER_OP(OP) \ |
4422 | - TEMPLATE_DECL(I) inline \ |
4423 | - bool operator OP( INTEGER_IMPL(I) const &i, INTEGER_IMPL(I) const &j ) { \ |
4424 | - return i.value_ OP j.value_; \ |
4425 | +#define ZORBA_REL_OP(OP) \ |
4426 | + template<class T,class U> inline \ |
4427 | + bool operator OP( IntegerImpl<T> const &i, IntegerImpl<U> const &j ) { \ |
4428 | + return i.value_ OP j.value_; \ |
4429 | } |
4430 | |
4431 | -ZORBA_INTEGER_OP(==) |
4432 | -ZORBA_INTEGER_OP(!=) |
4433 | -ZORBA_INTEGER_OP(< ) |
4434 | -ZORBA_INTEGER_OP(<=) |
4435 | -ZORBA_INTEGER_OP(> ) |
4436 | -ZORBA_INTEGER_OP(>=) |
4437 | -#undef ZORBA_INTEGER_OP |
4438 | +ZORBA_REL_OP(==) |
4439 | +ZORBA_REL_OP(!=) |
4440 | +ZORBA_REL_OP(< ) |
4441 | +ZORBA_REL_OP(<=) |
4442 | +ZORBA_REL_OP(> ) |
4443 | +ZORBA_REL_OP(>=) |
4444 | +#undef ZORBA_REL_OP |
4445 | |
4446 | -#define ZORBA_INTEGER_OP(OP,T) \ |
4447 | - TEMPLATE_DECL(I) inline \ |
4448 | - bool operator OP( INTEGER_IMPL(I) const &i, T n ) { \ |
4449 | - return i.value_ OP INTEGER_IMPL(I)::make_value_type( n ); \ |
4450 | +#define ZORBA_REL_OP(OP,N) \ |
4451 | + template<class T> inline \ |
4452 | + bool operator OP( IntegerImpl<T> const &i, N n ) { \ |
4453 | + return i.value_ OP IntegerImpl<T>::make_value_type( n ); \ |
4454 | } \ |
4455 | \ |
4456 | - TEMPLATE_DECL(I) inline \ |
4457 | - bool operator OP( T n, INTEGER_IMPL(I) const &i ) { \ |
4458 | - return INTEGER_IMPL(I)::make_value_type( n ) OP i.value_; \ |
4459 | + template<class T> inline \ |
4460 | + bool operator OP( N n, IntegerImpl<T> const &i ) { \ |
4461 | + return IntegerImpl<T>::make_value_type( n ) OP i.value_; \ |
4462 | } |
4463 | |
4464 | -ZORBA_INTEGER_OP(==,char) |
4465 | -ZORBA_INTEGER_OP(!=,char) |
4466 | -ZORBA_INTEGER_OP(< ,char) |
4467 | -ZORBA_INTEGER_OP(<=,char) |
4468 | -ZORBA_INTEGER_OP(> ,char) |
4469 | -ZORBA_INTEGER_OP(>=,char) |
4470 | -ZORBA_INTEGER_OP(==,signed char) |
4471 | -ZORBA_INTEGER_OP(!=,signed char) |
4472 | -ZORBA_INTEGER_OP(< ,signed char) |
4473 | -ZORBA_INTEGER_OP(<=,signed char) |
4474 | -ZORBA_INTEGER_OP(> ,signed char) |
4475 | -ZORBA_INTEGER_OP(>=,signed char) |
4476 | -ZORBA_INTEGER_OP(==,short) |
4477 | -ZORBA_INTEGER_OP(!=,short) |
4478 | -ZORBA_INTEGER_OP(< ,short) |
4479 | -ZORBA_INTEGER_OP(<=,short) |
4480 | -ZORBA_INTEGER_OP(> ,short) |
4481 | -ZORBA_INTEGER_OP(>=,short) |
4482 | -ZORBA_INTEGER_OP(==,int) |
4483 | -ZORBA_INTEGER_OP(!=,int) |
4484 | -ZORBA_INTEGER_OP(< ,int) |
4485 | -ZORBA_INTEGER_OP(<=,int) |
4486 | -ZORBA_INTEGER_OP(> ,int) |
4487 | -ZORBA_INTEGER_OP(>=,int) |
4488 | -ZORBA_INTEGER_OP(==,long) |
4489 | -ZORBA_INTEGER_OP(!=,long) |
4490 | -ZORBA_INTEGER_OP(< ,long) |
4491 | -ZORBA_INTEGER_OP(<=,long) |
4492 | -ZORBA_INTEGER_OP(> ,long) |
4493 | -ZORBA_INTEGER_OP(>=,long) |
4494 | -ZORBA_INTEGER_OP(==,unsigned char) |
4495 | -ZORBA_INTEGER_OP(!=,unsigned char) |
4496 | -ZORBA_INTEGER_OP(< ,unsigned char) |
4497 | -ZORBA_INTEGER_OP(<=,unsigned char) |
4498 | -ZORBA_INTEGER_OP(> ,unsigned char) |
4499 | -ZORBA_INTEGER_OP(>=,unsigned char) |
4500 | -ZORBA_INTEGER_OP(==,unsigned short) |
4501 | -ZORBA_INTEGER_OP(!=,unsigned short) |
4502 | -ZORBA_INTEGER_OP(< ,unsigned short) |
4503 | -ZORBA_INTEGER_OP(<=,unsigned short) |
4504 | -ZORBA_INTEGER_OP(> ,unsigned short) |
4505 | -ZORBA_INTEGER_OP(>=,unsigned short) |
4506 | -ZORBA_INTEGER_OP(==,unsigned int) |
4507 | -ZORBA_INTEGER_OP(!=,unsigned int) |
4508 | -ZORBA_INTEGER_OP(< ,unsigned int) |
4509 | -ZORBA_INTEGER_OP(<=,unsigned int) |
4510 | -ZORBA_INTEGER_OP(> ,unsigned int) |
4511 | -ZORBA_INTEGER_OP(>=,unsigned int) |
4512 | -ZORBA_INTEGER_OP(==,float) |
4513 | -ZORBA_INTEGER_OP(!=,float) |
4514 | -ZORBA_INTEGER_OP(< ,float) |
4515 | -ZORBA_INTEGER_OP(<=,float) |
4516 | -ZORBA_INTEGER_OP(> ,float) |
4517 | -ZORBA_INTEGER_OP(>=,float) |
4518 | -ZORBA_INTEGER_OP(==,double) |
4519 | -ZORBA_INTEGER_OP(!=,double) |
4520 | -ZORBA_INTEGER_OP(< ,double) |
4521 | -ZORBA_INTEGER_OP(<=,double) |
4522 | -ZORBA_INTEGER_OP(> ,double) |
4523 | -ZORBA_INTEGER_OP(>=,double) |
4524 | +ZORBA_REL_OP(==,char) |
4525 | +ZORBA_REL_OP(!=,char) |
4526 | +ZORBA_REL_OP(< ,char) |
4527 | +ZORBA_REL_OP(<=,char) |
4528 | +ZORBA_REL_OP(> ,char) |
4529 | +ZORBA_REL_OP(>=,char) |
4530 | +ZORBA_REL_OP(==,signed char) |
4531 | +ZORBA_REL_OP(!=,signed char) |
4532 | +ZORBA_REL_OP(< ,signed char) |
4533 | +ZORBA_REL_OP(<=,signed char) |
4534 | +ZORBA_REL_OP(> ,signed char) |
4535 | +ZORBA_REL_OP(>=,signed char) |
4536 | +ZORBA_REL_OP(==,short) |
4537 | +ZORBA_REL_OP(!=,short) |
4538 | +ZORBA_REL_OP(< ,short) |
4539 | +ZORBA_REL_OP(<=,short) |
4540 | +ZORBA_REL_OP(> ,short) |
4541 | +ZORBA_REL_OP(>=,short) |
4542 | +ZORBA_REL_OP(==,int) |
4543 | +ZORBA_REL_OP(!=,int) |
4544 | +ZORBA_REL_OP(< ,int) |
4545 | +ZORBA_REL_OP(<=,int) |
4546 | +ZORBA_REL_OP(> ,int) |
4547 | +ZORBA_REL_OP(>=,int) |
4548 | +ZORBA_REL_OP(==,long) |
4549 | +ZORBA_REL_OP(!=,long) |
4550 | +ZORBA_REL_OP(< ,long) |
4551 | +ZORBA_REL_OP(<=,long) |
4552 | +ZORBA_REL_OP(> ,long) |
4553 | +ZORBA_REL_OP(>=,long) |
4554 | +ZORBA_REL_OP(==,unsigned char) |
4555 | +ZORBA_REL_OP(!=,unsigned char) |
4556 | +ZORBA_REL_OP(< ,unsigned char) |
4557 | +ZORBA_REL_OP(<=,unsigned char) |
4558 | +ZORBA_REL_OP(> ,unsigned char) |
4559 | +ZORBA_REL_OP(>=,unsigned char) |
4560 | +ZORBA_REL_OP(==,unsigned short) |
4561 | +ZORBA_REL_OP(!=,unsigned short) |
4562 | +ZORBA_REL_OP(< ,unsigned short) |
4563 | +ZORBA_REL_OP(<=,unsigned short) |
4564 | +ZORBA_REL_OP(> ,unsigned short) |
4565 | +ZORBA_REL_OP(>=,unsigned short) |
4566 | +ZORBA_REL_OP(==,unsigned int) |
4567 | +ZORBA_REL_OP(!=,unsigned int) |
4568 | +ZORBA_REL_OP(< ,unsigned int) |
4569 | +ZORBA_REL_OP(<=,unsigned int) |
4570 | +ZORBA_REL_OP(> ,unsigned int) |
4571 | +ZORBA_REL_OP(>=,unsigned int) |
4572 | +ZORBA_REL_OP(==,float) |
4573 | +ZORBA_REL_OP(!=,float) |
4574 | +ZORBA_REL_OP(< ,float) |
4575 | +ZORBA_REL_OP(<=,float) |
4576 | +ZORBA_REL_OP(> ,float) |
4577 | +ZORBA_REL_OP(>=,float) |
4578 | +ZORBA_REL_OP(==,double) |
4579 | +ZORBA_REL_OP(!=,double) |
4580 | +ZORBA_REL_OP(< ,double) |
4581 | +ZORBA_REL_OP(<=,double) |
4582 | +ZORBA_REL_OP(> ,double) |
4583 | +ZORBA_REL_OP(>=,double) |
4584 | #ifndef ZORBA_WITH_BIG_INTEGER |
4585 | -ZORBA_INTEGER_OP(==,long long) |
4586 | -ZORBA_INTEGER_OP(!=,long long) |
4587 | -ZORBA_INTEGER_OP(< ,long long) |
4588 | -ZORBA_INTEGER_OP(<=,long long) |
4589 | -ZORBA_INTEGER_OP(> ,long long) |
4590 | -ZORBA_INTEGER_OP(>=,long long) |
4591 | -ZORBA_INTEGER_OP(==,unsigned long) |
4592 | -ZORBA_INTEGER_OP(!=,unsigned long) |
4593 | -ZORBA_INTEGER_OP(< ,unsigned long) |
4594 | -ZORBA_INTEGER_OP(<=,unsigned long) |
4595 | -ZORBA_INTEGER_OP(> ,unsigned long) |
4596 | -ZORBA_INTEGER_OP(>=,unsigned long) |
4597 | -ZORBA_INTEGER_OP(==,unsigned long long) |
4598 | -ZORBA_INTEGER_OP(!=,unsigned long long) |
4599 | -ZORBA_INTEGER_OP(< ,unsigned long long) |
4600 | -ZORBA_INTEGER_OP(<=,unsigned long long) |
4601 | -ZORBA_INTEGER_OP(> ,unsigned long long) |
4602 | -ZORBA_INTEGER_OP(>=,unsigned long long) |
4603 | +ZORBA_REL_OP(==,long long) |
4604 | +ZORBA_REL_OP(!=,long long) |
4605 | +ZORBA_REL_OP(< ,long long) |
4606 | +ZORBA_REL_OP(<=,long long) |
4607 | +ZORBA_REL_OP(> ,long long) |
4608 | +ZORBA_REL_OP(>=,long long) |
4609 | +ZORBA_REL_OP(==,unsigned long) |
4610 | +ZORBA_REL_OP(!=,unsigned long) |
4611 | +ZORBA_REL_OP(< ,unsigned long) |
4612 | +ZORBA_REL_OP(<=,unsigned long) |
4613 | +ZORBA_REL_OP(> ,unsigned long) |
4614 | +ZORBA_REL_OP(>=,unsigned long) |
4615 | +ZORBA_REL_OP(==,unsigned long long) |
4616 | +ZORBA_REL_OP(!=,unsigned long long) |
4617 | +ZORBA_REL_OP(< ,unsigned long long) |
4618 | +ZORBA_REL_OP(<=,unsigned long long) |
4619 | +ZORBA_REL_OP(> ,unsigned long long) |
4620 | +ZORBA_REL_OP(>=,unsigned long long) |
4621 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4622 | -#undef ZORBA_INTEGER_OP |
4623 | +#undef ZORBA_REL_OP |
4624 | |
4625 | ////////// miscellaneous ////////////////////////////////////////////////////// |
4626 | |
4627 | #ifdef ZORBA_WITH_BIG_INTEGER |
4628 | |
4629 | -inline int IntegerImpl::compare( IntegerImpl const &i ) const { |
4630 | +template<class T> |
4631 | +inline int IntegerImpl<T>::compare( IntegerImpl<T> const &i ) const { |
4632 | return value_.compare( i.value_ ); |
4633 | } |
4634 | |
4635 | -inline bool IntegerImpl::is_xs_int() const { |
4636 | +template<class T> |
4637 | +inline bool IntegerImpl<T>::is_xs_int() const { |
4638 | return value_ >= MAPM::getMinInt32() && value_ <= MAPM::getMaxInt32(); |
4639 | } |
4640 | |
4641 | -inline bool IntegerImpl::is_xs_long() const { |
4642 | +template<class T> |
4643 | +inline bool IntegerImpl<T>::is_xs_long() const { |
4644 | return value_ >= MAPM::getMinInt64() && value_ <= MAPM::getMaxInt64(); |
4645 | } |
4646 | |
4647 | -inline int IntegerImpl::sign() const { |
4648 | +template<class T> |
4649 | +inline int IntegerImpl<T>::sign() const { |
4650 | return value_.sign(); |
4651 | } |
4652 | |
4653 | #else /* ZORBA_WITH_BIG_INTEGER */ |
4654 | |
4655 | -template<typename I> |
4656 | -inline int IntegerImpl<I>::compare( IntegerImpl const &i ) const { |
4657 | +template<class T> |
4658 | +inline int IntegerImpl<T>::compare( IntegerImpl<T> const &i ) const { |
4659 | return value_ < i.value_ ? -1 : value_ > i.value_ ? 1 : 0; |
4660 | } |
4661 | |
4662 | -template<typename I> |
4663 | -inline uint32_t IntegerImpl<I>::hash() const { |
4664 | +template<class T> |
4665 | +inline uint32_t IntegerImpl<T>::hash() const { |
4666 | return static_cast<uint32_t>( value_ ); |
4667 | } |
4668 | |
4669 | -template<typename I> |
4670 | -inline bool IntegerImpl<I>::is_cxx_long() const { |
4671 | +template<class T> |
4672 | +inline bool IntegerImpl<T>::is_cxx_long() const { |
4673 | return ZORBA_IN_RANGE( value_, long ); |
4674 | } |
4675 | |
4676 | -template<typename I> |
4677 | -inline bool IntegerImpl<I>::is_xs_byte() const { |
4678 | +template<class T> |
4679 | +inline bool IntegerImpl<T>::is_xs_byte() const { |
4680 | return ZORBA_IN_RANGE( value_, xs_byte ); |
4681 | } |
4682 | |
4683 | -template<typename I> |
4684 | -inline bool IntegerImpl<I>::is_xs_int() const { |
4685 | +template<class T> |
4686 | +inline bool IntegerImpl<T>::is_xs_int() const { |
4687 | return ZORBA_IN_RANGE( value_, xs_int ); |
4688 | } |
4689 | |
4690 | -template<typename I> |
4691 | -inline bool IntegerImpl<I>::is_xs_long() const { |
4692 | +template<class T> |
4693 | +inline bool IntegerImpl<T>::is_xs_long() const { |
4694 | return ZORBA_IN_RANGE( value_, xs_long ); |
4695 | } |
4696 | |
4697 | -template<typename I> |
4698 | -inline bool IntegerImpl<I>::is_xs_short() const { |
4699 | +template<class T> |
4700 | +inline bool IntegerImpl<T>::is_xs_short() const { |
4701 | return ZORBA_IN_RANGE( value_, xs_short ); |
4702 | } |
4703 | |
4704 | -template<typename I> |
4705 | -inline bool IntegerImpl<I>::is_xs_unsignedByte() const { |
4706 | +template<class T> |
4707 | +inline bool IntegerImpl<T>::is_xs_unsignedByte() const { |
4708 | return ZORBA_IN_RANGE( value_, xs_unsignedByte ); |
4709 | } |
4710 | |
4711 | -template<typename I> |
4712 | -inline bool IntegerImpl<I>::is_xs_unsignedInt() const { |
4713 | +template<class T> |
4714 | +inline bool IntegerImpl<T>::is_xs_unsignedInt() const { |
4715 | return ZORBA_IN_RANGE( value_, xs_unsignedInt ); |
4716 | } |
4717 | |
4718 | -template<typename I> |
4719 | -inline bool IntegerImpl<I>::is_xs_unsignedLong() const { |
4720 | +template<class T> |
4721 | +inline bool IntegerImpl<T>::is_xs_unsignedLong() const { |
4722 | return ZORBA_IN_RANGE( value_, xs_unsignedLong ); |
4723 | } |
4724 | |
4725 | -template<typename I> |
4726 | -inline bool IntegerImpl<I>::is_xs_unsignedShort() const { |
4727 | +template<class T> |
4728 | +inline bool IntegerImpl<T>::is_xs_unsignedShort() const { |
4729 | return ZORBA_IN_RANGE( value_, xs_unsignedShort ); |
4730 | } |
4731 | |
4732 | -template<typename I> |
4733 | -inline int IntegerImpl<I>::sign() const { |
4734 | +template<class T> |
4735 | +inline int IntegerImpl<T>::sign() const { |
4736 | return ztd::lt0( value_ ) ? -1 : value_ > 0 ? 1 : 0; |
4737 | } |
4738 | |
4739 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4740 | |
4741 | -TEMPLATE_DECL(I) inline |
4742 | -TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type& INTEGER_IMPL(I)::value() { |
4743 | - return value_; |
4744 | -} |
4745 | - |
4746 | -TEMPLATE_DECL(I) inline |
4747 | -TEMPLATE_TYPENAME INTEGER_IMPL(I)::value_type const& |
4748 | -INTEGER_IMPL(I)::value() const { |
4749 | - return value_; |
4750 | -} |
4751 | - |
4752 | -TEMPLATE_DECL(I) |
4753 | -inline std::ostream& operator<<( std::ostream &os, INTEGER_IMPL(I) const &i ) { |
4754 | +template<class T> |
4755 | +inline typename IntegerImpl<T>::value_type& IntegerImpl<T>::value() { |
4756 | + return value_; |
4757 | +} |
4758 | + |
4759 | +template<class T> |
4760 | +inline typename IntegerImpl<T>::value_type const& |
4761 | +IntegerImpl<T>::value() const { |
4762 | + return value_; |
4763 | +} |
4764 | + |
4765 | +template<class T> |
4766 | +inline std::ostream& operator<<( std::ostream &os, IntegerImpl<T> const &i ) { |
4767 | return os << i.toString(); |
4768 | } |
4769 | |
4770 | @@ -1155,11 +1230,6 @@ |
4771 | |
4772 | } // namespace zorba |
4773 | |
4774 | -#undef TEMPLATE_DECL |
4775 | -#undef INTEGER_IMPL |
4776 | -#undef INTEGER_IMPL_LL |
4777 | -#undef INTEGER_IMPL_ULL |
4778 | - |
4779 | #endif // ZORBA_INTEGER_H |
4780 | /* |
4781 | * Local variables: |
4782 | |
4783 | === modified file 'src/zorbatypes/numconversions.cpp' |
4784 | --- src/zorbatypes/numconversions.cpp 2013-03-22 19:06:44 +0000 |
4785 | +++ src/zorbatypes/numconversions.cpp 2013-05-08 15:05:31 +0000 |
4786 | @@ -15,11 +15,18 @@ |
4787 | */ |
4788 | #include "stdafx.h" |
4789 | |
4790 | +// standard |
4791 | #include <stdexcept> |
4792 | |
4793 | +// Zorba |
4794 | #include "common/common.h" |
4795 | #include "util/string_util.h" |
4796 | -#include "zorbatypes/numconversions.h" |
4797 | + |
4798 | +// local |
4799 | +#include "decimal.h" |
4800 | +#include "floatimpl.h" |
4801 | +#include "integer.h" |
4802 | +#include "numconversions.h" |
4803 | |
4804 | namespace zorba { |
4805 | |
4806 | |
4807 | === modified file 'src/zorbatypes/numconversions.h' |
4808 | --- src/zorbatypes/numconversions.h 2013-03-22 19:06:44 +0000 |
4809 | +++ src/zorbatypes/numconversions.h 2013-05-08 15:05:31 +0000 |
4810 | @@ -64,6 +64,7 @@ |
4811 | */ |
4812 | xs_long to_xs_long( xs_integer const &i ); |
4813 | |
4814 | +#if 0 |
4815 | #ifndef ZORBA_WITH_BIG_INTEGER |
4816 | /** |
4817 | * Converts an \c xs:nonNegativeInteger value to an \c xs:long. |
4818 | @@ -75,6 +76,7 @@ |
4819 | */ |
4820 | xs_long to_xs_long( xs_nonNegativeInteger const &i ); |
4821 | #endif /* ZORBA_WITH_BIG_INTEGER */ |
4822 | +#endif |
4823 | |
4824 | /** |
4825 | * Converts an \c xs:integer value to an \c xs:unsignedByte. |
4826 | |
4827 | === added file 'src/zorbatypes/numeric_types.cpp' |
4828 | --- src/zorbatypes/numeric_types.cpp 1970-01-01 00:00:00 +0000 |
4829 | +++ src/zorbatypes/numeric_types.cpp 2013-05-08 15:05:31 +0000 |
4830 | @@ -0,0 +1,82 @@ |
4831 | +/* |
4832 | + * Copyright 2006-2008 The FLWOR Foundation. |
4833 | + * |
4834 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
4835 | + * you may not use this file except in compliance with the License. |
4836 | + * You may obtain a copy of the License at |
4837 | + * |
4838 | + * http://www.apache.org/licenses/LICENSE-2.0 |
4839 | + * |
4840 | + * Unless required by applicable law or agreed to in writing, software |
4841 | + * distributed under the License is distributed on an "AS IS" BASIS, |
4842 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
4843 | + * See the License for the specific language governing permissions and |
4844 | + * limitations under the License. |
4845 | + */ |
4846 | + |
4847 | +#include "stdafx.h" |
4848 | + |
4849 | +// local |
4850 | +#include "decimal.h" |
4851 | +#include "floatimpl.h" |
4852 | +#include "integer.h" |
4853 | + |
4854 | +using namespace std; |
4855 | + |
4856 | +namespace zorba { |
4857 | + |
4858 | +/////////////////////////////////////////////////////////////////////////////// |
4859 | + |
4860 | +template<class NumericType> |
4861 | +NumericType const& numeric_consts<NumericType>::zero() { |
4862 | + static NumericType const n(0); |
4863 | + return n; |
4864 | +} |
4865 | + |
4866 | +template<class NumericType> |
4867 | +NumericType const& numeric_consts<NumericType>::one() { |
4868 | + static NumericType const n(1); |
4869 | + return n; |
4870 | +} |
4871 | + |
4872 | +template<class NumericType> |
4873 | +NumericType const& numeric_consts<NumericType>::neg_one() { |
4874 | + static NumericType const n(-1); |
4875 | + return n; |
4876 | +} |
4877 | + |
4878 | +// instantiate non-special cases |
4879 | +template class numeric_consts<Decimal>; |
4880 | +template class numeric_consts<Double>; |
4881 | +template class numeric_consts<Float>; |
4882 | +template class numeric_consts<Integer>; |
4883 | + |
4884 | +NonNegativeInteger const& numeric_consts<NonNegativeInteger>::zero() { |
4885 | + static NonNegativeInteger const n(0); |
4886 | + return n; |
4887 | +} |
4888 | + |
4889 | +NonNegativeInteger const& numeric_consts<NonNegativeInteger>::one() { |
4890 | + static NonNegativeInteger const n(1); |
4891 | + return n; |
4892 | +} |
4893 | + |
4894 | +NonPositiveInteger const& numeric_consts<NonPositiveInteger>::zero() { |
4895 | + static NonPositiveInteger const n(0); |
4896 | + return n; |
4897 | +} |
4898 | + |
4899 | +NonPositiveInteger const& numeric_consts<NonPositiveInteger>::neg_one() { |
4900 | + static NonPositiveInteger const n(-1); |
4901 | + return n; |
4902 | +} |
4903 | + |
4904 | +PositiveInteger const& numeric_consts<PositiveInteger>::one() { |
4905 | + static PositiveInteger const n(1); |
4906 | + return n; |
4907 | +} |
4908 | + |
4909 | +/////////////////////////////////////////////////////////////////////////////// |
4910 | + |
4911 | +} // namespace zorba |
4912 | +/* vim:set et sw=2 ts=2: */ |
4913 | |
4914 | === added file 'src/zorbatypes/numeric_types.h' |
4915 | --- src/zorbatypes/numeric_types.h 1970-01-01 00:00:00 +0000 |
4916 | +++ src/zorbatypes/numeric_types.h 2013-05-08 15:05:31 +0000 |
4917 | @@ -0,0 +1,106 @@ |
4918 | +/* |
4919 | + * Copyright 2006-2008 The FLWOR Foundation. |
4920 | + * |
4921 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
4922 | + * you may not use this file except in compliance with the License. |
4923 | + * You may obtain a copy of the License at |
4924 | + * |
4925 | + * http://www.apache.org/licenses/LICENSE-2.0 |
4926 | + * |
4927 | + * Unless required by applicable law or agreed to in writing, software |
4928 | + * distributed under the License is distributed on an "AS IS" BASIS, |
4929 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
4930 | + * See the License for the specific language governing permissions and |
4931 | + * limitations under the License. |
4932 | + */ |
4933 | + |
4934 | +#pragma once |
4935 | +#ifndef ZORBA_NUMERIC_CONSTS_H |
4936 | +#define ZORBA_NUMERIC_CONSTS_H |
4937 | + |
4938 | +namespace zorba { |
4939 | + |
4940 | +/////////////////////////////////////////////////////////////////////////////// |
4941 | + |
4942 | +class integer_traits; |
4943 | +class negative_traits; |
4944 | +class nonNegative_traits; |
4945 | +class nonPositive_traits; |
4946 | +class positive_traits; |
4947 | + |
4948 | +template<class T> class IntegerImpl; |
4949 | +typedef IntegerImpl<integer_traits> Integer; |
4950 | +typedef IntegerImpl<negative_traits> NegativeInteger; |
4951 | +typedef IntegerImpl<nonNegative_traits> NonNegativeInteger; |
4952 | +typedef IntegerImpl<nonPositive_traits> NonPositiveInteger; |
4953 | +typedef IntegerImpl<positive_traits> PositiveInteger; |
4954 | + |
4955 | +class Decimal; |
4956 | + |
4957 | +template<typename F> class FloatImpl; |
4958 | +typedef FloatImpl<float> Float; |
4959 | +typedef FloatImpl<double> Double; |
4960 | + |
4961 | +/** |
4962 | + * This contains references to singleton objects having constant values for the |
4963 | + * often-used numeric constants -1, 0, and +1. |
4964 | + * |
4965 | + * @tparam NumericType One of Integer, NegativeInteger, NonNegativeInteger, |
4966 | + * NonPositiveInteger, PositiveInteger, Decimal, Float, or Double. |
4967 | + */ |
4968 | +template<class NumericType> |
4969 | +struct numeric_consts { |
4970 | + static NumericType const& neg_one(); |
4971 | + static NumericType const& zero(); |
4972 | + static NumericType const& one(); |
4973 | +}; |
4974 | + |
4975 | +/** |
4976 | + * Specialization for NegativeInteger that has only a reference to a singleton |
4977 | + * object having the constant value -1. |
4978 | + */ |
4979 | +template<> |
4980 | +struct numeric_consts<NegativeInteger> { |
4981 | + static NegativeInteger const& neg_one(); |
4982 | +}; |
4983 | + |
4984 | +/** |
4985 | + * Specialization for NonNegativeInteger that has only references to the |
4986 | + * singleton objects having the constant values 0 and 1. |
4987 | + */ |
4988 | +template<> |
4989 | +struct numeric_consts<NonNegativeInteger> { |
4990 | + static NonNegativeInteger const& zero(); |
4991 | + static NonNegativeInteger const& one(); |
4992 | +}; |
4993 | + |
4994 | +/** |
4995 | + * Specialization for NonPositiveInteger that has only references to the |
4996 | + * singleton objects having the constant values -1 and 0. |
4997 | + */ |
4998 | +template<> |
4999 | +struct numeric_consts<NonPositiveInteger> { |
5000 | + static NonPositiveInteger const& neg_one(); |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ bug-1090089- 2013-04- 30T14-52- 16.682Z/ log.html
Log at: http://