Changeset d919cd in git for Singular/countedref.cc
- Timestamp:
- Sep 2, 2012, 4:55:06 PM (12 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- a010d6eaa276986ef854adc014c99f570301d549
- Parents:
- 9373f05657970e6e7e18aac67a18d1245fb6bb4e
- git-author:
- Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-09-02 16:55:06+02:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-09-05 15:52:17+02:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/countedref.cc
r9373f0 rd919cd 259 259 260 260 public: 261 struct copy_tag {}; 261 262 LeftvDeep(): m_data(allocate()) {} 262 263 LeftvDeep(leftv data): m_data(cpy(data)) { … … 265 266 } 266 267 267 LeftvDeep(leftv data, int,int): m_data(allocate()) { m_data->Copy(data); }268 LeftvDeep(leftv data, copy_tag): m_data(allocate()) { m_data->Copy(data); } 268 269 269 270 ~LeftvDeep() { m_data->CleanUp(); } … … 346 347 public RefCounter { 347 348 typedef CountedRefData self; 349 typedef CountedRefPtr<self*, false, true> self_ptr; 348 350 typedef RefCounter base; 349 351 350 /// Subscripted object351 CountedRefData(leftv wrapped, CountedRefPtr<self*>back):352 /// Generate object linked to other reference (e.g. for subscripts) 353 CountedRefData(leftv wrapped, self_ptr back): 352 354 base(), m_data(wrapped), m_ring(back->m_ring), m_back(back) { } 353 355 354 /// Disallow copying to avoid inconsistence356 /// @name isallow copying to avoid inconsistence 355 357 //@{ 356 358 self& operator=(const self&); … … 358 360 //@} 359 361 public: 362 typedef LeftvDeep::copy_tag copy_tag; 363 364 /// Fix smart pointer type to referenced data 365 typedef self_ptr ptr_type; 366 367 /// Fix smart pointer type to ring 368 typedef CountedRefPtr<ring, true> ring_ptr; 369 360 370 /// Construct shared memory empty Singular object 361 371 explicit CountedRefData(): 362 372 base(), m_data(), m_ring(), m_back() { } 363 373 364 /// Construct reference forSingular object374 /// Reference Singular object 365 375 explicit CountedRefData(leftv data): 366 376 base(), m_data(data), m_ring(parent(data)), m_back() { } 367 377 368 CountedRefData(leftv data, BOOLEAN global, int): 369 base(), m_data(data, global,0), m_ring(parent(data)), m_back() { } 378 /// Construct reference for Singular object 379 CountedRefData(leftv data, copy_tag do_copy): 380 base(), m_data(data, do_copy), m_ring(parent(data)), m_back() { } 370 381 371 382 /// Destruct … … 373 384 374 385 /// Generate 375 CountedRefPtr<self*>subscripted() {386 ptr_type subscripted() { 376 387 return new self(m_data.idify(root()), 377 m_back? m_back: CountedRefPtr<self*>(this));388 m_back? m_back: ptr_type(this)); 378 389 } 379 390 … … 447 458 448 459 /// Store namespace for ring-dependent objects 449 CountedRefPtr<ring, true>m_ring;460 ring_ptr m_ring; 450 461 451 462 /// Reference to actual object for indexed structures 452 CountedRefPtr<self*>m_back;463 ptr_type m_back; 453 464 }; 454 465 … … 472 483 typedef int id_type; 473 484 474 /// Name type for handling reference data485 /// Name type for handling referenced data 475 486 typedef CountedRefData data_type; 487 488 /// Fix smart pointer type to referenced data 489 typedef data_type::ptr_type data_ptr; 476 490 477 491 /// Check whether argument is already a reference type … … 483 497 } 484 498 485 /// Construct new reference fromSingular data499 /// Reference given Singular data 486 500 explicit CountedRef(leftv arg): m_data(new data_type(arg)) { } 487 501 488 502 protected: 489 503 /// Recover previously constructed reference 490 CountedRef(data_ type*arg): m_data(arg) { assume(arg); }504 CountedRef(data_ptr arg): m_data(arg) { assume(arg); } 491 505 492 506 public: … … 503 517 return m_data->assign(result,arg); 504 518 } 505 BOOLEAN rering() { return m_data->rering(); }506 519 507 520 /// Extract (shallow) copy of stored data … … 514 527 } 515 528 516 /// Construct reference data object from 529 /// Construct reference data object from *this 517 530 BOOLEAN outcast(leftv res) { 518 531 if (res->rtyp == IDHDL) … … 522 535 return FALSE; 523 536 } 537 538 /// Construct raw reference data 524 539 data_type* outcast() { 525 540 m_data.reclaim(); … … 541 556 } 542 557 558 /// Check whether object in valid in current context 543 559 BOOLEAN broken() {return m_data->broken(); } 560 561 /// Check whether (shared) data was initialized but not assigned yet. 562 BOOLEAN unassigned() const { return m_data->unassigned(); } 544 563 545 564 /// Get number of references pointing here, too … … 547 566 548 567 // Get internal indentifier 549 BOOLEAN hash(leftv res) { return construct(res, (long)(data_type*)m_data); }568 BOOLEAN enumerate(leftv res) { return construct(res, (long)(data_type*)m_data); } 550 569 551 570 /// Check for likewise identifiers … … 567 586 BOOLEAN name(leftv res) { return construct(res, operator*()->Name()); } 568 587 569 /// Check whther argument is not defined yet570 BOOLEAN undefined(leftv res) { return construct(res, operator*()->Typ() == NONE); }571 BOOLEAN unassigned() const { return m_data->unassigned(); }572 588 /// Recover the actual object from raw Singular data 573 589 static self cast(void* data) { … … 589 605 } 590 606 591 protected:592 607 /// Construct integer value 593 608 static BOOLEAN construct(leftv res, long data) { … … 603 618 return FALSE; 604 619 } 605 620 /// Construct void-style object 621 static BOOLEAN construct(leftv res) { 622 res->data = NULL; 623 res->rtyp = NONE; 624 return FALSE; 625 } 626 627 628 protected: 606 629 /// Store pointer to actual data 607 CountedRefPtr<data_type*>m_data;630 data_ptr m_data; 608 631 }; 609 632 … … 712 735 typedef CountedRef base; 713 736 737 /// Reinterprete @c CountedRef as @c CountedRefShared 714 738 CountedRefShared(const base& rhs): base(rhs) { } 715 CountedRefShared(data_type* rhs): base(rhs) { } 739 740 /// Genreate 741 CountedRefShared(data_ptr rhs): base(rhs) { } 716 742 717 743 public: 744 /// Default constructor for initialized, but all-zero, shared data object 718 745 CountedRefShared(): base(new data_type) { } 719 explicit CountedRefShared(leftv arg): base(new data_type(arg, FALSE,0)) { } 720 721 /// Construct copy 746 747 /// Construct internal copy of Singular interpreter object 748 explicit CountedRefShared(leftv arg): base(new data_type(arg, data_type::copy_tag())) { } 749 750 /// Construct new reference to internal data 722 751 CountedRefShared(const self& rhs): base(rhs) { } 723 752 753 /// Desctruct 724 754 ~CountedRefShared() { } 725 755 756 /// Change reference to shared data 726 757 self& operator=(const self& rhs) { 727 758 return static_cast<self&>(base::operator=(rhs)); 728 759 } 729 760 761 /// Recovering outcasted @c CountedRefShared object from interpreter object 730 762 static self cast(leftv arg) { return base::cast(arg); } 763 764 /// Recovering outcasted @c CountedRefShared object from raw data 731 765 static self cast(void* arg) { return base::cast(arg); } 732 766 … … 739 773 }; 740 774 775 /// Blackbox support - generate initialized, but all-zero - shared data 741 776 void* countedref_InitShared(blackbox*) 742 777 { … … 768 803 leftv next = args->next; 769 804 args->next = NULL; 770 CountedRef obj = CountedRef::cast(args); 805 771 806 char* name = (next->Typ() == STRING_CMD? 772 807 (char*) next->Data(): (char*)next->Name()); 773 808 next = next->next; 809 810 if (strcmp(name, "help") == 0) { 811 PrintS("system(<ref>, ...): extended functionality for reference/shared data <ref>\n"); 812 PrintS(" system(<ref>, count) - number of references pointing to <ref>\n"); 813 PrintS(" system(<ref>, enumerate) - unique number for identifying <ref>\n"); 814 PrintS(" system(<ref>, undefined) - checks whether <ref> had been assigned\n"); 815 PrintS(" system(<ref>, \"help\") - prints this information message\n"); 816 PrintS(" system(<ref>, \"typeof\") - actual type referenced by <ref>\n"); 817 PrintS(" system(<ref1>, same, <ref2>) - tests for identic reference objects\n"); 818 return CountedRef::construct(res); 819 } 820 if (strncmp(name, "undef", 5) == 0) { 821 return CountedRef::construct(res, args->Data()? 822 (CountedRef::cast(args).unassigned()? 1: 2): 0); 823 } 824 825 CountedRef obj = CountedRef::cast(args); 774 826 if (next) { 775 827 if (strcmp(name, "same") == 0) return obj.same(res, next); 776 if (strncmp(name, "like", 4) == 0) return obj.likewise(res, next); 828 // likewise may be hard to interprete, so we not not document it above 829 if (strncmp(name, "like", 4) == 0) return obj.likewise(res, next); 777 830 } 778 831 if (strncmp(name, "count", 5) == 0) return obj.count(res); 779 if (strcmp(name, "hash") == 0) return obj.hash(res); 780 if (strcmp(name, "name") == 0) return obj.name(res); 781 if (strncmp(name, "type", 4) == 0) return obj.type(res); 782 if (strncmp(name, "undef", 5) == 0) return obj.undefined(res); 832 if (strncmp(name, "enum", 4) == 0) return obj.enumerate(res); 833 if (strcmp(name, "name") == 0) return obj.name(res); // undecumented 834 if (strncmp(name, "typ", 3) == 0) return obj.type(res); 783 835 } 784 836 return TRUE;
Note: See TracChangeset
for help on using the changeset viewer.