CXXR (C++ R) API
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
CXXR::ConsCell Class Reference

Element of a singly linked list. More...

#include <ConsCell.h>

Inheritance diagram for CXXR::ConsCell:
Inheritance graph
[legend]
Collaboration diagram for CXXR::ConsCell:
Collaboration graph
[legend]

List of all members.

Classes

class  const_iterator
 const_iterator for iterating over a ConsCell list. More...
class  iterator
 iterator for iterating over a HeterogeneousList. More...

Public Member Functions

iterator begin ()
const_iterator begin () const
RObjectcar () const
iterator end ()
const_iterator end () const
void setCar (RObject *cr)
 Set the 'car' value.
void setTag (const RObject *tg)
 Set the 'tag' value.
void setTail (PairList *tl)
 Set the 'tail' value.
const RObjecttag () const
const PairListtail () const
PairListtail ()
void visitReferents (const_visitor *v) const
 Conduct a visitor to the nodes referred to by this one.
- Public Member Functions inherited from CXXR::RObject
virtual const PairListattributes () const
 Get object attributes.
virtual void clearAttributes ()
 Remove all attributes.
virtual RObjectclone () const
 Return pointer to a copy of this object.
void copyAttribute (const Symbol *name, const RObject *source)
 Copy an attribute from one RObject to another.
void copyAttributes (const RObject *source, bool copyS4)
 Copy attributes from one RObject to another.
virtual RObjectevaluate (Environment *env)
 Evaluate object in a specified Environment.
virtual RObjectgetAttribute (const Symbol *name) const
 Get the value a particular attribute.
virtual bool hasAttributes () const
 Has this object any attributes?
bool hasClass () const
 Has this object the class attribute?
bool isS4Object () const
 Is this an S4 object?
void maybeTraceMemory (const RObject *src)
 Carry out memory tracing.
void maybeTraceMemory (const RObject *src1, const RObject *src2)
 Carry out memory tracing.
void maybeTraceMemory (const RObject *src1, const RObject *src2, const RObject *src3)
 Carry out memory tracing.
bool memoryTraced () const
 Is copying etc. of this object being traced?
virtual unsigned int packGPBits () const
 Reproduce the gp bits field used in CR.
virtual void setAttribute (const Symbol *name, RObject *value)
 Set or remove an attribute.
void setAttributes (const PairList *new_attributes)
 Replace the attributes of an object.
void setMemoryTracing (bool on)
 Enable/disable tracing of copying etc.
void setS4Object (bool on)
 Set the status of this RObject as an S4 object.
SEXPTYPE sexptype () const
 Get an object's SEXPTYPE.
virtual const char * typeName () const
 Name within R of this type of object.
virtual void unpackGPBits (unsigned int gpbits)
 Interpret the gp bits field used in CR.
- Public Member Functions inherited from CXXR::GCNode
void expose () const
 Record that construction of a node is complete.
bool isExposed () const
 Has this node been exposed to garbage collection?

Static Public Member Functions

template<class T >
static T * convert (ConsCell *cc)
 Convert a ConsCell to a (possibly) different ConsCell type.
static const char * staticTypeName ()
 The name by which this type is known in R.
- Static Public Member Functions inherited from CXXR::RObject
template<class T >
static T * clone (const T *pattern)
 Return a pointer to a copy of an object.
- Static Public Member Functions inherited from CXXR::GCNode
static void * operator new (size_t bytes)
 Allocate memory.
static void * operator new (size_t, void *where)
 Placement new for GCNode.
static void operator delete (void *p, size_t bytes)
 Deallocate memory.
static bool check ()
 Integrity check.
template<class T >
static T * expose (T *node)
 Record that construction of a node is complete.
static void gc ()
 Initiate a garbage collection.
static void gclite ()
 Lightweight garbage collection.
static void maybeCheckExposed (const GCNode *node)
 Subject to configuration, check that a GCNode is exposed.
static size_t numNodes ()
 Number of GCNode objects in existence.

Protected Member Functions

 ConsCell (SEXPTYPE st, RObject *cr=0, PairList *tl=0, const RObject *tg=0)
 ConsCell (const ConsCell &pattern)
 Copy constructor.
 ConsCell (const ConsCell &pattern, int dummy)
 Tailless copy constructor.
 ~ConsCell ()
void detachReferents ()
 Null out all references from this node to other nodes.
- Protected Member Functions inherited from CXXR::RObject
 RObject (SEXPTYPE stype=CXXSXP)
 RObject (const RObject &pattern)
 Copy constructor.
- Protected Member Functions inherited from CXXR::GCNode
virtual ~GCNode ()

Friends

class boost::serialization::access
class PairList

Additional Inherited Members

- Public Attributes inherited from CXXR::RObject
unsigned char m_named
unsigned m_missing: 2
unsigned m_argused: 2
bool m_active_binding: 1
bool m_binding_locked: 1

Detailed Description

Element of a singly linked list.

Element of a LISP-like singly-linked list, containing pointers to a 'car' object (this is LISP terminology, and has nothing to do with automobiles) and to a 'tag' object, as well as a pointer to the next element of the list, which must be of the derived type PairList. (Any of these pointers may be null.)

When the object is copied, the copy thus created will contain copies of the 'car' and of subsequent elements of the list. However, the tag is not copied: the copy object will simply contain a pointer to the tag of the original object. Despite this, the tag is considered to be part of the object.

Note:
This class is used as a base class to implement CR's LISTSXP, LANGSXP, DOTSXP and (for the time being) BCODESXP. Because what these SEXPTYPEs have in common is implementation rather than meaning in the application domain, canons of object-oriented design would argue against their publicly inheriting from a common base class. Without doing this, however, it would have been difficult efficiently to implement functions such as CAR(), which are ubiquitous in the CR code.
The semantics of this class are somewhat inconsistent. When a ConsCell is copied, the copy constructor tries to copy the 'car', implying that the car is considered part of the object. But the const member function car() passes back a non-const pointer to the car. See the discussion in the documentation of class RObject regarding the handling of const pointers.

Constructor & Destructor Documentation

CXXR::ConsCell::ConsCell ( SEXPTYPE  st,
RObject cr = 0,
PairList tl = 0,
const RObject tg = 0 
)
inlineexplicitprotected
Parameters:
stThe required SEXPTYPE of the ConsCell. Must be one of LISTSXP, LANGSXP, DOTSXP or BCODESXP (not normally checked).
crPointer to the 'car' of the element to be constructed.
tlPointer to the 'tail' (LISP cdr) of the element to be constructed.
tgPointer to the 'tag' of the element to be constructed.
CXXR::ConsCell::ConsCell ( const ConsCell pattern)
inlineprotected

Copy constructor.

Parameters:
patternConsCell to be copied. Beware that if this ConsCell or any of its successors have unclonable 'car' objects, they will be shared between pattern and the created object.
CXXR::ConsCell::ConsCell ( const ConsCell pattern,
int  dummy 
)
inlineprotected

Tailless copy constructor.

Copies the node without copying its tail. Used in implementing the PairList copy constructor proper.

Parameters:
patternConsCell to be copied. Beware that if this ConsCell or any of its successors have unclonable 'car' objects, they will be shared between pattern and the created object.
dummyThis parameter is used simply to provide the constructor with a distinct signature. Its value is ignored.
CXXR::ConsCell::~ConsCell ( )
inlineprotected

Declared protected to ensure that ConsCell objects are allocated only using 'new'.


Member Function Documentation

RObject* CXXR::ConsCell::car ( ) const
inline
Returns:
a const pointer to the 'car' of this ConsCell element.
template<class T >
static T* CXXR::ConsCell::convert ( ConsCell cc)
inlinestatic

Convert a ConsCell to a (possibly) different ConsCell type.

Template Parameters:
TA (non-abstract) class derived from ConsCell.
Parameters:
ccPointer to a ConsCell (possibly null). The effect of the method on cc is undefined; consequently cc should not be used subsequently to the method call.
Returns:
Pointer to the converted object, or a null pointer if cc is null. If cc is already of the desired type, the method simply returns cc.
void CXXR::ConsCell::detachReferents ( )
protectedvirtual

Null out all references from this node to other nodes.

The referents of this node are those objects (derived from GCNode) designated by a GCEdge within this object. This function changes all GCEdges within this object to encapsulate a null pointer. It is used during the sweep phase of a mark-sweep garbage collection to break up unreachable subgraphs, and in particular to remove reference loops from them. After the application of this method, the GCNode should be regarded as a 'zombie', kept in existence only so other nodes can detach their references to it cleanly (using decRefCount()).

Note:
If this method is reimplemented in a derived class, the reimplemented version must remember to invoke detachReferents() for the immediate base class of the derived class, to ensure that all referents of the object get detached.

Reimplemented from CXXR::RObject.

void CXXR::ConsCell::setCar ( RObject cr)
inline

Set the 'car' value.

Parameters:
crPointer to the new car object (or a null pointer).
void CXXR::ConsCell::setTag ( const RObject tg)
inline

Set the 'tag' value.

Parameters:
tgPointer to the new tag object (or a null pointer).
void CXXR::ConsCell::setTail ( PairList tl)
inline

Set the 'tail' value.

Parameters:
tlPointer to the new tail list (or a null pointer).
static const char* CXXR::ConsCell::staticTypeName ( )
inlinestatic

The name by which this type is known in R.

Returns:
the name by which this type is known in R.

Reimplemented in CXXR::PairList, and CXXR::Expression.

const RObject* CXXR::ConsCell::tag ( ) const
inline
Returns:
a pointer to the 'tag' of this ConsCell.
const PairList * CXXR::ConsCell::tail ( ) const
inline
Returns:
a const pointer to the 'tail' of this ConsCell element.
PairList * CXXR::ConsCell::tail ( )
inline
Returns:
a pointer to the 'tail' of this ConsCell.
void CXXR::ConsCell::visitReferents ( const_visitor v) const
virtual

Conduct a visitor to the nodes referred to by this one.

The referents of this node are those objects (derived from GCNode) designated by a GCEdge within this object.

Parameters:
vPointer to the visitor object.
Note:
If this method is reimplemented in a derived class, the reimplemented version must remember to invoke visitReferents() for the immediate base class of the derived class, to ensure that all referents of the object get visited. It is suggested that implementations set up stack-based pointers to all the referents of a node before visiting any of them; in that case, if the (recursive) visiting pushes the node out of the processor cache, there is no need to fetch it back in.

Reimplemented from CXXR::RObject.


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