My Project
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Types
CountedRef Class Reference

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 CountedRef (data_ptr arg)
 Recover previously constructed reference. More...
 

Protected Attributes

data_ptr m_data
 Store pointer to actual data. More...
 

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.
Definition: countedref.cc:352
CountedRefData data_type
Name type for handling referenced data.
Definition: countedref.cc:207

◆ 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 }
BOOLEAN assign(leftv result, leftv arg)
Reassign actual object.
Definition: countedref.cc:142
return result
Definition: facAbsBiFact.cc:75

◆ 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(); }
BOOLEAN broken() const
Check whether identifier became invalid.
Definition: countedref.cc:123

◆ 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.
Definition: countedref.cc:216
static self cast(void *data)
Recover the actual object from raw Singular data.
Definition: countedref.cc:312
void * Data()
Definition: subexpr.cc:1162
#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
Definition: countedref.cc:200

◆ 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:96
CanonicalForm res
Definition: facAbsFact.cc:60
#define NONE
Definition: tok.h:221

◆ 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)
Definition: omAllocDecl.h:263
@ STRING_CMD
Definition: tok.h:185

◆ 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); }
count_type count() const
Store actual pointer.
Definition: countedref.h:95
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331

◆ 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:87
CanonicalForm b
Definition: cfModGcd.cc:4103
BOOLEAN put(leftv res)
Write (shallow) copy to given handle.
Definition: countedref.cc:108
void release()
Store actual pointer.
Definition: countedref.h:97
void reclaim()
Store actual pointer.
Definition: countedref.h:96
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition: countedref.cc:324
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:1019
BOOLEAN countedref_CheckAssign(blackbox *, leftv, leftv)
We use the function pointer as a marker of reference types for CountedRef::is_ref(leftv),...
Definition: countedref.cc:193
@ MAX_TOK
Definition: tok.h:218

◆ 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.
Definition: countedref.cc:262
Definition: idrec.h:35
#define IDDATA(a)
Definition: ipid.h:126
#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:100
BOOLEAN dereference(leftv arg)
Replaces argument by a shallow copy of the references data.
Definition: countedref.cc:274

◆ 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:140

◆ 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(); }
BOOLEAN unassigned() const
Check whether data is all-zero.
Definition: countedref.cc:154

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: