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 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)
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...
self & operator=(ptr_type ptr)
Pointer-style interface.
BOOLEAN isid() const
Check for being an identifier.
static Type * shallowcpy(Type *data)
CountedRefWeakPtr(const self &rhs)
Construct copy.
CountedRefPtr(const self &rhs)
Construct refernce copy.
ptr_type m_ptr
Store actual pointer.
LeftvDeep()
Allocate all-zero object by default.
static Type * cpy(Type *data)
void countedref_reference_load()
Initialize blackbox types 'reference' and 'shared', or both.
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...
bool unassigned() const
Test whether reference was never used.
void killhdl2(idhdl h, idhdl *ih, ring r)
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
CountedRefWeakPtr(ptr_type ptr)
Convert from pointer.
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.
self & operator=(const self &rhs)
Pointer-style interface.
static leftv idify(leftv head, idhdl *root)
~LeftvDeep()
Really clear data.
self & operator=(leftv rhs)
Assign shallow copy of the input.
CountedRefWeakPtr()
Construct unassigned weak reference.
self & operator=(const self &)
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.
char name(const Variable &v)
bool like(const self &rhs) const
Determine whether we point to the same data.
void invalidate()
Mark weak reference as invalid.
bool operator==(const self &rhs) const
Checking equality.
const ptr_type operator->() const
Pointer-style interface.
static void clearid(idhdl handle, idhdl *root)
static void recursivekill(Type *current)
self & operator=(ptr_type ptr)
leftv idify(idhdl *root)
Wrap data by identifier, if not done yet.
static Type * cpy(Type *result, Type *data)
bool operator!=(ptr_type rhs) const
Pointer-style interface.
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)
ptr_type operator->()
Pointer-style interface.
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)
~CountedRefWeakPtr()
Unlink one reference (handled by CountedRefPtr)
CountedRefIndirectPtr(PtrType ptr)
CountedRefPtr(const CountedRefPtr< ptr_type,!nondestructive, Never, count_type > &rhs)
Convert from compatible smart pointer.
CountedRefPtr< CountedRefIndirectPtr< ptr_type > * > ptrptr_type
LeftvShallow(const self &rhs)
Construct (shallow) copy of *this.
static Type * recursivecpy(Type *data)
BOOLEAN ringed()
Test whether we reference to ring-dependent data.
bool operator==(ptr_type ptr) const
Pointer-style interface.
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.