1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ZORBA_STORE_ATOMIC_ITEMS_H 18 #define ZORBA_STORE_ATOMIC_ITEMS_H 19 20 #include <zorba/config.h> 21 #include <iostream> 22 #include <vector> 23 #include <cstring> 24 25 #include <zorba/streams.h> 26 #ifndef ZORBA_NO_FULL_TEXT 27 #include <zorba/tokenizer.h> 28 #endif /* ZORBA_NO_FULL_TEXT */ 29 30 #include "store/api/item.h" 31 #include "store/api/item_handle.h" 32 #include <zorba/store_consts.h> 33 #include "store_defs.h" 34 #include "shared_types.h" 35 #include "tree_id.h" 36 37 #ifndef ZORBA_NO_FULL_TEXT 38 #include "naive_ft_token_iterator.h" 39 #endif /* ZORBA_NO_FULL_TEXT */ 40 41 #include "zorbatypes/schema_types.h" 42 #include "zorbatypes/datetime.h" 43 44 #include "diagnostics/xquery_diagnostics.h" 45 #include "ordpath.h" 46 47 48 namespace zorba 49 { 50 51 namespace simplestore 52 { 53 54 55 enum AnyUriTypeCode 56 { 57 NON_SPECIALIZED_ANY_URI, 58 STRUCTURAL_INFORMATION_ANY_URI 59 }; 60 61 class AtomicItemTokenizerCallback; 62 63 class QNameItem; 64 typedef store::ItemHandle<QNameItem> QNameItem_t; 65 66 67 /****************************************************************************** 68 69 *******************************************************************************/ 70 71 class AtomicItem : public store::Item 72 { 73 protected: SYNC_CODE(mutable RCLock theRCLock;)74 SYNC_CODE(mutable RCLock theRCLock;) 75 76 public: 77 AtomicItem() : store::Item(ATOMIC) { } 78 ~AtomicItem()79 virtual ~AtomicItem() {} 80 81 SYNC_CODE(RCLock* getRCLock() const { return &theRCLock; }) 82 83 void getTypedValue(store::Item_t& val, store::Iterator_t& iter) const; 84 85 virtual AnyUriTypeCode getAnyUriTypeCode() const; 86 87 bool castToLong(store::Item_t& result) const; 88 89 void coerceToDouble(store::Item_t& result, bool force, bool& lossy) const; 90 }; 91 92 93 /******************************************************************************* 94 class UserTypedAtomicItem 95 ********************************************************************************/ 96 class UserTypedAtomicItem : public AtomicItem 97 { 98 friend class BasicItemFactory; 99 friend class AtomicItem; 100 101 protected: 102 AtomicItem_t theBaseItem; 103 store::Item_t theTypeName; 104 105 protected: UserTypedAtomicItem(store::Item_t & baseItem,store::Item_t & typeName)106 UserTypedAtomicItem( 107 store::Item_t& baseItem, 108 store::Item_t& typeName) 109 { 110 theBaseItem.transfer(baseItem); 111 theTypeName.transfer(typeName); 112 } 113 UserTypedAtomicItem()114 UserTypedAtomicItem() {} 115 116 public: 117 store::Item* getBaseItem() const; 118 getTypeCode()119 store::SchemaTypeCode getTypeCode() const { return theBaseItem->getTypeCode(); } 120 getType()121 store::Item* getType() const { return theTypeName.getp(); } 122 123 uint32_t hash(long timezone = 0, const XQPCollator* collation = 0) const 124 { 125 return theBaseItem->hash(timezone, collation); 126 } 127 128 bool equals( 129 const store::Item* other, 130 long timezone = 0, 131 const XQPCollator* collation = 0) const 132 { 133 if (other->getBaseItem() == NULL) 134 return theBaseItem->equals(other, timezone, collation); 135 else 136 return theBaseItem->equals(other->getBaseItem(), timezone, collation); 137 } 138 139 long compare( 140 const store::Item* other, 141 long timezone = 0, 142 const XQPCollator* collation = 0) const 143 { 144 if (other->getBaseItem() == NULL) 145 return theBaseItem->compare(other, timezone, collation); 146 else 147 return theBaseItem->compare(other->getBaseItem(), timezone, collation); 148 } 149 getEBV()150 bool getEBV() const { return theBaseItem->getEBV(); } 151 getStringValue()152 zstring getStringValue() const { return theBaseItem->getStringValue(); } 153 getStringValue2(zstring & val)154 void getStringValue2(zstring& val) const { theBaseItem->getStringValue2(val); } 155 appendStringValue(zstring & buf)156 void appendStringValue(zstring& buf) const { theBaseItem->appendStringValue(buf); } 157 getString()158 const zstring& getString() const { return theBaseItem->getString(); } 159 isEncoded()160 bool isEncoded() const { return theBaseItem->isEncoded(); } 161 getBase64BinaryValue(size_t & s)162 const char* getBase64BinaryValue(size_t& s) const 163 { 164 return theBaseItem->getBase64BinaryValue(s); 165 } 166 getHexBinaryValue()167 xs_hexBinary getHexBinaryValue() const { return theBaseItem->getHexBinaryValue(); } 168 getBooleanValue()169 bool getBooleanValue() const { return theBaseItem->getBooleanValue(); } 170 getDoubleValue()171 xs_double getDoubleValue() const { return theBaseItem->getDoubleValue(); } 172 getFloatValue()173 xs_float getFloatValue() const { return theBaseItem->getFloatValue(); } 174 getDecimalValue()175 xs_decimal getDecimalValue() const { return theBaseItem->getDecimalValue(); } 176 getIntegerValue()177 xs_integer getIntegerValue() const { return theBaseItem->getIntegerValue(); } 178 getUnsignedIntegerValue()179 xs_nonNegativeInteger getUnsignedIntegerValue() const { return theBaseItem->getUnsignedIntegerValue(); } 180 getLongValue()181 xs_long getLongValue() const { return theBaseItem->getLongValue(); } 182 getIntValue()183 xs_int getIntValue() const { return theBaseItem->getIntValue(); } 184 getShortValue()185 xs_short getShortValue() const { return theBaseItem->getShortValue(); } 186 getByteValue()187 xs_byte getByteValue() const { return theBaseItem->getByteValue(); } 188 getUnsignedLongValue()189 xs_unsignedLong getUnsignedLongValue() const { return theBaseItem->getUnsignedLongValue(); } 190 getUnsignedIntValue()191 xs_unsignedInt getUnsignedIntValue() const { return theBaseItem->getUnsignedIntValue(); } 192 getUnsignedShortValue()193 xs_unsignedShort getUnsignedShortValue() const { return theBaseItem->getUnsignedShortValue(); } 194 getUnsignedByteValue()195 xs_unsignedByte getUnsignedByteValue() const { return theBaseItem->getUnsignedByteValue(); } 196 isNaN()197 bool isNaN() const { return theBaseItem->isNaN(); } 198 isPosOrNegInf()199 bool isPosOrNegInf() const { return theBaseItem->isPosOrNegInf(); } 200 getDateTimeValue()201 const xs_dateTime& getDateTimeValue() const 202 { 203 return theBaseItem->getDateTimeValue(); 204 } 205 getDateValue()206 const xs_date& getDateValue() const 207 { 208 return theBaseItem->getDateValue(); 209 } 210 getTimeValue()211 const xs_time& getTimeValue() const 212 { 213 return theBaseItem->getTimeValue(); 214 } 215 getGYearMonthValue()216 const xs_gYearMonth& getGYearMonthValue() const 217 { 218 return theBaseItem->getGYearMonthValue(); 219 } 220 getGYearValue()221 const xs_gYear& getGYearValue() const 222 { 223 return theBaseItem->getGYearValue(); 224 } 225 getGMonthValue()226 const xs_gMonth& getGMonthValue() const 227 { 228 return theBaseItem->getGMonthValue(); 229 } 230 getGMonthDayValue()231 const xs_gMonthDay& getGMonthDayValue() const 232 { 233 return theBaseItem->getGMonthDayValue(); 234 } 235 getGDayValue()236 const xs_gDay& getGDayValue() const 237 { 238 return theBaseItem->getGDayValue(); 239 } 240 getDurationValue()241 const xs_duration& getDurationValue() const 242 { 243 return theBaseItem->getDurationValue(); 244 } 245 getDayTimeDurationValue()246 const xs_dayTimeDuration& getDayTimeDurationValue() const 247 { 248 return theBaseItem->getDayTimeDurationValue(); 249 } 250 getYearMonthDurationValue()251 const xs_yearMonthDuration& getYearMonthDurationValue() const 252 { 253 return theBaseItem->getYearMonthDurationValue(); 254 } 255 show()256 zstring show() const { return "UserTypedAtomicItem [" + theBaseItem->show() + "]"; } 257 }; 258 259 260 /******************************************************************************* 261 class UntypedAtomicItem 262 ********************************************************************************/ 263 class UntypedAtomicItem : public AtomicItem 264 { 265 friend class BasicItemFactory; 266 friend class AtomicItem; 267 268 protected: 269 zstring theValue; 270 271 protected: UntypedAtomicItem(zstring & value)272 UntypedAtomicItem(zstring& value) { theValue.take(value); } 273 UntypedAtomicItem()274 UntypedAtomicItem() {} 275 276 public: 277 bool castToUri(store::Item_t& result) const; 278 279 bool castToString(store::Item_t& result) const; 280 281 bool castToDateTime(store::Item_t& result) const; 282 283 bool castToDate(store::Item_t& result) const; 284 285 bool castToTime(store::Item_t& result) const; 286 287 bool castToGYear(store::Item_t& result) const; 288 289 bool castToGYearMonth(store::Item_t& result) const; 290 291 bool castToGMonthDay(store::Item_t& result) const; 292 293 bool castToGMonth(store::Item_t& result) const; 294 295 bool castToGDay(store::Item_t& result) const; 296 297 bool castToDuration(store::Item_t& result) const; 298 299 bool castToDouble(store::Item_t& result) const; 300 301 bool castToDecimal(store::Item_t& result) const; 302 303 bool castToInteger(store::Item_t& result) const; 304 305 bool castToHexBinary(store::Item_t& result) const; 306 307 bool castToBase64Binary(store::Item_t& result) const; 308 309 bool castToBoolean(store::Item_t& result) const; 310 getTypeCode()311 store::SchemaTypeCode getTypeCode() const { return store::XS_UNTYPED_ATOMIC; } 312 313 store::Item* getType() const; 314 315 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 316 317 bool equals( 318 const store::Item* other, 319 long timezone = 0, 320 const XQPCollator* collation = 0) const; 321 322 long compare( 323 const store::Item* other, 324 long timezone = 0, 325 const XQPCollator* collation = 0) const; 326 327 bool getEBV() const; 328 getStringValue()329 zstring getStringValue() const { return theValue; } 330 getStringValue2(zstring & val)331 void getStringValue2(zstring& val) const { val = theValue; } 332 appendStringValue(zstring & buf)333 void appendStringValue(zstring& buf) const { buf += theValue; } 334 getString()335 const zstring& getString() const { return theValue; } 336 337 zstring show() const; 338 }; 339 340 341 /******************************************************************************* 342 Instances of this class can be classified into two categories: 343 - QNames in the pool. There can be only one QName in the pool with a given 344 namespace, prefix and local name. 345 - QNames that are not in the pool. The user owns them and is responsible 346 for their destruction (which can be realized with reference-counting 347 pointers). The ternary constructors construct such QNames. 348 349 Normalized QNames are QNames without a prefix and that are in the pool. There 350 is only one normalized QName with a given namespace and local name, so that 351 direct pointer comparison can be used to compare them. 352 353 Each QName points to its associated normalized QName (same namespace and 354 prefix) which provides an efficient way of comparing two QNames. 355 356 Pointer comparison on normalized QNames is equivalent to using the equals() 357 method. For example, a pointer to the normalized QName can be used as a key. 358 359 A newly constructed instance of this class can be initialized as a normalized 360 QName (always in the pool), as an unnormalized QName in the pool or as an 361 unnormalized QName not in the pool. It can also be invalidated and initialized 362 again. 363 *******************************************************************************/ 364 class QNameItem : public AtomicItem 365 { 366 // The QName pool is the only class authorized to edit namespace/prefix/local 367 // name. 368 friend class QNamePool; 369 370 private: 371 zstring theNamespace; 372 zstring thePrefix; 373 zstring theLocal; 374 375 // Points to the corresponding normalized QName in the pool (pool owns this 376 // pointer). 377 const QNameItem * theNormalizedQName; 378 379 bool theIsInPool; 380 381 // Used by the pool for managing the cache. 382 uint16_t thePosition; 383 uint16_t theNextFree; 384 uint16_t thePrevFree; 385 386 public: ~QNameItem()387 virtual ~QNameItem() {} 388 389 // zorba::store::Item interface. 390 391 bool equals( 392 const store::Item* item, 393 long timezone = 0, 394 const XQPCollator* aCollation = 0) const; 395 396 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 397 398 store::Item* getType() const; 399 getTypeCode()400 store::SchemaTypeCode getTypeCode() const { return store::XS_QNAME; } 401 402 bool getEBV() const; 403 getLocalName()404 const zstring& getLocalName() const { return theLocal; } 405 getNamespace()406 const zstring& getNamespace() const { return theNamespace; } 407 getPrefix()408 const zstring& getPrefix() const { return thePrefix; } 409 410 zstring getStringValue() const; 411 412 void getStringValue2(zstring& val) const; 413 414 void appendStringValue(zstring& buf) const; 415 416 417 // Class-specific extensions. 418 getNormalized()419 const QNameItem* getNormalized() const { return theNormalizedQName; } 420 421 bool isBaseUri() const; 422 423 bool isIdQName() const; 424 425 zstring show() const; 426 427 protected: QNameItem()428 QNameItem() 429 : 430 AtomicItem(), 431 theNormalizedQName(NULL), 432 theIsInPool(true), 433 thePosition(0), 434 theNextFree(0), 435 thePrevFree(0) 436 { 437 } 438 439 // These two constructors are for building QName items outside 440 // of the pool (they point back to the normalized QName in the pool). 441 // Zorba does not use them, but extensions to the simple store may. 442 QNameItem(const char* ns, const char* prefix, const char* local); 443 444 QNameItem(const zstring& ns, const zstring& prefix, const zstring& local); 445 446 void free(); 447 isValid()448 bool isValid() const 449 { 450 assert(theNormalizedQName == NULL || 451 (theNormalizedQName->isNormalized() && 452 theNamespace == theNormalizedQName->theNamespace && 453 theLocal == theNormalizedQName->theLocal)); 454 455 return theNormalizedQName != NULL; 456 } 457 isInCache()458 bool isInCache() const { return thePosition != 0; } 459 isOverflow()460 bool isOverflow() const { return thePosition == 0; } 461 isNormalized()462 bool isNormalized() const 463 { 464 assert(theNormalizedQName != this || thePrefix.empty()); 465 assert(!theIsInPool || theNormalizedQName == this || !thePrefix.empty()); 466 467 return theNormalizedQName == this; 468 } 469 initializeAsNormalizedQName(const zstring & ns,const zstring & local)470 void initializeAsNormalizedQName(const zstring& ns, const zstring& local) 471 { 472 assert(!isValid()); 473 474 theNormalizedQName = this; 475 theNamespace = ns; 476 thePrefix.clear(); 477 theLocal = local; 478 479 assert(isNormalized()); 480 assert(isValid()); 481 } 482 initializeAsUnnormalizedQName(const QNameItem * normalizedQName,const zstring & prefix)483 void initializeAsUnnormalizedQName( 484 const QNameItem* normalizedQName, 485 const zstring& prefix) 486 { 487 assert(!isValid()); 488 489 theNormalizedQName = normalizedQName; 490 theNormalizedQName->addReference(); 491 theNamespace = theNormalizedQName->theNamespace; 492 thePrefix = prefix; 493 theLocal = theNormalizedQName->theLocal; 494 495 assert(!isNormalized()); 496 assert(isValid()); 497 } 498 499 void initializeAsQNameNotInPool( 500 const zstring& ns, 501 const zstring& pre, 502 const zstring& local); 503 invalidate(bool asynchronous,QNameItem ** aNormalizationVictim)504 void invalidate(bool asynchronous, QNameItem** aNormalizationVictim) 505 { 506 assert(isValid()); 507 508 if (!isNormalized()) 509 { 510 if (asynchronous) 511 { 512 // caller must later remove reference to returned aNormalizationVictim. 513 *aNormalizationVictim = const_cast<QNameItem*>(theNormalizedQName); 514 } 515 else 516 { 517 QNameItem* lNormalized = const_cast<QNameItem*>(theNormalizedQName); 518 lNormalized->removeReference(); 519 } 520 } 521 522 theNormalizedQName = NULL; 523 524 assert(!isValid()); 525 } 526 }; 527 528 529 /******************************************************************************* 530 class NotationItem 531 ********************************************************************************/ 532 class NotationItem : public AtomicItem 533 { 534 protected: 535 QNameItem_t theQName; 536 537 protected: 538 friend class BasicItemFactory; 539 540 NotationItem( 541 const zstring& nameSpace, 542 const zstring& prefix, 543 const zstring& localName); 544 545 NotationItem(store::Item* qname); 546 547 public: 548 virtual ~NotationItem(); 549 550 store::Item* getType() const; 551 552 bool equals( 553 const store::Item* item, 554 long timezone = 0, 555 const XQPCollator* aCollation = 0) const; 556 557 zstring getStringValue() const; 558 559 void getStringValue2(zstring& val) const; 560 561 void appendStringValue(zstring& buf) const; 562 getNamespace()563 const zstring& getNamespace() const { return theQName->getNamespace(); } 564 getPrefix()565 const zstring& getPrefix() const { return theQName->getPrefix(); } 566 getLocalName()567 const zstring& getLocalName() const { return theQName->getLocalName(); } 568 569 zstring show() const; 570 getTypeCode()571 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_NOTATION; } 572 }; 573 574 575 /******************************************************************************* 576 class AnyUriItem 577 ********************************************************************************/ 578 class AnyUriItem : public AtomicItem 579 { 580 friend class BasicItemFactory; 581 582 protected: 583 zstring theValue; 584 585 protected: AnyUriItem(zstring & value)586 AnyUriItem(zstring& value) { theValue.take(value); } 587 AnyUriItem()588 AnyUriItem() {} 589 590 public: getAnyUriTypeCode()591 virtual AnyUriTypeCode getAnyUriTypeCode() const 592 { 593 return NON_SPECIALIZED_ANY_URI; 594 } 595 getTypeCode()596 store::SchemaTypeCode getTypeCode() const { return store::XS_ANY_URI; } 597 598 store::Item* getType() const; 599 600 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 601 602 bool equals( 603 const store::Item* item, 604 long timezone = 0, 605 const XQPCollator* aCollation = 0) const 606 { 607 return item->getString() == theValue; 608 } 609 610 long compare( 611 const Item* other, 612 long timezone = 0, 613 const XQPCollator* aCollation = 0) const 614 { 615 return theValue.compare(other->getString()); 616 } 617 618 bool getEBV() const; 619 getStringValue()620 zstring getStringValue() const { return theValue; } 621 getStringValue2(zstring & val)622 void getStringValue2(zstring& val) const { val = theValue; } 623 appendStringValue(zstring & buf)624 void appendStringValue(zstring& buf) const { buf += theValue; } 625 getString()626 const zstring& getString() const { return theValue; } 627 628 zstring show() const; 629 630 virtual bool 631 isAncestor(const store::Item_t&) const; 632 633 virtual bool 634 isFollowingSibling(const store::Item_t&) const; 635 636 virtual bool 637 isFollowing(const store::Item_t&) const; 638 639 virtual bool 640 isInSubtreeOf(const store::Item_t&) const; 641 642 virtual bool 643 isDescendant(const store::Item_t&) const; 644 645 virtual bool 646 isPrecedingSibling(const store::Item_t&) const; 647 648 virtual bool 649 isPreceding(const store::Item_t&) const; 650 651 virtual bool 652 isChild(const store::Item_t&) const; 653 654 virtual bool 655 isAttribute(const store::Item_t&) const; 656 657 virtual bool 658 isParent(const store::Item_t&) const; 659 660 virtual bool 661 isPrecedingInDocumentOrder(const store::Item_t&) const; 662 663 virtual bool 664 isFollowingInDocumentOrder(const store::Item_t&) const; 665 666 virtual store::Item_t 667 getLevel() const; 668 669 virtual bool 670 isAttributeRef() const; 671 672 virtual bool 673 isCommentRef() const; 674 675 virtual bool 676 isDocumentRef() const; 677 678 virtual bool 679 isElementRef() const; 680 681 virtual bool 682 isProcessingInstructionRef() const; 683 684 virtual bool 685 isTextRef() const; 686 687 virtual bool 688 isSibling(const store::Item_t&) const; 689 690 virtual bool 691 inSameTree(const store::Item_t&) const; 692 693 virtual bool 694 inCollection() const; 695 696 virtual bool 697 inSameCollection(const store::Item_t&) const; 698 }; 699 700 701 /******************************************************************************* 702 class StructuralAnyUriItem 703 ********************************************************************************/ 704 class StructuralAnyUriItem : public AtomicItem 705 { 706 protected: 707 ulong theCollectionId; 708 TreeId theTreeId; 709 store::StoreConsts::NodeKind theNodeKind; 710 OrdPath theOrdPath; 711 712 // The value is computed lazily when needed. 713 // The empty string is used if it has not been computed yet. 714 mutable zstring theEncodedValue; 715 716 public: getAnyUriTypeCode()717 virtual AnyUriTypeCode getAnyUriTypeCode() const 718 { 719 return STRUCTURAL_INFORMATION_ANY_URI; 720 } 721 getTypeCode()722 store::SchemaTypeCode getTypeCode() const 723 { 724 return store::XS_ANY_URI; 725 } 726 727 store::Item* getType() const; 728 729 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 730 731 bool equals( 732 const store::Item* item, 733 long timezone = 0, 734 const XQPCollator* aCollation = 0) const; 735 736 long compare( 737 const Item* other, 738 long timezone = 0, 739 const XQPCollator* aCollation = 0) const; 740 741 // A structural URI is never empty. getEBV()742 bool getEBV() const { return true; } 743 744 zstring getStringValue() const; 745 746 void getStringValue2(zstring& val) const; 747 748 void appendStringValue(zstring& buf) const; 749 getString()750 const zstring& getString() const 751 { 752 if (theEncodedValue == "") 753 { 754 encode(); 755 } 756 return theEncodedValue; 757 } 758 759 zstring show() const; 760 761 bool 762 isAncestor(const store::Item_t&) const; 763 764 bool 765 isFollowingSibling(const store::Item_t&) const; 766 767 bool 768 isFollowing(const store::Item_t&) const; 769 770 bool 771 isInSubtreeOf(const store::Item_t&) const; 772 773 bool 774 isDescendant(const store::Item_t&) const; 775 776 bool 777 isPrecedingSibling(const store::Item_t&) const; 778 779 bool 780 isPreceding(const store::Item_t&) const; 781 782 bool 783 isChild(const store::Item_t&) const; 784 785 bool 786 isAttribute(const store::Item_t&) const; 787 788 bool 789 isParent(const store::Item_t&) const; 790 791 bool 792 isPrecedingInDocumentOrder(const store::Item_t&) const; 793 794 bool 795 isFollowingInDocumentOrder(const store::Item_t&) const; 796 797 store::Item_t 798 getLevel() const; 799 800 bool 801 isAttributeRef() const; 802 803 bool 804 isCommentRef() const; 805 806 bool 807 isDocumentRef() const; 808 809 bool 810 isElementRef() const; 811 812 bool 813 isProcessingInstructionRef() const; 814 815 bool 816 isTextRef() const; 817 818 bool 819 isSibling(const store::Item_t&) const; 820 821 bool 822 inSameTree(const store::Item_t&) const; 823 824 bool 825 inCollection() const; 826 827 bool 828 inSameCollection(const store::Item_t&) const; 829 830 private: 831 // Forces computation of the value. 832 void encode() const; 833 834 protected: 835 friend class BasicItemFactory; 836 837 StructuralAnyUriItem(zstring& value); 838 839 StructuralAnyUriItem( 840 ulong collectionId, 841 const TreeId& treeId, 842 store::StoreConsts::NodeKind nodeKind, 843 const OrdPath& ordPath); 844 StructuralAnyUriItem()845 StructuralAnyUriItem() : theEncodedValue("") {} 846 }; 847 848 849 /******************************************************************************* 850 class StringItem 851 ********************************************************************************/ 852 class StringItem : public AtomicItem 853 { 854 friend class BasicItemFactory; 855 #ifndef ZORBA_NO_FULL_TEXT 856 friend class AtomicItemTokenizerCallback; 857 #endif /* ZORBA_NO_FULL_TEXT */ 858 859 protected: 860 zstring theValue; 861 862 protected: StringItem(zstring & value)863 StringItem(zstring& value) { theValue.take(value); } 864 StringItem()865 StringItem() {} 866 867 public: 868 getTypeCode()869 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_STRING; } 870 871 virtual store::Item* getType() const; 872 873 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 874 875 bool equals( 876 const store::Item*, 877 long timezone = 0, 878 const XQPCollator* aCollation = 0) const; 879 880 long compare( 881 const Item* other, 882 long timezone = 0, 883 const XQPCollator* aCollation = 0) const; 884 885 bool getEBV() const; 886 getStringValue()887 zstring getStringValue() const { return theValue; } 888 getStringValue2(zstring & val)889 void getStringValue2(zstring& val) const { val = theValue; } 890 appendStringValue(zstring & buf)891 void appendStringValue(zstring& buf) const { buf += theValue; } 892 getString()893 const zstring& getString() const { return theValue; } 894 895 virtual zstring show() const; 896 897 #ifndef ZORBA_NO_FULL_TEXT 898 FTTokenIterator_t getTokens( 899 TokenizerProvider const&, 900 Tokenizer::State&, 901 locale::iso639_1::type, 902 bool = false ) const; 903 #endif /* ZORBA_NO_FULL_TEXT */ 904 }; 905 906 907 /******************************************************************************* 908 class StreamableStringItem 909 ********************************************************************************/ 910 class StreamableStringItem : public StringItem 911 { 912 friend class BasicItemFactory; 913 914 protected: 915 std::istream & theIstream; 916 917 bool theIsMaterialized; 918 bool theIsConsumed; 919 bool theIsSeekable; 920 921 StreamReleaser theStreamReleaser; 922 923 store::Item_t theStreamableDependent; 924 925 public: 926 bool equals( 927 store::Item const*, 928 long timezone = 0, 929 const XQPCollator* collator = 0 ) const; 930 931 long compare( 932 Item const* other, 933 long timezone = 0, 934 const XQPCollator* collator = 0) const; 935 936 bool getEBV() const; 937 938 zstring getStringValue() const; 939 940 void getStringValue2(zstring& result) const; 941 942 void appendStringValue(zstring& buf) const; 943 944 const zstring& getString() const; 945 946 uint32_t hash(long timezone = 0, const XQPCollator* collator = 0) const; 947 948 zstring show() const; 949 950 bool isStreamable() const; 951 952 bool isSeekable() const; 953 954 std::istream& getStream(); 955 956 StreamReleaser getStreamReleaser(); 957 958 void setStreamReleaser(StreamReleaser aReleaser); 959 ~StreamableStringItem()960 virtual ~StreamableStringItem() 961 { 962 if (theStreamReleaser) 963 { 964 theStreamReleaser(&theIstream); 965 } 966 } 967 968 protected: 969 StreamableStringItem( 970 std::istream& aStream, 971 StreamReleaser streamReleaser, 972 bool seekable = false); 973 974 StreamableStringItem( 975 store::Item_t& aStreamableDependent); 976 977 void materialize() const; 978 }; 979 980 981 /******************************************************************************* 982 class NormalizedStringItem 983 ********************************************************************************/ 984 class NormalizedStringItem : public StringItem 985 { 986 friend class BasicItemFactory; 987 988 protected: NormalizedStringItem(zstring & value)989 NormalizedStringItem(zstring& value) : StringItem(value) {} 990 991 public: getTypeCode()992 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_NORMALIZED_STRING; } 993 994 virtual store::Item* getType() const; 995 996 virtual zstring show() const; 997 }; 998 999 1000 /******************************************************************************* 1001 class TokenItem 1002 ********************************************************************************/ 1003 class TokenItem : public NormalizedStringItem 1004 { 1005 friend class BasicItemFactory; 1006 1007 public: TokenItem(zstring & value)1008 TokenItem(zstring& value) : NormalizedStringItem(value) {} 1009 getTypeCode()1010 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_TOKEN; } 1011 1012 virtual store::Item* getType() const; 1013 1014 virtual zstring show() const; 1015 }; 1016 1017 1018 /******************************************************************************* 1019 class NMTOKENItem 1020 ********************************************************************************/ 1021 class NMTOKENItem : public TokenItem 1022 { 1023 friend class BasicItemFactory; 1024 1025 protected: NMTOKENItem(zstring & value)1026 NMTOKENItem(zstring& value) : TokenItem(value) {} 1027 1028 public: getTypeCode()1029 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_NMTOKEN; } 1030 1031 virtual store::Item* getType() const; 1032 1033 virtual zstring show() const; 1034 }; 1035 1036 1037 /******************************************************************************* 1038 class LanguageItem 1039 ********************************************************************************/ 1040 class LanguageItem : public TokenItem 1041 { 1042 friend class BasicItemFactory; 1043 1044 protected: LanguageItem(zstring & value)1045 LanguageItem(zstring& value) : TokenItem(value) {} 1046 1047 public: getTypeCode()1048 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_LANGUAGE; } 1049 1050 virtual store::Item* getType() const; 1051 1052 virtual zstring show() const; 1053 }; 1054 1055 1056 /******************************************************************************* 1057 class NameItem 1058 ********************************************************************************/ 1059 class NameItem : public TokenItem 1060 { 1061 friend class BasicItemFactory; 1062 1063 protected: NameItem(zstring & value)1064 NameItem(zstring& value) : TokenItem(value) {} 1065 1066 public: getTypeCode()1067 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_NAME; } 1068 1069 virtual store::Item* getType() const; 1070 1071 virtual zstring show() const; 1072 }; 1073 1074 1075 /******************************************************************************* 1076 class NCNameItem 1077 ********************************************************************************/ 1078 class NCNameItem : public NameItem 1079 { 1080 friend class BasicItemFactory; 1081 1082 protected: NCNameItem(zstring & value)1083 NCNameItem(zstring& value) : NameItem(value) {} 1084 1085 public: getTypeCode()1086 virtual store::SchemaTypeCode getTypeCode() const { return store::XS_NCNAME; } 1087 1088 virtual store::Item* getType() const; 1089 1090 virtual zstring show() const; 1091 }; 1092 1093 1094 /******************************************************************************* 1095 class IDItem 1096 ********************************************************************************/ 1097 class IDItem : public NCNameItem 1098 { 1099 friend class BasicItemFactory; 1100 1101 protected: IDItem(zstring & value)1102 IDItem(zstring& value) : NCNameItem(value) { } 1103 1104 public: getTypeCode()1105 store::SchemaTypeCode getTypeCode() const { return store::XS_ID; } 1106 1107 store::Item* getType() const; 1108 1109 virtual zstring show() const; 1110 }; 1111 1112 /******************************************************************************* 1113 class IDREFItem 1114 ********************************************************************************/ 1115 class IDREFItem : public NCNameItem 1116 { 1117 friend class BasicItemFactory; 1118 1119 protected: IDREFItem(zstring & value)1120 IDREFItem(zstring& value) : NCNameItem(value) { } 1121 1122 public: getTypeCode()1123 store::SchemaTypeCode getTypeCode() const { return store::XS_IDREF; } 1124 1125 store::Item* getType() const; 1126 1127 virtual zstring show() const; 1128 }; 1129 1130 /******************************************************************************* 1131 class ENTITYItem 1132 ********************************************************************************/ 1133 class ENTITYItem : public NCNameItem 1134 { 1135 friend class BasicItemFactory; 1136 1137 protected: ENTITYItem(zstring & value)1138 ENTITYItem(zstring& value) : NCNameItem(value) { } 1139 1140 public: getTypeCode()1141 store::SchemaTypeCode getTypeCode() const { return store::XS_ENTITY; } 1142 1143 store::Item* getType() const; 1144 1145 virtual zstring show() const; 1146 }; 1147 1148 1149 /******************************************************************************* 1150 class DateTimeItem 1151 ********************************************************************************/ 1152 class DateTimeItem : public AtomicItem 1153 { 1154 friend class BasicItemFactory; 1155 1156 protected: 1157 DateTime theValue; 1158 1159 protected: DateTimeItem(const DateTime * aValue)1160 DateTimeItem(const DateTime* aValue) : theValue(*aValue) { }; 1161 DateTimeItem()1162 DateTimeItem() { }; 1163 1164 public: getDateTimeValue()1165 const xs_dateTime& getDateTimeValue() const { return theValue; } 1166 getDateValue()1167 const xs_date& getDateValue() const { return theValue; } 1168 getTimeValue()1169 const xs_time& getTimeValue() const { return theValue; } 1170 getGYearMonthValue()1171 const xs_gYearMonth& getGYearMonthValue() const { return theValue; } 1172 getGYearValue()1173 const xs_gYear& getGYearValue() const { return theValue; } 1174 getGMonthValue()1175 const xs_gMonth& getGMonthValue() const { return theValue; } 1176 getGMonthDayValue()1177 const xs_gMonthDay& getGMonthDayValue() const { return theValue; } 1178 getGDayValue()1179 const xs_gDay& getGDayValue() const { return theValue; } 1180 1181 store::SchemaTypeCode getTypeCode() const; 1182 1183 store::Item* getType() const; 1184 1185 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 1186 1187 bool equals( 1188 const store::Item*, 1189 long timezone = 0, 1190 const XQPCollator* aCollation = 0) const; 1191 1192 long compare( 1193 const Item* other, 1194 long timezone = 0, 1195 const XQPCollator* aCollation = 0) const; 1196 1197 bool getEBV() const; 1198 1199 zstring getStringValue() const; 1200 1201 void getStringValue2(zstring& val) const; 1202 1203 void appendStringValue(zstring& buf) const; 1204 1205 zstring show() const; 1206 }; 1207 1208 1209 /******************************************************************************* 1210 class DurationItem 1211 ********************************************************************************/ 1212 class DurationItem : public AtomicItem 1213 { 1214 friend class BasicItemFactory; 1215 1216 protected: 1217 Duration theValue; 1218 1219 protected: DurationItem(const xs_duration * aValue)1220 DurationItem(const xs_duration* aValue) : theValue(*aValue) { }; 1221 DurationItem()1222 DurationItem() {} 1223 1224 public: 1225 const xs_duration& getDurationValue() const; 1226 1227 const xs_dayTimeDuration& getDayTimeDurationValue() const; 1228 1229 const xs_yearMonthDuration& getYearMonthDurationValue() const; 1230 1231 store::SchemaTypeCode getTypeCode() const; 1232 1233 store::Item* getType() const; 1234 1235 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 1236 { 1237 return theValue.hash(); 1238 } 1239 1240 bool equals( 1241 const store::Item* other, 1242 long timezone = 0, 1243 const XQPCollator* aCollation = 0) const 1244 { 1245 return theValue == other->getDurationValue(); 1246 } 1247 1248 1249 long compare( 1250 const Item* other, 1251 long timezone = 0, 1252 const XQPCollator* aCollation = 0) const 1253 { 1254 return theValue.compare(other->getDurationValue()); 1255 } 1256 1257 bool getEBV() const; 1258 1259 zstring getStringValue() const; 1260 1261 void getStringValue2(zstring& val) const; 1262 1263 void appendStringValue(zstring& buf) const; 1264 1265 zstring show() const; 1266 }; 1267 1268 1269 /******************************************************************************* 1270 class DoubleItem 1271 ********************************************************************************/ 1272 class DoubleItem : public AtomicItem 1273 { 1274 friend class BasicItemFactory; 1275 1276 protected: 1277 xs_double theValue; 1278 1279 protected: DoubleItem(const xs_double & aValue)1280 DoubleItem(const xs_double& aValue) : theValue( aValue ) {} 1281 DoubleItem()1282 DoubleItem() {} 1283 1284 public: getDoubleValue()1285 xs_double getDoubleValue() const { return theValue; } 1286 1287 bool isNaN() const; 1288 1289 bool isPosOrNegInf() const; 1290 getTypeCode()1291 store::SchemaTypeCode getTypeCode() const { return store::XS_DOUBLE; } 1292 1293 store::Item* getType() const; 1294 1295 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 1296 1297 bool equals( 1298 const store::Item* other, 1299 long timezone = 0, 1300 const XQPCollator* aCollation = 0) const 1301 { 1302 return theValue == other->getDoubleValue(); 1303 } 1304 1305 long compare( 1306 const Item* other, 1307 long timezone = 0, 1308 const XQPCollator* aCollation = 0) const 1309 { 1310 if (theValue.isNaN() || other->getDoubleValue().isNaN()) 1311 throw ZORBA_EXCEPTION(zerr::ZSTR0041_NAN_COMPARISON); 1312 1313 return theValue.compare(other->getDoubleValue()); 1314 } 1315 1316 bool getEBV() const; 1317 1318 zstring getStringValue() const; 1319 1320 void getStringValue2(zstring& val) const; 1321 1322 void appendStringValue(zstring& buf) const; 1323 1324 zstring show() const; 1325 }; 1326 1327 1328 /******************************************************************************* 1329 class FloatItem 1330 ********************************************************************************/ 1331 class FloatItem : public AtomicItem 1332 { 1333 friend class BasicItemFactory; 1334 1335 protected: 1336 xs_float theValue; 1337 1338 protected: FloatItem(const xs_float & aValue)1339 FloatItem(const xs_float& aValue) : theValue ( aValue ) {} 1340 FloatItem()1341 FloatItem() {} 1342 1343 public: getFloatValue()1344 xs_float getFloatValue() const { return theValue; } 1345 getDoubleValue()1346 xs_double getDoubleValue() const { return xs_double(theValue); } 1347 1348 bool isNaN() const; 1349 1350 bool isPosOrNegInf() const; 1351 getTypeCode()1352 store::SchemaTypeCode getTypeCode() const { return store::XS_FLOAT; } 1353 1354 store::Item* getType() const; 1355 1356 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 1357 1358 bool equals( 1359 const store::Item* other, 1360 long timezone = 0, 1361 const XQPCollator* aCollation = 0) const 1362 { 1363 return getDoubleValue() == other->getDoubleValue(); 1364 } 1365 1366 long compare( 1367 const Item* other, 1368 long timezone = 0, 1369 const XQPCollator* aCollation = 0) const 1370 { 1371 if (theValue.isNaN() || other->getFloatValue().isNaN()) 1372 throw ZORBA_EXCEPTION( zerr::ZSTR0041_NAN_COMPARISON ); 1373 1374 return getDoubleValue().compare(other->getDoubleValue()); 1375 } 1376 1377 bool getEBV() const; 1378 1379 zstring getStringValue() const; 1380 1381 void getStringValue2(zstring& val) const; 1382 1383 void appendStringValue(zstring& buf) const; 1384 1385 zstring show() const; 1386 }; 1387 1388 1389 /******************************************************************************* 1390 class DecimalItem 1391 1392 decimal 1393 | 1394 | 1395 integer 1396 | 1397 ------------------------------------------ 1398 | | | 1399 nonPositiveInteger nonNegativeInteger long 1400 | | | 1401 | ----------------- int 1402 negativeInteger | | | 1403 | | short 1404 positiveInteger unsignedLong | 1405 | byte 1406 unsignedInt 1407 | 1408 unsingedShort 1409 | 1410 unsingedByte 1411 1412 ********************************************************************************/ 1413 class DecimalItem : public AtomicItem 1414 { 1415 friend class BasicItemFactory; 1416 friend class IndexConditionImpl; 1417 friend class AtomicItem; 1418 1419 protected: 1420 xs_decimal theValue; 1421 DecimalItem(const xs_decimal & aValue)1422 DecimalItem(const xs_decimal& aValue) : theValue(aValue) {} 1423 DecimalItem()1424 DecimalItem() {} 1425 1426 public: getDecimalValue()1427 xs_decimal getDecimalValue() const { return theValue; } 1428 getTypeCode()1429 store::SchemaTypeCode getTypeCode() const { return store::XS_DECIMAL; } 1430 1431 store::Item* getType() const; 1432 1433 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 1434 { 1435 return theValue.hash(); 1436 } 1437 1438 bool equals( 1439 const store::Item* other, 1440 long timezone = 0 , 1441 const XQPCollator* aCollation = 0) const 1442 { 1443 return theValue == other->getDecimalValue(); 1444 } 1445 1446 long compare( 1447 const Item* other, 1448 long timezone = 0, 1449 const XQPCollator* aCollation = 0) const 1450 { 1451 return theValue.compare(other->getDecimalValue()); 1452 } 1453 1454 bool getEBV() const; 1455 1456 zstring getStringValue() const; 1457 1458 void getStringValue2(zstring& val) const; 1459 1460 void appendStringValue(zstring& buf) const; 1461 1462 bool isNaN() const; 1463 1464 zstring show() const; 1465 }; 1466 1467 1468 /******************************************************************************* 1469 class IntegerItem 1470 ********************************************************************************/ 1471 class IntegerItem : public AtomicItem 1472 { 1473 protected: IntegerItem()1474 IntegerItem() {} 1475 1476 public: 1477 virtual xs_decimal getDecimalValue() const = 0; 1478 virtual xs_integer getIntegerValue() const = 0; 1479 virtual xs_long getLongValue() const = 0; 1480 isNaN()1481 bool isNaN() const { return false; } 1482 }; 1483 1484 1485 /******************************************************************************* 1486 class IntegerItemImpl 1487 ********************************************************************************/ 1488 class IntegerItemImpl : public IntegerItem 1489 { 1490 friend class BasicItemFactory; 1491 friend class AtomicItem; 1492 1493 protected: 1494 xs_integer theValue; 1495 1496 protected: IntegerItemImpl(const xs_integer & aValue)1497 IntegerItemImpl(const xs_integer& aValue) : theValue ( aValue ) {} 1498 IntegerItemImpl()1499 IntegerItemImpl() {} 1500 1501 public: 1502 xs_decimal getDecimalValue() const; 1503 getIntegerValue()1504 xs_integer getIntegerValue() const { return theValue; } 1505 1506 xs_long getLongValue() const; 1507 1508 xs_unsignedInt getUnsignedIntValue() const; 1509 getUnsignedIntegerValue()1510 xs_nonNegativeInteger getUnsignedIntegerValue() const { return theValue; } 1511 1512 zstring getStringValue() const; 1513 1514 void getStringValue2(zstring&) const; 1515 1516 void appendStringValue(zstring&) const; 1517 getTypeCode()1518 store::SchemaTypeCode getTypeCode() const { return store::XS_INTEGER; } 1519 1520 store::Item* getType() const; 1521 1522 uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const; 1523 1524 long compare( 1525 const Item* other, 1526 long timezone = 0, 1527 const XQPCollator* aCollation = 0) const; 1528 1529 bool equals( 1530 const store::Item* other, 1531 long timezone = 0, 1532 const XQPCollator* aCollation = 0) const; 1533 1534 bool getEBV() const; 1535 1536 zstring show() const; 1537 }; 1538 1539 1540 /******************************************************************************* 1541 class NonPositiveIntegerItem 1542 ********************************************************************************/ 1543 class NonPositiveIntegerItem : public IntegerItem 1544 { 1545 friend class BasicItemFactory; 1546 1547 protected: 1548 xs_nonPositiveInteger theValue; 1549 NonPositiveIntegerItem(const xs_integer & aValue)1550 NonPositiveIntegerItem(const xs_integer& aValue) : theValue(aValue) {} 1551 NonPositiveIntegerItem()1552 NonPositiveIntegerItem() {} 1553 1554 public: 1555 xs_decimal getDecimalValue() const; 1556 1557 xs_integer getIntegerValue() const; 1558 1559 xs_long getLongValue() const; 1560 1561 zstring getStringValue() const; 1562 1563 void getStringValue2(zstring& val) const; 1564 1565 void appendStringValue(zstring&) const; 1566 getTypeCode()1567 virtual store::SchemaTypeCode getTypeCode() const 1568 { 1569 return store::XS_NON_POSITIVE_INTEGER; 1570 } 1571 1572 virtual store::Item* getType() const; 1573 1574 uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const; 1575 1576 long compare( 1577 const Item* other, 1578 long timezone = 0, 1579 const XQPCollator* aCollation = 0) const; 1580 1581 bool equals( 1582 const store::Item* other, 1583 long timezone = 0, 1584 const XQPCollator* aCollation = 0) const; 1585 1586 bool getEBV() const; 1587 1588 virtual zstring show() const; 1589 }; 1590 1591 1592 /******************************************************************************* 1593 class NegativeIntegerItem 1594 ********************************************************************************/ 1595 class NegativeIntegerItem : public NonPositiveIntegerItem 1596 { 1597 friend class BasicItemFactory; 1598 1599 protected: NegativeIntegerItem(const xs_integer & aValue)1600 NegativeIntegerItem(const xs_integer& aValue) : NonPositiveIntegerItem(aValue) {} 1601 NegativeIntegerItem()1602 NegativeIntegerItem() {} 1603 1604 public: getTypeCode()1605 store::SchemaTypeCode getTypeCode() const { return store::XS_NEGATIVE_INTEGER; } 1606 1607 store::Item* getType() const; 1608 1609 zstring show() const; 1610 }; 1611 1612 1613 /******************************************************************************* 1614 class NonNegativeIntegerItem 1615 ********************************************************************************/ 1616 class NonNegativeIntegerItem : public IntegerItem 1617 { 1618 friend class BasicItemFactory; 1619 1620 protected: 1621 xs_nonNegativeInteger theValue; 1622 NonNegativeIntegerItem(const xs_nonNegativeInteger & aValue)1623 NonNegativeIntegerItem(const xs_nonNegativeInteger& aValue) : theValue(aValue) {} 1624 NonNegativeIntegerItem()1625 NonNegativeIntegerItem() {} 1626 1627 public: 1628 xs_decimal getDecimalValue() const; 1629 1630 xs_integer getIntegerValue() const; 1631 1632 xs_long getLongValue() const; 1633 getUnsignedIntegerValue()1634 xs_nonNegativeInteger getUnsignedIntegerValue() const { return theValue; } 1635 1636 zstring getStringValue() const; 1637 1638 void getStringValue2(zstring& val) const; 1639 1640 void appendStringValue(zstring&) const; 1641 getTypeCode()1642 virtual store::SchemaTypeCode getTypeCode() const 1643 { 1644 return store::XS_NON_NEGATIVE_INTEGER; 1645 } 1646 1647 virtual store::Item* getType() const; 1648 1649 uint32_t hash(long = 0, const XQPCollator* aCollation = 0) const; 1650 1651 long compare( 1652 const Item* other, 1653 long timezone = 0, 1654 const XQPCollator* aCollation = 0) const; 1655 1656 bool equals( 1657 const store::Item* other, 1658 long timezone = 0, 1659 const XQPCollator* aCollation = 0) const; 1660 1661 bool getEBV() const; 1662 1663 virtual zstring show() const; 1664 }; 1665 1666 1667 /******************************************************************************* 1668 class PositiveIntegerItem 1669 ********************************************************************************/ 1670 class PositiveIntegerItem : public NonNegativeIntegerItem 1671 { 1672 friend class BasicItemFactory; 1673 1674 protected: PositiveIntegerItem(const xs_positiveInteger & aValue)1675 PositiveIntegerItem(const xs_positiveInteger& aValue) 1676 : 1677 NonNegativeIntegerItem(aValue) { } 1678 PositiveIntegerItem()1679 PositiveIntegerItem() {} 1680 1681 public: getTypeCode()1682 store::SchemaTypeCode getTypeCode() const { return store::XS_POSITIVE_INTEGER; } 1683 1684 store::Item* getType() const; 1685 1686 zstring show() const; 1687 }; 1688 1689 1690 /******************************************************************************* 1691 class LongItem 1692 ********************************************************************************/ 1693 class LongItem : public AtomicItem 1694 { 1695 friend class BasicItemFactory; 1696 friend class AtomicItem; 1697 1698 protected: 1699 xs_long theValue; 1700 1701 protected: LongItem(xs_long aValue)1702 LongItem(xs_long aValue) : theValue(aValue) {} 1703 LongItem()1704 LongItem() {} 1705 1706 public: 1707 xs_decimal getDecimalValue() const; 1708 1709 xs_integer getIntegerValue() const; 1710 getLongValue()1711 xs_long getLongValue() const { return theValue; } 1712 1713 xs_nonNegativeInteger getUnsignedIntegerValue() const; 1714 getTypeCode()1715 store::SchemaTypeCode getTypeCode() const { return store::XS_LONG; } 1716 1717 store::Item* getType() const; 1718 1719 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 1720 { 1721 return static_cast<uint32_t>(theValue); 1722 } 1723 1724 bool equals( 1725 const store::Item* other, 1726 long timezone = 0, 1727 const XQPCollator* collation = 0 ) const 1728 { 1729 try 1730 { 1731 return theValue == other->getLongValue(); 1732 } catch(ZorbaException const &)1733 catch (ZorbaException const&) 1734 { 1735 return getDecimalValue() == other->getDecimalValue(); 1736 } 1737 } 1738 1739 long compare( 1740 const Item* other, 1741 long timezone = 0, 1742 const XQPCollator* aCollation = 0) const 1743 { 1744 try 1745 { 1746 return (theValue < other->getLongValue() ? 1747 -1 : 1748 (theValue == other->getLongValue() ? 0 : 1)); 1749 } catch(ZorbaException const &)1750 catch (ZorbaException const&) 1751 { 1752 return getDecimalValue().compare(other->getDecimalValue()); 1753 } 1754 } 1755 1756 bool getEBV() const; 1757 1758 zstring getStringValue() const; 1759 1760 void getStringValue2(zstring& val) const; 1761 1762 void appendStringValue(zstring& buf) const; 1763 isNaN()1764 bool isNaN() const { return false; } 1765 1766 zstring show() const; 1767 }; 1768 1769 1770 /******************************************************************************* 1771 class IntItem 1772 ********************************************************************************/ 1773 class IntItem : public AtomicItem 1774 { 1775 friend class BasicItemFactory; 1776 friend class AtomicItem; 1777 1778 protected: 1779 xs_int theValue; 1780 1781 protected: IntItem(xs_int aValue)1782 IntItem(xs_int aValue) : theValue(aValue) {} 1783 IntItem()1784 IntItem() {} 1785 1786 public: isNaN()1787 bool isNaN() const { return false; } 1788 1789 xs_decimal getDecimalValue() const; 1790 1791 xs_integer getIntegerValue() const; 1792 getLongValue()1793 xs_long getLongValue() const { return static_cast<xs_long>(theValue); } 1794 getIntValue()1795 xs_int getIntValue() const { return theValue; } 1796 getTypeCode()1797 store::SchemaTypeCode getTypeCode() const { return store::XS_INT; } 1798 1799 store::Item* getType( ) const; 1800 1801 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 1802 { 1803 return static_cast<uint32_t>(theValue); 1804 } 1805 1806 bool equals( 1807 const store::Item* other, 1808 long timezone = 0, 1809 const XQPCollator* collation = 0 ) const 1810 { 1811 try 1812 { 1813 return theValue == other->getLongValue(); 1814 } catch(ZorbaException const &)1815 catch (ZorbaException const&) 1816 { 1817 return getDecimalValue() == other->getDecimalValue(); 1818 } 1819 } 1820 1821 long compare( 1822 const Item* other, 1823 long timezone = 0, 1824 const XQPCollator* aCollation = 0) const 1825 { 1826 try 1827 { 1828 return (theValue < other->getLongValue() ? 1829 -1 : 1830 (theValue == other->getLongValue() ? 0 : 1)); 1831 } catch(ZorbaException const &)1832 catch (ZorbaException const&) 1833 { 1834 return getDecimalValue().compare(other->getDecimalValue()); 1835 } 1836 } 1837 1838 bool getEBV() const; 1839 1840 zstring getStringValue() const; 1841 1842 void getStringValue2(zstring& val) const; 1843 1844 void appendStringValue(zstring& buf) const; 1845 1846 zstring show() const; 1847 }; 1848 1849 1850 /******************************************************************************* 1851 class ShortItem 1852 ********************************************************************************/ 1853 class ShortItem : public AtomicItem 1854 { 1855 friend class BasicItemFactory; 1856 friend class AtomicItem; 1857 1858 protected: 1859 xs_short theValue; 1860 1861 protected: ShortItem(xs_short aValue)1862 ShortItem(xs_short aValue) : theValue(aValue) {} 1863 ShortItem()1864 ShortItem() {} 1865 1866 public: 1867 xs_decimal getDecimalValue() const; 1868 1869 xs_integer getIntegerValue() const; 1870 getLongValue()1871 xs_long getLongValue() const { return static_cast<xs_long>(theValue); } 1872 getIntValue()1873 xs_int getIntValue() const { return static_cast<xs_int>(theValue); } 1874 getShortValue()1875 xs_short getShortValue() const { return theValue; } 1876 getTypeCode()1877 store::SchemaTypeCode getTypeCode() const { return store::XS_SHORT; } 1878 1879 store::Item* getType() const; 1880 1881 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 1882 { 1883 return static_cast<uint32_t>(theValue); 1884 } 1885 1886 bool equals( 1887 const store::Item* other, 1888 long timezone = 0, 1889 const XQPCollator* collation = 0 ) const 1890 { 1891 try 1892 { 1893 return theValue == other->getLongValue(); 1894 } catch(ZorbaException const &)1895 catch (ZorbaException const&) 1896 { 1897 return getDecimalValue() == other->getDecimalValue(); 1898 } 1899 } 1900 1901 long compare( 1902 const Item* other, 1903 long timezone = 0, 1904 const XQPCollator* collation = 0) const 1905 { 1906 try 1907 { 1908 return (theValue < other->getLongValue() ? 1909 -1 : 1910 (theValue == other->getLongValue() ? 0 : 1)); 1911 } catch(ZorbaException const &)1912 catch (ZorbaException const&) 1913 { 1914 return getDecimalValue().compare(other->getDecimalValue()); 1915 } 1916 } 1917 1918 bool getEBV() const; 1919 1920 zstring getStringValue() const; 1921 1922 void getStringValue2(zstring& val) const; 1923 1924 void appendStringValue(zstring& buf) const; 1925 1926 zstring show() const; 1927 isNaN()1928 bool isNaN() const { return false; } 1929 }; 1930 1931 1932 /******************************************************************************* 1933 class ByteItem 1934 ********************************************************************************/ 1935 class ByteItem : public AtomicItem 1936 { 1937 friend class BasicItemFactory; 1938 friend class AtomicItem; 1939 1940 protected: 1941 xs_byte theValue; 1942 1943 protected: ByteItem(xs_byte aValue)1944 ByteItem(xs_byte aValue) : theValue(aValue) {} 1945 ByteItem()1946 ByteItem() {} 1947 1948 public: 1949 xs_decimal getDecimalValue() const; 1950 1951 xs_integer getIntegerValue() const; 1952 getLongValue()1953 xs_long getLongValue() const { return static_cast<xs_long>(theValue); } 1954 getIntValue()1955 xs_int getIntValue() const { return static_cast<xs_int>(theValue); } 1956 getShortValue()1957 xs_short getShortValue() const { return static_cast<xs_short>(theValue); } 1958 getByteValue()1959 xs_byte getByteValue() const { return theValue; } 1960 getTypeCode()1961 store::SchemaTypeCode getTypeCode() const { return store::XS_BYTE; } 1962 1963 store::Item* getType() const; 1964 1965 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 1966 { 1967 return theValue; 1968 } 1969 1970 bool equals( 1971 const store::Item* other, 1972 long timezone = 0, 1973 const XQPCollator* collation = 0 ) const 1974 { 1975 try 1976 { 1977 return theValue == other->getLongValue(); 1978 } catch(ZorbaException const &)1979 catch (ZorbaException const&) 1980 { 1981 return getDecimalValue() == other->getDecimalValue(); 1982 } 1983 } 1984 1985 long compare( 1986 const Item* other, 1987 long timezone = 0, 1988 const XQPCollator* collation = 0) const 1989 { 1990 try 1991 { 1992 return (theValue < other->getLongValue() ? 1993 -1 : 1994 (theValue == other->getLongValue() ? 0 : 1)); 1995 } catch(ZorbaException const &)1996 catch (ZorbaException const&) 1997 { 1998 return getDecimalValue().compare(other->getDecimalValue()); 1999 } 2000 } 2001 2002 bool getEBV() const; 2003 2004 zstring getStringValue() const; 2005 2006 void getStringValue2(zstring& val) const; 2007 2008 void appendStringValue(zstring& buf) const; 2009 isNaN()2010 bool isNaN() const { return false; } 2011 2012 zstring show() const; 2013 }; 2014 2015 2016 /******************************************************************************* 2017 class UnsignedLongItem 2018 ********************************************************************************/ 2019 class UnsignedLongItem : public AtomicItem 2020 { 2021 friend class BasicItemFactory; 2022 friend class AtomicItem; 2023 2024 protected: 2025 xs_unsignedLong theValue; 2026 2027 protected: UnsignedLongItem(xs_unsignedLong aValue)2028 UnsignedLongItem(xs_unsignedLong aValue) : theValue(aValue) {} 2029 UnsignedLongItem()2030 UnsignedLongItem() {} 2031 2032 public: isNaN()2033 bool isNaN() const { return false; } 2034 2035 xs_decimal getDecimalValue() const; 2036 2037 xs_integer getIntegerValue() const; 2038 2039 xs_nonNegativeInteger getUnsignedIntegerValue() const; 2040 getUnsignedLongValue()2041 xs_unsignedLong getUnsignedLongValue() const { return theValue; } 2042 getTypeCode()2043 store::SchemaTypeCode getTypeCode() const { return store::XS_UNSIGNED_LONG; } 2044 2045 store::Item* getType() const; 2046 2047 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 2048 { 2049 return static_cast<uint32_t>(theValue); 2050 } 2051 2052 bool equals( 2053 const store::Item* other, 2054 long timezone = 0, 2055 const XQPCollator* collation = 0 ) const 2056 { 2057 try 2058 { 2059 return theValue == other->getUnsignedLongValue(); 2060 } catch(ZorbaException const &)2061 catch (ZorbaException const&) 2062 { 2063 return getDecimalValue() == other->getDecimalValue(); 2064 } 2065 } 2066 2067 long compare( 2068 const Item* other, 2069 long timezone = 0, 2070 const XQPCollator* collation = 0) const 2071 { 2072 try 2073 { 2074 return (theValue < other->getUnsignedLongValue() ? 2075 -1 : 2076 (theValue == other->getUnsignedLongValue() ? 0 : 1)); 2077 } catch(ZorbaException const &)2078 catch (ZorbaException const&) 2079 { 2080 return getDecimalValue().compare(other->getDecimalValue()); 2081 } 2082 } 2083 2084 bool getEBV() const; 2085 2086 zstring getStringValue() const; 2087 2088 void getStringValue2(zstring& val) const; 2089 2090 void appendStringValue(zstring& buf) const; 2091 2092 zstring show() const; 2093 }; 2094 2095 2096 /******************************************************************************* 2097 class UnsignedIntItem 2098 ********************************************************************************/ 2099 class UnsignedIntItem : public AtomicItem 2100 { 2101 friend class BasicItemFactory; 2102 friend class AtomicItem; 2103 2104 protected: 2105 xs_unsignedInt theValue; 2106 2107 protected: UnsignedIntItem(xs_unsignedInt aValue)2108 UnsignedIntItem(xs_unsignedInt aValue) : theValue(aValue) {} 2109 UnsignedIntItem()2110 UnsignedIntItem() {} 2111 2112 public: isNaN()2113 bool isNaN() const { return false; } 2114 2115 xs_decimal getDecimalValue() const; 2116 2117 xs_integer getIntegerValue() const; 2118 2119 xs_nonNegativeInteger getUnsignedIntegerValue() const; 2120 getLongValue()2121 xs_long getLongValue() const { return static_cast<xs_long>(theValue); } 2122 getUnsignedLongValue()2123 xs_unsignedLong getUnsignedLongValue() const { return static_cast<xs_unsignedLong>(theValue); } 2124 getUnsignedIntValue()2125 xs_unsignedInt getUnsignedIntValue() const { return theValue; } 2126 getTypeCode()2127 store::SchemaTypeCode getTypeCode() const { return store::XS_UNSIGNED_INT; } 2128 2129 store::Item* getType() const; 2130 2131 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 2132 { 2133 return theValue; 2134 } 2135 2136 bool equals( 2137 const store::Item* other, 2138 long timezone = 0, 2139 const XQPCollator* collation = 0 ) const 2140 { 2141 try 2142 { 2143 return theValue == other->getUnsignedLongValue(); 2144 } catch(ZorbaException const &)2145 catch (ZorbaException const&) 2146 { 2147 try 2148 { 2149 return getLongValue() == other->getLongValue(); 2150 } 2151 catch (ZorbaException const&) 2152 { 2153 return getDecimalValue() == other->getDecimalValue(); 2154 } 2155 } 2156 } 2157 2158 long compare( 2159 const Item* other, 2160 long timezone = 0, 2161 const XQPCollator* collation = 0) const 2162 { 2163 try 2164 { 2165 return (theValue < other->getUnsignedLongValue() ? 2166 -1 : 2167 (theValue == other->getUnsignedLongValue() ? 0 : 1)); 2168 } catch(ZorbaException const &)2169 catch (ZorbaException const&) 2170 { 2171 return getDecimalValue().compare(other->getDecimalValue()); 2172 } 2173 } 2174 2175 bool getEBV() const; 2176 2177 zstring getStringValue() const; 2178 2179 void getStringValue2(zstring& val) const; 2180 2181 void appendStringValue(zstring& buf) const; 2182 2183 zstring show() const; 2184 }; 2185 2186 2187 /******************************************************************************* 2188 class UnsignedShortItem 2189 ********************************************************************************/ 2190 class UnsignedShortItem : public AtomicItem 2191 { 2192 friend class BasicItemFactory; 2193 friend class AtomicItem; 2194 2195 protected: 2196 xs_unsignedShort theValue; 2197 2198 protected: UnsignedShortItem(xs_unsignedShort aValue)2199 UnsignedShortItem(xs_unsignedShort aValue) : theValue(aValue) {} 2200 UnsignedShortItem()2201 UnsignedShortItem() {} 2202 2203 public: 2204 xs_decimal getDecimalValue() const; 2205 2206 xs_integer getIntegerValue() const; 2207 2208 xs_nonNegativeInteger getUnsignedIntegerValue() const; 2209 getLongValue()2210 xs_long getLongValue() const { return static_cast<xs_long>(theValue); } 2211 getUnsignedLongValue()2212 xs_unsignedLong getUnsignedLongValue() const { return static_cast<xs_unsignedLong>(theValue); } 2213 getUnsignedIntValue()2214 xs_unsignedInt getUnsignedIntValue() const { return static_cast<xs_unsignedInt>(theValue); } 2215 getUnsignedShortValue()2216 xs_unsignedShort getUnsignedShortValue() const { return theValue; } 2217 isNaN()2218 bool isNaN() const { return false; } 2219 getTypeCode()2220 store::SchemaTypeCode getTypeCode() const { return store::XS_UNSIGNED_SHORT; } 2221 2222 store::Item* getType() const; 2223 2224 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 2225 { 2226 return static_cast<uint32_t>(theValue); 2227 } 2228 2229 bool equals( 2230 const store::Item* other, 2231 long timezone = 0, 2232 const XQPCollator* aCollation = 0 ) const 2233 { 2234 try 2235 { 2236 return theValue == other->getUnsignedLongValue(); 2237 } catch(ZorbaException const &)2238 catch (ZorbaException const&) 2239 { 2240 try 2241 { 2242 return getLongValue() == other->getLongValue(); 2243 } 2244 catch (ZorbaException const&) 2245 { 2246 return getDecimalValue() == other->getDecimalValue(); 2247 } 2248 } 2249 } 2250 2251 long compare( 2252 const Item* other, 2253 long timezone = 0, 2254 const XQPCollator* collation = 0) const 2255 { 2256 try 2257 { 2258 return (theValue < other->getUnsignedLongValue() ? 2259 -1 : 2260 (theValue == other->getUnsignedLongValue() ? 0 : 1)); 2261 } catch(ZorbaException const &)2262 catch (ZorbaException const&) 2263 { 2264 return getDecimalValue().compare(other->getDecimalValue()); 2265 } 2266 } 2267 2268 bool getEBV() const; 2269 2270 zstring getStringValue() const; 2271 2272 void getStringValue2(zstring& val) const; 2273 2274 void appendStringValue(zstring& buf) const; 2275 2276 zstring show() const; 2277 }; 2278 2279 2280 /******************************************************************************* 2281 class UnsignedByteItem 2282 ********************************************************************************/ 2283 class UnsignedByteItem : public AtomicItem 2284 { 2285 friend class BasicItemFactory; 2286 friend class AtomicItem; 2287 2288 protected: 2289 xs_unsignedByte theValue; 2290 2291 protected: UnsignedByteItem(xs_unsignedByte aValue)2292 UnsignedByteItem(xs_unsignedByte aValue) : theValue(aValue) {} 2293 UnsignedByteItem()2294 UnsignedByteItem() : theValue(0) {} 2295 2296 public: 2297 xs_decimal getDecimalValue() const; 2298 2299 xs_integer getIntegerValue() const; 2300 2301 xs_nonNegativeInteger getUnsignedIntegerValue() const; 2302 getLongValue()2303 xs_long getLongValue() const { return static_cast<xs_long>(theValue); } 2304 getUnsignedLongValue()2305 xs_unsignedLong getUnsignedLongValue() const { return static_cast<xs_unsignedLong>(theValue); } 2306 getUnsignedIntValue()2307 xs_unsignedInt getUnsignedIntValue() const { return static_cast<xs_unsignedInt>(theValue); } 2308 getUnsignedShortValue()2309 xs_unsignedShort getUnsignedShortValue() const { return static_cast<xs_unsignedShort>(theValue); } 2310 getUnsignedByteValue()2311 xs_unsignedByte getUnsignedByteValue() const { return theValue; } 2312 isNaN()2313 bool isNaN() const { return false; } 2314 getTypeCode()2315 store::SchemaTypeCode getTypeCode() const { return store::XS_UNSIGNED_BYTE; } 2316 2317 store::Item* getType() const; 2318 2319 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const 2320 { 2321 return static_cast<uint32_t>(theValue); 2322 } 2323 2324 bool equals( 2325 const store::Item* other, 2326 long timezone = 0, 2327 const XQPCollator* aCollation = 0 ) const 2328 { 2329 try 2330 { 2331 return theValue == other->getUnsignedLongValue(); 2332 } catch(ZorbaException const &)2333 catch (ZorbaException const&) 2334 { 2335 try 2336 { 2337 return getLongValue() == other->getLongValue(); 2338 } 2339 catch (ZorbaException const&) 2340 { 2341 return getDecimalValue() == other->getDecimalValue(); 2342 } 2343 } 2344 } 2345 2346 long compare( 2347 const Item* other, 2348 long timezone = 0, 2349 const XQPCollator* aCollation = 0) const 2350 { 2351 try 2352 { 2353 return (theValue < other->getUnsignedLongValue() ? 2354 -1 : 2355 (theValue == other->getUnsignedLongValue() ? 0 : 1)); 2356 } catch(ZorbaException const &)2357 catch (ZorbaException const&) 2358 { 2359 return getDecimalValue().compare(other->getDecimalValue()); 2360 } 2361 } 2362 2363 bool getEBV() const; 2364 2365 zstring getStringValue() const; 2366 2367 void getStringValue2(zstring& val) const; 2368 2369 void appendStringValue(zstring& buf) const; 2370 2371 zstring show() const; 2372 }; 2373 2374 2375 /******************************************************************************* 2376 class BooleanItem 2377 ********************************************************************************/ 2378 class BooleanItem : public AtomicItem 2379 { 2380 friend class BasicItemFactory; 2381 2382 protected: 2383 xs_boolean theValue; 2384 2385 protected: BooleanItem(xs_boolean aValue)2386 BooleanItem(xs_boolean aValue) : theValue(aValue) {} 2387 BooleanItem()2388 BooleanItem() {} 2389 2390 public: getBooleanValue()2391 xs_boolean getBooleanValue() const { return theValue; } 2392 getTypeCode()2393 store::SchemaTypeCode getTypeCode() const { return store::XS_BOOLEAN; } 2394 2395 store::Item* getType() const; 2396 2397 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 2398 2399 bool equals( 2400 const store::Item* other, 2401 long timezone = 0, 2402 const XQPCollator* aCollation = 0) const 2403 { 2404 return other->getBooleanValue() == theValue; 2405 } 2406 2407 long compare( 2408 const Item* other, 2409 long timezone = 0, 2410 const XQPCollator* aCollation = 0) const 2411 { 2412 return (theValue == other->getBooleanValue() ? 2413 0 : 2414 (theValue == false ? -1 : 1)); 2415 } 2416 2417 bool getEBV() const; 2418 2419 zstring getStringValue() const; 2420 2421 void getStringValue2(zstring& val) const; 2422 2423 void appendStringValue(zstring& buf) const; 2424 2425 zstring show() const; 2426 }; 2427 2428 2429 /******************************************************************************* 2430 class Base64BinaryItem 2431 ********************************************************************************/ 2432 class Base64BinaryItem : public AtomicItem 2433 { 2434 friend class BasicItemFactory; 2435 2436 protected: 2437 std::vector<char> theValue; 2438 bool theIsEncoded; 2439 2440 protected: Base64BinaryItem(bool aIsEncoded)2441 Base64BinaryItem(bool aIsEncoded) 2442 : theIsEncoded(aIsEncoded) {} 2443 2444 Base64BinaryItem(const char* aValue, size_t aSize, bool aIsEncoded = true) theIsEncoded(aIsEncoded)2445 : theIsEncoded(aIsEncoded) 2446 { 2447 theValue.reserve(aSize); 2448 theValue.insert(theValue.begin(), aValue, aValue + aSize); 2449 } 2450 2451 public: 2452 const char* getBase64BinaryValue(size_t& data) const; 2453 getTypeCode()2454 store::SchemaTypeCode getTypeCode() const { return store::XS_BASE64BINARY; } 2455 2456 store::Item* getType() const; 2457 isEncoded()2458 bool isEncoded() const { return theIsEncoded; } 2459 2460 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 2461 2462 bool equals( 2463 const store::Item* other, 2464 long timezone = 0, 2465 const XQPCollator* aCollation = 0 ) const; 2466 2467 zstring getStringValue() const; 2468 2469 void getStringValue2(zstring& val) const; 2470 2471 void appendStringValue(zstring& buf) const; 2472 2473 zstring show() const; 2474 2475 protected: 2476 // used in hash doing simple xor of the data 2477 struct hash_functor 2478 { 2479 uint32_t hash_value; 2480 operatorhash_functor2481 void operator() (char c) 2482 { 2483 hash_value ^= (uint32_t) c; 2484 } 2485 }; 2486 }; 2487 2488 2489 /******************************************************************************* 2490 class StreamableBase64BinaryItem 2491 ********************************************************************************/ 2492 class StreamableBase64BinaryItem : public Base64BinaryItem 2493 { 2494 friend class BasicItemFactory; 2495 2496 protected: 2497 std::istream & theIstream; 2498 2499 bool theIsMaterialized; 2500 bool theIsConsumed; 2501 bool theIsSeekable; 2502 2503 StreamReleaser theStreamReleaser; 2504 2505 protected: 2506 StreamableBase64BinaryItem( 2507 std::istream& aStream, 2508 StreamReleaser streamReleaser, 2509 bool seekable = false, 2510 bool is_encoded = false) Base64BinaryItem(is_encoded)2511 : Base64BinaryItem(is_encoded), 2512 theIstream(aStream), 2513 theIsMaterialized(false), 2514 theIsConsumed(false), 2515 theIsSeekable(seekable), 2516 theStreamReleaser(streamReleaser) 2517 {} 2518 2519 void materialize() const; 2520 2521 public: ~StreamableBase64BinaryItem()2522 virtual ~StreamableBase64BinaryItem() 2523 { 2524 if (theStreamReleaser) 2525 { 2526 theStreamReleaser(&theIstream); 2527 } 2528 } 2529 2530 bool isStreamable() const; 2531 2532 bool isSeekable() const; 2533 2534 std::istream& getStream(); 2535 2536 StreamReleaser getStreamReleaser(); 2537 2538 void setStreamReleaser(StreamReleaser aReleaser); 2539 2540 const char* getBase64BinaryValue(size_t&) const; 2541 getTypeCode()2542 store::SchemaTypeCode getTypeCode() const { return store::XS_BASE64BINARY; } 2543 2544 uint32_t hash(long timezone = 0, const XQPCollator* aCollation = 0) const; 2545 2546 zstring getStringValue() const; 2547 2548 void getStringValue2(zstring& val) const; 2549 2550 void appendStringValue(zstring& buf) const; 2551 2552 zstring show() const; 2553 }; 2554 2555 2556 /******************************************************************************* 2557 class HexBinaryItem 2558 ********************************************************************************/ 2559 class HexBinaryItem : public AtomicItem 2560 { 2561 friend class BasicItemFactory; 2562 2563 protected: 2564 xs_hexBinary theValue; 2565 2566 protected: HexBinaryItem(xs_hexBinary value)2567 HexBinaryItem(xs_hexBinary value) : theValue(value) {} 2568 HexBinaryItem()2569 HexBinaryItem() {} 2570 2571 public: getHexBinaryValue()2572 xs_hexBinary getHexBinaryValue() const { return theValue; } 2573 getTypeCode()2574 store::SchemaTypeCode getTypeCode() const { return store::XS_HEXBINARY; } 2575 2576 store::Item* getType() const; 2577 2578 uint32_t hash(long timezone = 0, const XQPCollator* coll = 0) const; 2579 2580 bool equals(const store::Item* other, long tz = 0, const XQPCollator* coll = 0) const 2581 { 2582 return theValue.equal(other->getHexBinaryValue()); 2583 } 2584 2585 zstring getStringValue() const; 2586 2587 void getStringValue2(zstring& val) const; 2588 2589 void appendStringValue(zstring& buf) const; 2590 2591 zstring show() const; 2592 }; 2593 2594 2595 /******************************************************************************* 2596 class ErrorItem 2597 2598 An ErrorItem obj stores a pointer to a ZorbaError obj. The ZorbaError obj is 2599 not created by the store, but once a pointer to it is set inside an ErrorItem 2600 obj, the ErrorItem obj assumes ownership of the ZorbaError. The getError() 2601 method returns the zorbaError pointer, but if the caller needs to access the 2602 ZobaError obj beyond the lifetime of the ErrorItem, they must make a deep 2603 copy of it. 2604 2605 This design is due to the fact that ZorbaError class is visible to the store 2606 lib, but subclasses of ZorbaError (like ZorbaUserError) may not be visible, 2607 so ErrorItem cannot do much with an error obj other than storing a pointer 2608 to it (and calling the virtual free() method on that pointer when the 2609 ErrorItem gets destroyed). 2610 ********************************************************************************/ 2611 class ErrorItem : public AtomicItem 2612 { 2613 friend class BasicItemFactory; 2614 2615 protected: 2616 ZorbaException * theError; 2617 2618 protected: ErrorItem(ZorbaException * error)2619 ErrorItem(ZorbaException* error) : theError(error) 2620 { 2621 theUnion.itemKind = ERROR_; 2622 } 2623 2624 public: 2625 virtual ~ErrorItem(); 2626 getError()2627 ZorbaException* getError() const { return theError; } 2628 2629 zstring show() const; 2630 2631 protected: 2632 // Disable copy 2633 ErrorItem(const ErrorItem& other); 2634 ErrorItem& operator=(const ErrorItem& other); 2635 }; 2636 2637 2638 #ifndef ZORBA_NO_FULL_TEXT 2639 /** 2640 * An %AtomicItemTokenizerCallback is-a Tokenizer::Callback for tokenizing 2641 * atomic items. 2642 */ 2643 class AtomicItemTokenizerCallback : public Tokenizer::Callback 2644 { 2645 public: 2646 typedef FTTokenStore::container_type container_type; 2647 2648 AtomicItemTokenizerCallback( container_type &tokens ); 2649 2650 // inherited 2651 void token( char const *utf8_s, size_type utf8_len, locale::iso639_1::type, 2652 size_type token_no, size_type sent_no, size_type para_no, 2653 Item const* ); 2654 2655 private: 2656 container_type &tokens_; 2657 }; 2658 #endif /* ZORBA_NO_FULL_TEXT */ 2659 2660 2661 } // namespace simplestore 2662 } // namespace zorba 2663 #endif /* ZORBA_STORE_ATOMIC_ITEMS_H */ 2664 2665 /* 2666 * Local variables: 2667 * mode: c++ 2668 * End: 2669 */ 2670 /* vim:set et sw=2 ts=2: */ 2671