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); }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
#define assume(x)
Definition: mod2.h:394

◆ 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) { }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352

◆ ~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  }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
return result
Definition: facAbsBiFact.cc:76

◆ 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(); }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352

◆ cast() [1/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  }
CountedRefData data_type
Name type for handling referenced data.
Definition: countedref.cc:207
#define assume(x)
Definition: mod2.h:394
#define NULL
Definition: omList.c:10

◆ cast() [2/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
#define assume(x)
Definition: mod2.h:394
#define NULL
Definition: omList.c:10
void * Data()
Definition: subexpr.cc:1137
static self cast(void *data)
Recover the actual object from raw Singular data.
Definition: countedref.cc:312

◆ construct() [1/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  }
Definition: tok.h:95
#define FALSE
Definition: auxiliary.h:94
poly res
Definition: myNF.cc:322

◆ 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 FALSE
Definition: auxiliary.h:94
poly res
Definition: myNF.cc:322
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ construct() [3/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:94
poly res
Definition: myNF.cc:322
#define NULL
Definition: omList.c:10
#define NONE
Definition: tok.h:216

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

◆ 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  }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition: countedref.cc:324
void reclaim()
Definition: countedref.h:96
leftv next
Definition: subexpr.h:86
void release()
Definition: countedref.h:97
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:85
const poly b
Definition: syzextra.cc:213

◆ destruct()

void CountedRef::destruct ( )
inline

Kills a link to the referenced object.

Definition at line 268 of file countedref.cc.

268 { m_data.release(); }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
void release()
Definition: countedref.h:97

◆ enumerate()

BOOLEAN CountedRef::enumerate ( leftv  res)
inline

Definition at line 291 of file countedref.cc.

291 { return construct(res, (long)(data_type*)m_data); }
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
poly res
Definition: myNF.cc:322
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331

◆ 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  }
Definition: tok.h:213
int Typ()
Definition: subexpr.cc:995
BOOLEAN countedref_CheckAssign(blackbox *, leftv, leftv)
We use the function pointer as a marker of reference types for CountedRef::is_ref(leftv), see the latter for details.
Definition: countedref.cc:193
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:16

◆ 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  }
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition: countedref.cc:324
void * data
Definition: subexpr.h:88
poly res
Definition: myNF.cc:322
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331

◆ 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()); }
poly res
Definition: myNF.cc:322
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331

◆ operator*()

LeftvShallow CountedRef::operator* ( )
inline

Extract (shallow) copy of stored data.

Definition at line 244 of file countedref.cc.

244 { return m_data->operator*(); }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352

◆ 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  }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352

◆ outcast() [1/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  }
data_type * outcast()
Construct raw reference data.
Definition: countedref.cc:262
poly res
Definition: myNF.cc:322

◆ 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
#define FALSE
Definition: auxiliary.h:94
Definition: idrec.h:34
#define IDHDL
Definition: tok.h:31
poly res
Definition: myNF.cc:322
#define IDDATA(a)
Definition: ipid.h:123

◆ outcast() [3/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  }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
void reclaim()
Definition: countedref.h:96

◆ 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  }
BOOLEAN dereference(leftv arg)
Replaces argument by a shallow copy of the references data.
Definition: countedref.cc:274
static BOOLEAN is_ref(leftv arg)
Check whether argument is already a reference type.
Definition: countedref.cc:216
#define TRUE
Definition: auxiliary.h:98
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition: countedref.cc:324
#define assume(x)
Definition: mod2.h:394
leftv next
Definition: subexpr.h:86
#define NULL
Definition: omList.c:10
static self cast(void *data)
Recover the actual object from raw Singular data.
Definition: countedref.cc:312

◆ 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  }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352
poly res
Definition: myNF.cc:322
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331
void * Data()
Definition: subexpr.cc:1137

◆ 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  };
poly res
Definition: myNF.cc:322
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:331

◆ 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(); }
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:352

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: