Changeset d919cd in git


Ignore:
Timestamp:
Sep 2, 2012, 4:55:06 PM (10 years ago)
Author:
Alexander Dreyer <alexander.dreyer@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'ad2543eab51733612ba7d118afc77edca719600e')
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
Message:
new added some comments to developer's documentation, and documented system commands
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/countedref.cc

    r9373f0 rd919cd  
    259259
    260260public:
     261  struct copy_tag {};
    261262  LeftvDeep(): m_data(allocate()) {}
    262263  LeftvDeep(leftv data): m_data(cpy(data)) {
     
    265266  }
    266267
    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);  }
    268269
    269270  ~LeftvDeep() { m_data->CleanUp(); }
     
    346347  public RefCounter {
    347348  typedef CountedRefData self;
     349  typedef CountedRefPtr<self*, false, true> self_ptr;
    348350  typedef RefCounter base;
    349351
    350   /// Subscripted object
    351   CountedRefData(leftv wrapped, CountedRefPtr<self*> back):
     352  /// Generate object linked to other reference (e.g. for subscripts)
     353  CountedRefData(leftv wrapped, self_ptr back):
    352354    base(), m_data(wrapped), m_ring(back->m_ring), m_back(back) {  }
    353355
    354   /// Disallow copying to avoid inconsistence
     356  /// @name  isallow copying to avoid inconsistence
    355357  //@{
    356358  self& operator=(const self&);
     
    358360  //@}
    359361public:
     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
    360370  /// Construct shared memory empty Singular object
    361371  explicit CountedRefData():
    362372    base(), m_data(), m_ring(), m_back() { }
    363373
    364   /// Construct reference for Singular object
     374  /// Reference Singular object
    365375  explicit CountedRefData(leftv data):
    366376    base(), m_data(data), m_ring(parent(data)), m_back() { }
    367377
    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() { }
    370381
    371382  /// Destruct
     
    373384
    374385  /// Generate
    375   CountedRefPtr<self*> subscripted() {
     386  ptr_type subscripted() {
    376387    return new self(m_data.idify(root()),
    377                     m_back? m_back: CountedRefPtr<self*>(this));
     388                    m_back? m_back: ptr_type(this));
    378389  }
    379390
     
    447458
    448459  /// Store namespace for ring-dependent objects
    449   CountedRefPtr<ring, true> m_ring;
     460  ring_ptr m_ring;
    450461
    451462  /// Reference to actual object for indexed structures 
    452   CountedRefPtr<self*> m_back;
     463  ptr_type m_back;
    453464};
    454465
     
    472483  typedef int id_type;
    473484
    474   /// Name type for handling reference data
     485  /// Name type for handling referenced data
    475486  typedef CountedRefData data_type;
     487
     488  /// Fix smart pointer type to referenced data
     489  typedef data_type::ptr_type data_ptr;
    476490
    477491  /// Check whether argument is already a reference type
     
    483497  }
    484498
    485   /// Construct new reference from Singular data 
     499  /// Reference given Singular data 
    486500  explicit CountedRef(leftv arg):  m_data(new data_type(arg)) { }
    487501
    488502protected:
    489503  /// Recover previously constructed reference
    490   CountedRef(data_type* arg):  m_data(arg) { assume(arg); }
     504  CountedRef(data_ptr arg):  m_data(arg) { assume(arg); }
    491505
    492506public:
     
    503517    return m_data->assign(result,arg);
    504518  }
    505   BOOLEAN rering() { return m_data->rering(); }
    506519
    507520  /// Extract (shallow) copy of stored data
     
    514527  }
    515528
    516   /// Construct reference data object from
     529  /// Construct reference data object from *this
    517530  BOOLEAN outcast(leftv res) {
    518531    if (res->rtyp == IDHDL)
     
    522535    return FALSE;
    523536  }
     537
     538  /// Construct raw reference data
    524539  data_type* outcast() {
    525540    m_data.reclaim();
     
    541556  }
    542557
     558  /// Check whether object in valid in current context
    543559  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(); }
    544563
    545564  /// Get number of references pointing here, too
     
    547566
    548567  // 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); }
    550569
    551570  /// Check for likewise identifiers
     
    567586  BOOLEAN name(leftv res) { return construct(res, operator*()->Name()); }
    568587
    569   /// Check whther argument is not defined yet
    570   BOOLEAN undefined(leftv res) { return construct(res, operator*()->Typ() == NONE); }
    571   BOOLEAN unassigned() const { return  m_data->unassigned(); }
    572588  /// Recover the actual object from raw Singular data
    573589  static self cast(void* data) {
     
    589605  }
    590606
    591 protected:
    592607  /// Construct integer value
    593608  static BOOLEAN construct(leftv res, long data) {
     
    603618    return FALSE;
    604619  }
    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
     628protected:
    606629  /// Store pointer to actual data
    607   CountedRefPtr<data_type*> m_data;
     630  data_ptr m_data;
    608631};
    609632
     
    712735  typedef CountedRef base;
    713736
     737  /// Reinterprete @c CountedRef as @c CountedRefShared
    714738  CountedRefShared(const base& rhs):  base(rhs) { }
    715   CountedRefShared(data_type* rhs):  base(rhs) { }
     739
     740  /// Genreate   
     741  CountedRefShared(data_ptr rhs):  base(rhs) { }
    716742
    717743public:
     744  /// Default constructor for initialized, but all-zero, shared data object
    718745  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
    722751  CountedRefShared(const self& rhs): base(rhs) { }
    723752
     753  /// Desctruct
    724754  ~CountedRefShared() { }
    725755
     756  /// Change reference to shared data
    726757  self& operator=(const self& rhs) {
    727758    return static_cast<self&>(base::operator=(rhs));
    728759  }
    729760
     761  /// Recovering outcasted @c CountedRefShared object from interpreter object
    730762  static self cast(leftv arg) { return base::cast(arg); }
     763
     764  /// Recovering outcasted @c CountedRefShared object from raw data
    731765  static self cast(void* arg) { return base::cast(arg); }
    732766
     
    739773};
    740774
     775/// Blackbox support - generate initialized, but all-zero - shared data
    741776void* countedref_InitShared(blackbox*)
    742777{
     
    768803      leftv next = args->next;
    769804      args->next = NULL;
    770       CountedRef obj = CountedRef::cast(args);
     805
    771806      char* name = (next->Typ() == STRING_CMD?
    772807                    (char*) next->Data(): (char*)next->Name());
    773808      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);
    774826      if (next) {
    775827        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); 
    777830      }
    778831      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);
    783835    }
    784836    return TRUE;
Note: See TracChangeset for help on using the changeset viewer.