20 #ifndef SINGULAR_COUNTEDREF_H_ 21 #define SINGULAR_COUNTEDREF_H_ 41 template <
class PtrType,
bool Nondestructive =
false,
bool NeverNull =
false,
42 class CountType =
short>
86 operator bool()
const {
return NeverNull ||
m_ptr; }
95 count_type
count()
const {
return (*
this?
m_ptr->ref: 0); }
133 template <
class PtrType>
136 template <
class PtrType>
150 template <
class PtrType>
153 template <
class PtrType>
193 m_indirect->
m_ptr = ptr;
197 return m_indirect &&(m_indirect->m_ptr == ptr);
200 const ptr_type
operator->()
const {
return (m_indirect? m_indirect->m_ptr:
NULL); }
216 idhdl handle = newid(head, root);
218 res->
data =(
void*) handle;
227 sprintf(name,
" :%u:%p:_shared_: ", ++counter, head->
data);
228 if ((*root) ==
NULL )
243 template <
class Type>
245 return (Type*)memcpy(result, data,
sizeof(Type));
247 template <
class Type>
248 static Type*
cpy(Type* data) {
249 return cpy((Type*)
omAlloc0(
sizeof(Type)), data);
251 template <
class Type>
253 if (data ==
NULL)
return data;
255 result->next = recursivecpy(data->next);
258 template <
class Type>
260 cpy(result, data)->e = recursivecpy(data->e);
263 template <
class Type>
265 return shallowcpy((Type*)
omAlloc0(
sizeof(Type)), data);
267 template <
class Type>
269 if(current ==
NULL)
return;
270 recursivekill(current->next);
298 recursivekill(m_data->e);
304 recursivekill(m_data->e);
305 shallowcpy(m_data, rhs);
341 LeftvDeep(
const self&);
352 if(!isid()) m_data->data=data->
CopyD();
370 bool like(
const self& rhs)
const {
return m_data->data == rhs.m_data->data; }
391 return (context ==
NULL) ||
401 shallowcpy(result, m_data);
407 result->
flag = ((
idhdl)m_data->data)->flag;
415 if (res->
data == m_data->data) {
416 if(m_data->e != res->
e) recursivekill(m_data->e);
444 if (--((
idhdl)m_data->data)->ref <= 0)
CountedRefPtr()
Default constructor.
BOOLEAN unassigned() const
Check whether (all-zero) initialized data was never assigned.
void invalidate()
Mark weak reference as invalid.
void CountedRefPtr_kill(CountedRefIndirectPtr< PtrType > *pval)
Class used for (list of) interpreter objects.
bool operator==(const self &rhs) const
Checking equality.
leftv m_data
The actual data pointer.
count_type ref
Number of references.
CountedRefPtr(const CountedRefPtr< ptr_type, !nondestructive, Never, count_type > &rhs)
Convert from compatible smart pointer.
RefCounter(...)
Any Constructor resets the counter.
CountedRefIndirectPtr & operator=(PtrType ptr)
static Type * shallowcpy(Type *result, Type *data)
leftv operator->()
The actual data pointer.
const ptr_type operator->() const
Pointer-style interface.
LeftvDeep(leftv data)
Store a deep copy of the data @ note Occupies the provided leftv and invalidates the latter...
static Type * shallowcpy(Type *data)
CountedRefPtr(const self &rhs)
Construct refernce copy.
ptr_type m_ptr
Store actual pointer.
CountedRefWeakPtr(ptr_type ptr)
Convert from pointer.
LeftvDeep()
Allocate all-zero object by default.
self & operator=(ptr_type ptr)
Pointer-style interface.
static Type * cpy(Type *data)
void countedref_reference_load()
Initialize blackbox types 'reference' and 'shared', or both.
CountedRefWeakPtr(const self &rhs)
Construct copy.
void countedref_shared_load()
bool operator==(ptr_type ptr) const
Pointer-style interface.
LeftvShallow()
Just allocate (all-zero) leftv.
bool like(const self &rhs) const
Determine whether we point to the same data.
This class implements implements a refernce counter which we can use as a public base of objects mana...
void killhdl2(idhdl h, idhdl *ih, ring r)
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
This class wraps leftv by taking into acount memory allocation, destruction as well as deeply copying...
BOOLEAN retrieve(leftv res)
Get additional data (e.g. subexpression data) from likewise instances.
Construct even deeper copy: Skip identifier (if any) and take care of the data on our own...
leftv m_data
Store the actual data.
Ths class wraps leftv by taking into acount memory allocation, destruction as well as shallowly copyi...
CountedRefPtr(ptr_type ptr)
Convert from pointer.
~CountedRefWeakPtr()
Unlink one reference (handled by CountedRefPtr)
bool unassigned() const
Test whether reference was never used.
static leftv idify(leftv head, idhdl *root)
~LeftvDeep()
Really clear data.
self & operator=(leftv rhs)
Assign shallow copy of the input.
CountedRefPtr< CountedRefIndirectPtr< ptr_type > * > ptrptr_type
bool operator==(ptr_type ptr) const
self & operator=(leftv rhs)
Reassign a new deep copy by occupieing another leftv.
BOOLEAN put(leftv result)
Put a shallow copy to given leftv.
LeftvShallow(leftv data)
Shallow copy the input data.
self & operator=(const self &rhs)
Assign (shallow) copy of *this.
char name(const Variable &v)
bool operator!=(ptr_type rhs) const
Pointer-style interface.
static void clearid(idhdl handle, idhdl *root)
CountedRefWeakPtr()
Construct unassigned weak reference.
static void recursivekill(Type *current)
self & operator=(ptr_type ptr)
ptr_type operator->()
Pointer-style interface.
leftv idify(idhdl *root)
Wrap data by identifier, if not done yet.
static Type * cpy(Type *result, Type *data)
This class implements a smart pointer which handles pointer-style access to a reference-counted struc...
~CountedRefPtr()
Unlink one reference.
LeftvDeep(leftv data, copy_tag)
void CleanUp(ring r=currRing)
void clearid(idhdl *root)
Erase identifier handles by *this.
static idhdl newid(leftv head, idhdl *root)
leftv operator->() const
The actual data pointer.
self & operator=(const self &rhs)
CountedRefIndirectPtr(PtrType ptr)
BOOLEAN isid() const
Check for being an identifier.
LeftvShallow(const self &rhs)
Construct (shallow) copy of *this.
static Type * recursivecpy(Type *data)
self & operator=(const self &rhs)
Pointer-style interface.
BOOLEAN ringed()
Test whether we reference to ring-dependent data.
idhdl set(const char *s, int lev, int t, BOOLEAN init=TRUE)
short count_type
Name numerical type for enumbering.
const ptr_type operator->() const
This class implements some recurrent code sniplets to be used with leftv and idhdl.implements a refernce counter which we can use.
BOOLEAN brokenid(idhdl context) const
Check a given context for our identifier.