Back to home page

Enduro/X

 
 

    


0001 /*  see copyright notice in pscript.h */
0002 #ifndef _PSUSERDATA_H_
0003 #define _PSUSERDATA_H_
0004 
0005 struct PSUserData : PSDelegable
0006 {
0007     PSUserData(PSSharedState *ss){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); }
0008     ~PSUserData()
0009     {
0010         REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this);
0011         SetDelegate(NULL);
0012     }
0013     static PSUserData* Create(PSSharedState *ss, PSInteger size)
0014     {
0015         PSUserData* ud = (PSUserData*)PS_MALLOC(ps_aligning(sizeof(PSUserData))+size);
0016         new (ud) PSUserData(ss);
0017         ud->_size = size;
0018         ud->_typetag = 0;
0019         return ud;
0020     }
0021 #ifndef NO_GARBAGE_COLLECTOR
0022     void Mark(PSCollectable **chain);
0023     void Finalize(){SetDelegate(NULL);}
0024     PSObjectType GetType(){ return OT_USERDATA;}
0025 #endif
0026     void Release() {
0027         if (_hook) _hook((PSUserPointer)ps_aligning(this + 1),_size);
0028         PSInteger tsize = _size;
0029         this->~PSUserData();
0030         PS_FREE(this, ps_aligning(sizeof(PSUserData)) + tsize);
0031     }
0032 
0033 
0034     PSInteger _size;
0035     PSRELEASEHOOK _hook;
0036     PSUserPointer _typetag;
0037     //PSChar _val[1];

0038 };
0039 
0040 #endif //_PSUSERDATA_H_