Changeset a5e907 in git


Ignore:
Timestamp:
Aug 30, 2012, 11:20:14 PM (10 years ago)
Author:
Alexander Dreyer <alexander.dreyer@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '2234726c50d679d6664181a5c72f75a6fd64a787')
Children:
b8346741b9c72d735f018ce57120e6782a5d4d2d
Parents:
f8852177b833def200699ea2f50f0328ff40ce94
git-author:
Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-30 23:20:14+02:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-09-05 15:52:16+02:00
Message:
chg: simplified indexed type
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/countedref.cc

    rf88521 ra5e907  
    5656  //}
    5757
     58  /// Default constructor @note: exisis only if @c NeverNull is false
     59  CountedRefPtr(): m_ptr(NULL) {}
     60
    5861  /// Convert from pointer
    5962  CountedRefPtr(ptr_type ptr): m_ptr(ptr) { reclaim(); }
     
    107110};
    108111
     112/// Default constructor only implemented if @c NeverNull is false
     113//template <class PtrType, bool isWeak,bool val,class CountType>
     114//inline CountedRefPtr<PtrType, isWeak, val, CountType>::CountedRefPtr():
     115//  m_ptr(NULL) { }
    109116
    110117/** @class RefCounter
     
    163170    return g_sh_id;
    164171  }
    165   static int& idx_id() {
    166     static int g_sh_id = 0;
    167     return g_sh_id;
    168   }
    169 
    170172};
    171173
     
    298300  typedef RefCounter base;
    299301
     302  /// Subscripted object
     303  CountedRefData(idhdl handle, CountedRefPtr<self*> back):
     304    base(), m_data(init(handle)), m_ring(back->Ring()), m_back(back) { }
     305
    300306public:
     307  /// Construct shared memory empty Singular object
     308  explicit CountedRefData():
     309    base(), m_data(), m_ring(), m_back() { }
     310
    301311  /// Construct reference for Singular object
    302312  explicit CountedRefData(leftv data):
    303     base(), m_data(data), m_ring(parent(data)) { }
     313    base(), m_data(data), m_ring(parent(data)), m_back() { }
    304314
    305315  CountedRefData(leftv data, BOOLEAN global, int):
    306     base(), m_data(data, global,0), m_ring(parent(data)) { }
     316    base(), m_data(data, global,0), m_ring(parent(data)), m_back() { }
    307317
    308318  /// Construct deep copy
    309319  CountedRefData(const self& rhs):
    310     base(), m_data(rhs.m_data), m_ring(rhs.m_ring)  { }
     320    base(), m_data(rhs.m_data), m_ring(rhs.m_ring), m_back() { }
    311321 
    312322  /// Destruct
    313   ~CountedRefData()  { }
     323  ~CountedRefData() {
     324    if (m_back) CountedRefEnv::clearid((idhdl)m_data.access()->data, root());
     325   }
     326
     327  CountedRefPtr<self*> subscripted() {
     328    return new self(CountedRefEnv::idify(m_data.access(), root()), this);
     329  }
    314330
    315331  /// Replace data
     
    339355  BOOLEAN rering() {
    340356    if (m_ring ^ m_data->RingDependend()) m_ring = (m_ring? NULL: currRing);
    341     return FALSE;
     357    return (m_back && m_back->rering());
    342358  }
    343359
     
    362378
    363379  BOOLEAN assign(leftv result, leftv arg) {
     380    if (m_data->rtyp!=IDHDL) {
     381      set(arg);
     382      return FALSE;
     383    }
    364384    return get(result) || iiAssign(result, arg) || rering();
    365385  }
    366386
    367   /// @note Enables write-access via identifier
    368   idhdl idify() {  return CountedRefEnv::idify(m_data.access(), root());  }
    369 
    370   /// @note Only call, if @c idify had been called before!
    371   void clearid() {  CountedRefEnv::clearid((idhdl)m_data.access()->data, root());  }
     387  /// @note If we have a callback, our identifier was temporary, so remove it
     388  void clear() { 
     389    if (m_back) CountedRefEnv::clearid((idhdl)m_data.access()->data, root());
     390  }
    372391
    373392  BOOLEAN retrieve(leftv res) {
     
    400419    return (rhs->RingDependend()? currRing: NULL);
    401420  }
     421
     422 static leftv init(idhdl handle) {
     423    assume(handle);
     424    leftv res = (leftv)omAlloc0(sizeof(*res));
     425    res->data =(void*) handle;
     426    res->rtyp = IDHDL;
     427    return res;
     428  }
     429
    402430protected:
    403431  /// Singular object
     
    406434  /// Store namespace for ring-dependent objects
    407435  CountedRefPtr<ring, true> m_ring;
     436
     437  /// Reference to actual object for indexed structures 
     438  CountedRefPtr<self*> m_back;
    408439};
    409440
     
    432463  static BOOLEAN is_ref(leftv arg) {
    433464    int typ = arg->Typ();
    434     return ((typ==CountedRefEnv::ref_id())  ||(typ==CountedRefEnv::sh_id()) ||
    435             (typ==CountedRefEnv::idx_id()) );
     465    return ((typ==CountedRefEnv::ref_id())  ||(typ==CountedRefEnv::sh_id()) );
    436466    //    return ((typ > MAX_TOK) &&
    437467    //            (getBlackboxStuff(typ)->blackbox_Init == countedref_Init));
     
    464494    return m_data->assign(result,arg);
    465495  }
    466 
     496  BOOLEAN rering() { return m_data->rering(); }
    467497  /// Extract (shallow) copy of stored data
    468498  LeftvShallow operator*() { return m_data->operator*(); }
     499
     500  /// Construct reference data object marked by given identifier number
     501  BOOLEAN outcast(leftv res, int typ) {
     502    res->rtyp = typ;
     503    return outcast(res);
     504  }
    469505
    470506  /// Construct reference data object from
     
    644680}
    645681
    646 class CountedRefDataIndexed:
    647   public CountedRefData {
    648   typedef CountedRefData base;
    649   typedef CountedRefDataIndexed self;
    650 
    651 public:
    652   CountedRefDataIndexed(idhdl handle, CountedRefPtr<base*> back):
    653     base(init(handle)), m_back(back) {
    654     m_ring = back->Ring();
    655   }
    656 
    657   CountedRefDataIndexed(const self& rhs): base(rhs), m_back(rhs.m_back) { }
    658 
    659   ~CountedRefDataIndexed() { clearid();}
    660 
    661   BOOLEAN assign(leftv result, leftv arg) {
    662     return base::assign(result, arg) || m_back->rering();
    663   }
    664 
    665 private:
    666   static leftv init(idhdl handle) {
    667     assume(handle);
    668     leftv res = (leftv)omAlloc0(sizeof(*res));
    669     res->data =(void*) handle;
    670     res->rtyp = IDHDL;
    671     return res;
    672   }
    673 
    674   CountedRefPtr<CountedRefData*> m_back;
    675 };
    676 inline void CountedRefPtr_kill(CountedRefDataIndexed* data) { delete data; }
    677 
    678 
    679682
    680683/// blackbox support - ternary operations
     
    688691
    689692
    690 
    691693/// blackbox support - destruction
    692694void countedref_destroy(blackbox *b, void* ptr)
     
    695697}
    696698
    697 
    698 /// blackbox support - assign element
    699 BOOLEAN countedref_AssignIndexed(leftv result, leftv arg)
    700 {
    701   // Case: replace assignment behind reference
    702   if (result->Data() != NULL) {
    703     CountedRefPtr<CountedRefDataIndexed*> indexed =(CountedRefDataIndexed*)(result->Data());
    704     return CountedRef::resolve(arg) || indexed->assign(result, arg);
    705   }
    706  
    707   // Case: copy reference
    708   if (result->Typ() == arg->Typ())
    709     return CountedRef::cast(arg).outcast(result);
    710 
    711   Werror("Cannot generate subscripted shared from plain type. Use shared[i] or shared.attr");
    712   return TRUE;
    713 }
    714 
    715 
    716 /// blackbox support - destruction
    717 void countedref_destroyIndexed(blackbox *b, void* ptr)
    718 {
    719   if (ptr) {
    720     CountedRefPtr<CountedRefDataIndexed*> data =
    721     static_cast<CountedRefDataIndexed*>(ptr);
    722     data.release();
    723   }
    724 }
    725699
    726700class CountedRefShared:
     
    730704
    731705  CountedRefShared(const base& rhs):  base(rhs) { }
     706  CountedRefShared(data_type* rhs):  base(rhs) { }
    732707
    733708public:
     709  CountedRefShared():  base(new data_type) { }
    734710  CountedRefShared(leftv arg):  base(new data_type(arg, FALSE,0)) { }
    735711
     
    751727  static self cast(void* arg) { return base::cast(arg); }
    752728
    753   CountedRefPtr<CountedRefDataIndexed*> subscripted() {
    754     return new CountedRefDataIndexed(m_data->idify(), m_data);
     729  self subscripted() {
     730    return self(m_data->subscripted());//new CountedRefDataIndexed(m_data->idify(), m_data);
     731  }
     732
     733  BOOLEAN retrieve(leftv res, int typ) {
     734    return (m_data->retrieve(res) && outcast(res, typ));
    755735  }
    756736};
     
    758738void* countedref_InitShared(blackbox*)
    759739{
    760   LeftvDeep empty;
    761   return CountedRefShared(LeftvShallow(empty).operator->()).outcast();
     740  return CountedRefShared().outcast();
    762741}
    763742
     
    767746  if  ((op == '[') || (op == '.')) {
    768747    if (countedref_CheckInit(res, head))  return TRUE;
    769     CountedRefPtr<CountedRefDataIndexed*> indexed = CountedRefShared::cast(head).subscripted();
    770     if(indexed->operator*().get(head)) return TRUE;
    771  
    772     if (CountedRef::resolve(arg) || iiExprArith2(res, head, op, arg)) return
    773       TRUE;
    774 
    775     if(indexed->retrieve(res)) {
    776       indexed.reclaim();
    777       res->rtyp = CountedRefEnv::idx_id();
    778       res->data = (void *)indexed;
    779     }
    780     return FALSE;
     748    CountedRefShared indexed = CountedRefShared::cast(head).subscripted();
     749
     750    int typ = head->Typ();
     751    return indexed.dereference(head) || CountedRef::resolve(arg) ||
     752      iiExprArith2(res, head, op, arg) || indexed.retrieve(res, typ);
    781753  }
    782754
     
    810782  }
    811783  if (op == LIST_CMD){
    812     res->rtyp=op;
     784    res->rtyp = op;
    813785    return jjLIST_PL(res, args);
    814786  }
     
    823795  if ((result->Data() != NULL)  && (CountedRefShared::cast(result).Typ() !=0 )) {
    824796    if (CountedRefShared::resolve(arg)) return TRUE;
    825     CountedRefShared::cast(result) = arg;
     797    return CountedRefShared::cast(result).assign(result, arg);
    826798    return FALSE;
    827799  }
     
    834806  } 
    835807  if(CountedRefShared::cast(result).Typ() == 0) {
    836     CountedRefShared::cast(result) = arg;
     808   // CountedRefShared::cast(result) = arg;
     809   return CountedRefShared::cast(result).assign(result, arg);
     810
    837811    return FALSE;
    838812  }
     
    874848  bbxshared->data             = omAlloc0(newstruct_desc_size());
    875849  CountedRefEnv::sh_id()=setBlackboxStuff(bbxshared, "shared");
    876 
    877 
    878   blackbox *bbxindexed =
    879     (blackbox*)memcpy(omAlloc(sizeof(blackbox)), bbx, sizeof(blackbox));
    880   bbxindexed->blackbox_destroy = countedref_destroyIndexed;
    881   bbxindexed->blackbox_Assign = countedref_AssignIndexed;
    882   bbxindexed->data             = omAlloc0(newstruct_desc_size());
    883   CountedRefEnv::idx_id()=setBlackboxStuff(bbxindexed, "shared_subexpr");
    884 
    885850}
    886851
Note: See TracChangeset for help on using the changeset viewer.