My Project
Loading...
Searching...
No Matches
CountedRef Class Reference

Public Types

typedef int id_type
 name type for identifiers
 
typedef CountedRefData data_type
 Name type for handling referenced data.
 
typedef CountedRefPtr< CountedRefData * > data_ptr
 Fix smart pointer type to referenced data.
 

Public Member Functions

 CountedRef (leftv arg)
 Reference given Singular data.
 
 CountedRef (const self &rhs)
 Construct copy.
 
selfoperator= (const self &rhs)
 Replace reference.
 
BOOLEAN assign (leftv result, leftv arg)
 
LeftvShallow operator* ()
 Extract (shallow) copy of stored data.
 
BOOLEAN outcast (leftv res, int typ)
 Construct reference data object marked by given identifier number.
 
BOOLEAN outcast (leftv res)
 Construct reference data object from *this.
 
data_typeoutcast ()
 Construct raw reference data.
 
void destruct ()
 Kills a link to the referenced object.
 
 ~CountedRef ()
 Kills the link to the referenced object.
 
BOOLEAN dereference (leftv arg)
 Replaces argument by a shallow copy of the references data.
 
BOOLEAN broken ()
 Check whether object in valid in current context.
 
BOOLEAN unassigned () const
 Check whether (shared) data was initialized but not assigned yet.
 
BOOLEAN count (leftv res)
 Get number of references pointing here, too.
 
BOOLEAN enumerate (leftv res)
 
BOOLEAN likewise (leftv res, leftv arg)
 Check for likewise identifiers.
 
BOOLEAN same (leftv res, leftv arg)
 Check for identical reference objects.
 
BOOLEAN type (leftv res)
 Get type of references data.
 
BOOLEAN name (leftv res)
 Get (possibly) internal identifier name.
 

Static Public Member Functions

static BOOLEAN is_ref (leftv arg)
 Check whether argument is already a reference type.
 
static self cast (void *data)
 Recover the actual object from raw Singular data.
 
static self cast (leftv arg)
 Recover the actual object from Singular interpreter object.
 
static BOOLEAN resolve (leftv arg)
 If necessary dereference.
 
static BOOLEAN construct (leftv res, long data)
 Construct integer value.
 
static BOOLEAN construct (leftv res, const char *data)
 Construct string.
 
static BOOLEAN construct (leftv res)
 Construct void-style object.
 

Protected Member Functions

 CountedRef (data_ptr arg)
 Recover previously constructed reference.
 

Protected Attributes

data_ptr m_data
 Store pointer to actual data.
 

Private Types

typedef CountedRef self
 

Detailed Description

Definition at line 199 of file countedref.cc.

Member Typedef Documentation

◆ data_ptr

Fix smart pointer type to referenced data.

Definition at line 210 of file countedref.cc.

◆ data_type

Name type for handling referenced data.

Definition at line 207 of file countedref.cc.

◆ id_type

typedef int CountedRef::id_type

name type for identifiers

Definition at line 204 of file countedref.cc.

◆ self

typedef CountedRef CountedRef::self
private

Definition at line 200 of file countedref.cc.

Constructor & Destructor Documentation

◆ CountedRef() [1/3]

CountedRef::CountedRef ( leftv arg)
inlineexplicit

Reference given Singular data.

Definition at line 223 of file countedref.cc.

223: m_data(new data_type(arg)) { }
data_ptr m_data
Store pointer to actual data.
CountedRefData data_type
Name type for handling referenced data.

◆ CountedRef() [2/3]

CountedRef::CountedRef ( data_ptr arg)
inlineprotected

Recover previously constructed reference.

Definition at line 227 of file countedref.cc.

227: m_data(arg) { assume(arg); }
#define assume(x)
Definition mod2.h:389

◆ CountedRef() [3/3]

CountedRef::CountedRef ( const self & rhs)
inline

Construct copy.

Definition at line 231 of file countedref.cc.

231: m_data(rhs.m_data) { }

◆ ~CountedRef()

CountedRef::~CountedRef ( )
inline

Kills the link to the referenced object.

Definition at line 271 of file countedref.cc.

271{ }

Member Function Documentation

◆ assign()

BOOLEAN CountedRef::assign ( leftv result,
leftv arg )
inline

Definition at line 239 of file countedref.cc.

239 {
240 return m_data->assign(result,arg);
241 }
return result

◆ broken()

BOOLEAN CountedRef::broken ( )
inline

Check whether object in valid in current context.

Definition at line 282 of file countedref.cc.

282{return m_data->broken(); }

◆ cast() [1/2]

static self CountedRef::cast ( leftv arg)
inlinestatic

Recover the actual object from Singular interpreter object.

Definition at line 318 of file countedref.cc.

318 {
319 assume(arg != NULL); assume(is_ref(arg));
320 return self::cast(arg->Data());
321 }
static BOOLEAN is_ref(leftv arg)
Check whether argument is already a reference type.
static self cast(void *data)
Recover the actual object from raw Singular data.
void * Data()
Definition subexpr.cc:1192
#define NULL
Definition omList.c:12

◆ cast() [2/2]

static self CountedRef::cast ( void * data)
inlinestatic

Recover the actual object from raw Singular data.

Definition at line 312 of file countedref.cc.

312 {
313 assume(data != NULL);
314 return self(static_cast<data_type*>(data));
315 }
CountedRef self

◆ construct() [1/3]

static BOOLEAN CountedRef::construct ( leftv res)
inlinestatic

Construct void-style object.

Definition at line 344 of file countedref.cc.

344 {
345 res->data = NULL;
346 res->rtyp = NONE;
347 return FALSE;
348 }
#define FALSE
Definition auxiliary.h:97
CanonicalForm res
Definition facAbsFact.cc:60
#define NONE
Definition tok.h:223

◆ construct() [2/3]

static BOOLEAN CountedRef::construct ( leftv res,
const char * data )
inlinestatic

Construct string.

Definition at line 338 of file countedref.cc.

338 {
339 res->data = (void*)omStrDup(data);
340 res->rtyp = STRING_CMD;
341 return FALSE;
342 }
#define omStrDup(s)
@ STRING_CMD
Definition tok.h:187

◆ construct() [3/3]

static BOOLEAN CountedRef::construct ( leftv res,
long data )
inlinestatic

Construct integer value.

Definition at line 331 of file countedref.cc.

331 {
332 res->data = (void*) data;
333 res->rtyp = INT_CMD;
334 return FALSE;
335 }
@ INT_CMD
Definition tok.h:96

◆ count()

BOOLEAN CountedRef::count ( leftv res)
inline

Get number of references pointing here, too.

Definition at line 288 of file countedref.cc.

288{ return construct(res, m_data.count() - 1); }
static BOOLEAN construct(leftv res, long data)
Construct integer value.

◆ dereference()

BOOLEAN CountedRef::dereference ( leftv arg)
inline

Replaces argument by a shallow copy of the references data.

Definition at line 274 of file countedref.cc.

274 {
275 m_data.reclaim();
276 BOOLEAN b= m_data->put(arg) || ((arg->next != NULL) && resolve(arg->next));
277 m_data.release();
278 return b;
279 }
int BOOLEAN
Definition auxiliary.h:88
CanonicalForm b
Definition cfModGcd.cc:4111
static BOOLEAN resolve(leftv arg)
If necessary dereference.
leftv next
Definition subexpr.h:86

◆ destruct()

void CountedRef::destruct ( )
inline

Kills a link to the referenced object.

Definition at line 268 of file countedref.cc.

268{ m_data.release(); }

◆ enumerate()

BOOLEAN CountedRef::enumerate ( leftv res)
inline

Definition at line 291 of file countedref.cc.

291{ return construct(res, (long)(data_type*)m_data); }

◆ is_ref()

static BOOLEAN CountedRef::is_ref ( leftv arg)
inlinestatic

Check whether argument is already a reference type.

Note
We check for the function pointer countedref_CheckAssign here, that we (ab-)use as a unique marker. This avoids to check a bunch of of runtime-varying typ IDs for identifying reference-like types.

Definition at line 216 of file countedref.cc.

216 {
217 int typ = arg->Typ();
218 return ((typ > MAX_TOK) &&
219 (getBlackboxStuff(typ)->blackbox_CheckAssign == countedref_CheckAssign));
220 }
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
int Typ()
Definition subexpr.cc:1048
BOOLEAN countedref_CheckAssign(blackbox *, leftv, leftv)
We use the function pointer as a marker of reference types for CountedRef::is_ref(leftv),...
@ MAX_TOK
Definition tok.h:220

◆ likewise()

BOOLEAN CountedRef::likewise ( leftv res,
leftv arg )
inline

Check for likewise identifiers.

Definition at line 294 of file countedref.cc.

294 {
295 return resolve(arg) || construct(res, operator*()->data == arg->data);
296 }
void * data
Definition subexpr.h:88

◆ name()

BOOLEAN CountedRef::name ( leftv res)
inline

Get (possibly) internal identifier name.

Definition at line 309 of file countedref.cc.

309{ return construct(res, operator*()->Name()); }

◆ operator*()

LeftvShallow CountedRef::operator* ( )
inline

Extract (shallow) copy of stored data.

Definition at line 244 of file countedref.cc.

244{ return m_data->operator*(); }

◆ operator=()

self & CountedRef::operator= ( const self & rhs)
inline

Replace reference.

Definition at line 234 of file countedref.cc.

234 {
235 m_data = rhs.m_data;
236 return *this;
237 }

◆ outcast() [1/3]

data_type * CountedRef::outcast ( )
inline

Construct raw reference data.

Definition at line 262 of file countedref.cc.

262 {
263 m_data.reclaim();
264 return m_data;
265 }

◆ outcast() [2/3]

BOOLEAN CountedRef::outcast ( leftv res)
inline

Construct reference data object from *this.

Definition at line 253 of file countedref.cc.

253 {
254 if (res->rtyp == IDHDL)
255 IDDATA((idhdl)res->data) = (char *)outcast();
256 else
257 res->data = (void *)outcast();
258 return FALSE;
259 }
data_type * outcast()
Construct raw reference data.
#define IDDATA(a)
Definition ipid.h:126
idrec * idhdl
Definition ring.h:22
#define IDHDL
Definition tok.h:31

◆ outcast() [3/3]

BOOLEAN CountedRef::outcast ( leftv res,
int typ )
inline

Construct reference data object marked by given identifier number.

Definition at line 247 of file countedref.cc.

247 {
248 res->rtyp = typ;
249 return outcast(res);
250 }

◆ resolve()

static BOOLEAN CountedRef::resolve ( leftv arg)
inlinestatic

If necessary dereference.

Definition at line 324 of file countedref.cc.

324 {
325 assume(arg != NULL);
326 while (is_ref(arg)) { if(CountedRef::cast(arg).dereference(arg)) return TRUE; };
327 return (arg->next != NULL) && resolve(arg->next);
328 }
#define TRUE
Definition auxiliary.h:101
BOOLEAN dereference(leftv arg)
Replaces argument by a shallow copy of the references data.

◆ same()

BOOLEAN CountedRef::same ( leftv res,
leftv arg )
inline

Check for identical reference objects.

Definition at line 299 of file countedref.cc.

299 {
300 return construct(res, m_data == arg->Data());
301 }

◆ type()

BOOLEAN CountedRef::type ( leftv res)
inline

Get type of references data.

Definition at line 304 of file countedref.cc.

304 {
305 return construct(res, Tok2Cmdname(operator*()->Typ()));
306 };
const char * Tok2Cmdname(int tok)
Definition gentable.cc:137

◆ unassigned()

BOOLEAN CountedRef::unassigned ( ) const
inline

Check whether (shared) data was initialized but not assigned yet.

Definition at line 285 of file countedref.cc.

285{ return m_data->unassigned(); }

Field Documentation

◆ m_data

data_ptr CountedRef::m_data
protected

Store pointer to actual data.

Definition at line 352 of file countedref.cc.


The documentation for this class was generated from the following file: