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>
218 res->
data =(
void*) handle;
225 static unsigned int counter = 0;
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) {
251 template <
class Type>
253 if (data ==
NULL)
return data;
258 template <
class Type>
263 template <
class Type>
267 template <
class Type>
269 if(current ==
NULL)
return;
391 return (context ==
NULL) ||
CountedRefPtr()
Default constructor.
void invalidate()
Mark weak reference as invalid.
void CountedRefPtr_kill(CountedRefIndirectPtr< PtrType > *pval)
Class used for (list of) interpreter objects.
leftv m_data
The actual data pointer.
count_type ref
Number of references.
RefCounter(...)
Any Constructor resets the counter.
CountedRefIndirectPtr & operator=(PtrType ptr)
bool operator!=(ptr_type rhs) const
Pointer-style interface.
static Type * shallowcpy(Type *result, Type *data)
leftv operator->()
The actual data pointer.
LeftvDeep(leftv data)
Store a deep copy of the data @ note Occupies the provided leftv and invalidates the latter...
BOOLEAN isid() const
Check for being an identifier.
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()
LeftvShallow()
Just allocate (all-zero) leftv.
BOOLEAN unassigned() const
Check whether (all-zero) initialized data was never assigned.
leftv operator->() const
The actual data pointer.
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)
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
self & operator=(const self &)
const ptr_type operator->() const
Pointer-style interface.
self & operator=(leftv rhs)
Reassign a new deep copy by occupieing another leftv.
BOOLEAN put(leftv result)
Put a shallow copy to given leftv.
bool operator==(ptr_type ptr) const
LeftvShallow(leftv data)
Shallow copy the input data.
BOOLEAN brokenid(idhdl context) const
Check a given context for our identifier.
self & operator=(const self &rhs)
Assign (shallow) copy of *this.
bool like(const self &rhs) const
Determine whether we point to the same data.
bool operator==(ptr_type ptr) const
Pointer-style interface.
bool operator==(const self &rhs) const
Checking equality.
static void clearid(idhdl handle, idhdl *root)
char name(const Variable &v)
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)
bool unassigned() const
Test whether reference was never used.
This class implements a smart pointer which handles pointer-style access to a reference-counted struc...
const ptr_type operator->() const
~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)
self & operator=(const self &rhs)
CountedRefIndirectPtr(PtrType ptr)
CountedRefPtr(const CountedRefPtr< ptr_type,!nondestructive, Never, count_type > &rhs)
Convert from compatible smart pointer.
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.
This class implements some recurrent code sniplets to be used with leftv and idhdl.implements a refernce counter which we can use.