CXXR (C++ R) API
|
Replacement for CR's SEXPREC. More...
#include <RObject.h>
Classes | |
struct | DoNothing |
Class of function object that does nothing to an RObject. More... |
Public Member Functions | |
virtual const PairList * | attributes () const |
Get object attributes. | |
virtual void | clearAttributes () |
Remove all attributes. | |
virtual RObject * | clone () 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 RObject * | evaluate (Environment *env) |
Evaluate object in a specified Environment. | |
virtual RObject * | getAttribute (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. | |
void | detachReferents () |
Null out all references from this node to other nodes. | |
void | visitReferents (const_visitor *v) const |
Conduct a visitor to the nodes referred to by this one. | |
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? | |
Public Member Functions inherited from CXXR::HeterogeneousListBase::Link | |
Link () | |
Default constructor. | |
Link (HeterogeneousListBase *list) | |
Appending constructor. | |
void | freeLink () |
Detach Link from any list. |
Static Public Member Functions | |
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. |
Public Attributes | |
unsigned char | m_named |
unsigned | m_missing: 2 |
unsigned | m_argused: 2 |
bool | m_active_binding: 1 |
bool | m_binding_locked: 1 |
Protected Member Functions | |
RObject (SEXPTYPE stype=CXXSXP) | |
RObject (const RObject &pattern) | |
Copy constructor. | |
Protected Member Functions inherited from CXXR::GCNode | |
virtual | ~GCNode () |
Protected Member Functions inherited from CXXR::HeterogeneousListBase::Link | |
virtual | ~Link () |
Friends | |
class | boost::serialization::access |
Replacement for CR's SEXPREC.
This class is the rough equivalent within CXXR of the SEXPREC union within CR. However, all functionality relating to garbage collection has been factored out into the base class GCNode, and as CXXR development proceeds other functionality will be factored out into derived classes (corresponding roughly, but not exactly, to different SEXPTYPE values within CR), or outside the RObject hierarchy altogether.
Eventually this class may end up simply as the home of R attributes.
objects()
. In particular, it does not imply that the object belongs to an R class.m_has_class
is true iff the object has the class attribute.
Each attribute in the list of attributes must have a Symbol as its tag. Null tags are not allowed.
Each attribute must have a distinct tag: no duplicates allowed.
const SEXP
is misguided: the compiler interprets this in effect as RObject* const
, not as const RObject*
.) One possible policy would be simply never to use const T*
, where T
is RObject*
or a class inheriting from it: that would remove any need for const_cast
s at the interface between new CXXR code and code inherited from CR. But CXXR tries to move closer to C++ idiom than that, notwithstanding the resulting need for const_cast
s at the interface, and applies a policy driven by the following considerations: RObject::evaluate() cannot return a const RObject*
, because some functions return a pointer to an Environment
, which may well need subsequently to be modified e.g. by inserting or changing bindings.
This in turn means that RObject::evaluate() cannot itself be a const
function, because the default implementation returns this
. (Another view would be that the default implementation is an elided copy.) Also, Promise objects change internally when they are evaluated (though this might conceivably be swept up by mutable
).
It is a moot point whether FunctionBase::apply() can be const
. Closure::apply() entails evaluating the body, and if the body is regarded as part of the Closure object, that would point to apply()
not being const
. (Note that some of the types which Rf_mkCLOSXP() accepts as a Closure body use the default RObject::evaluate(), so Point 2 definitely applies.)
Should PairList objects and suchlike emulate (roughly speaking) (a) list<pair<const RObject*, const RObject*> >
(where the first element of the pair is the tag and the second the 'car'), (b) list<pair<const RObject*, RObject*> >
or (c) list<pair<RObject*, RObject*> >
? Since the 'cars' of list elements will often need to be evaluated, Point 2 rules out (a). At present CXXR follows (b).
stype | Required type of the RObject. |
|
protected |
Copy constructor.
pattern | Object to be copied. |
|
virtual |
Get object attributes.
|
inlinevirtual |
Return pointer to a copy of this object.
This function creates a copy of this object, and returns a pointer to that copy.
Generally this function (and the copy constructors it utilises) will attempt to create a 'deep' copy of the object; this follows standard practice within C++, and it is intended to extend this practice as CXXR development continues.
However, if the pattern object contains unclonable subobjects, then the created copy will at the relevant places simply contain pointers to those subobjects, i.e. to that extent the copy is 'shallow'. This is managed using the smart pointers defined by nested class RObject::Handle.
Reimplemented in CXXR::PairList, CXXR::VectorBase, CXXR::FixedVector< T, ST, Initializer >, CXXR::Closure, CXXR::DumbVector< T, ST >, CXXR::Expression, and CXXR::S4Object.
|
inlinestatic |
void CXXR::RObject::copyAttributes | ( | const RObject * | source, |
bool | copyS4 | ||
) |
Copy attributes from one RObject to another.
Any existing attributes of *this are discarded.
source | Non-null pointer to the object from which attributes are to be copied. |
copyS4 | If true, the status of source as an S4 object (or not) is also copied to *this . |
|
inlinevirtual |
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()).
Reimplemented from CXXR::GCNode.
Reimplemented in CXXR::Environment, CXXR::ConsCell, CXXR::Symbol, CXXR::FixedVector< T, ST, Initializer >, CXXR::Closure, CXXR::WeakRef, CXXR::ExternalPointer, CXXR::Promise, and CXXR::HandleVector< T, ST >.
|
virtual |
Evaluate object in a specified Environment.
env | Pointer to the environment in which evaluation is to take place. |
Reimplemented in CXXR::Symbol, CXXR::Promise, and CXXR::Expression.
Get the value a particular attribute.
name | Pointer to a Symbol giving the name of the sought attribute. |
|
inlinevirtual |
Has this object any attributes?
|
inline |
Has this object the class attribute?
|
inline |
Is this an S4 object?
|
inline |
Carry out memory tracing.
This function is a no-op unless CXXR is built with R_MEMORY_PROFILING defined (as will happen if it is configured with –enable-memory-profiling).
This function should be called if this
has been created as a copy of src, or if this
has been derived in some way from src1. When memory profiling is enabled, if src points to an RObject with the memoryTraced() property set, this property will be propagated to this
. Also the creation of this object will be reported, along with the current context stack.
src | Non-null pointer to an RObject. |
Carry out memory tracing.
This function is a no-op unless CXXR is built with R_MEMORY_PROFILING defined (as will happen if it is configured with –enable-memory-profiling).
This function should be called if this
has been derived in some way from src1 and src2. When memory profiling is enabled, if either src1 or src2 points to an RObject with the memoryTraced() property set, this property will be propagated to this
. Also the creation of this object will be reported, along with the current context stack.
|
inline |
Carry out memory tracing.
This function is a no-op unless CXXR is built with R_MEMORY_PROFILING defined (as will happen if it is configured with –enable-memory-profiling).
This function should be called if this
has been derived in some way from src1, src2 and src 3. When memory profiling is enabled, if any of src1, src2 or src3 points to an RObject with the memoryTraced() property set, this property will be propagated to this
. Also the creation of this object will be reported, along with the current context stack.
|
inline |
Is copying etc. of this object being traced?
The property reported by this function is used by R functions such as tracemem
, and has effect only if CXXR is built with R_MEMORY_PROFILING defined (as will happen if it is configured with –enable-memory-profiling).
|
virtual |
Reproduce the gp
bits field used in CR.
This function is used to reproduce the sxpinfo_struct.gp
field used in CR. It should be used exclusively for serialization. Refer to the 'R Internals' document for details of this field.
gp
bits field (within the least significant 16 bits).Reimplemented in CXXR::PairList, CXXR::Environment, CXXR::String, and CXXR::WeakRef.
Set or remove an attribute.
name | Pointer to the Symbol naming the attribute to be set or removed. |
value | Pointer to the value to be ascribed to the attribute, or a null pointer if the attribute is to be removed. The object whose attribute is set (i.e. this ) should be considered to assume ownership of value, which should therefore not be subsequently altered externally. |
void CXXR::RObject::setAttributes | ( | const PairList * | new_attributes | ) |
Replace the attributes of an object.
new_attributes | Pointer to the start of the new list of attributes. May be a null pointer, in which case all attributes are removed. The object whose attributes are set (i.e. this ) should be considered to assume ownership of the 'car' values in new_attributes ; they should therefore not be subsequently altered externally. |
|
inline |
Enable/disable tracing of copying etc.
The property set by this function is used by R functions such as tracemem
, and has effect only if CXXR is built with R_MEMORY_PROFILING defined (as will happen if it is configured with –enable-memory-profiling).
on | A value of true signifies that when a copy is made of this object, or - more generally - some comparably sized object is derived from this object, this fact should be reported, and the 'memory traced' property propagated to the new object. |
void CXXR::RObject::setS4Object | ( | bool | on | ) |
|
inline |
|
virtual |
Name within R of this type of object.
Reimplemented in CXXR::PairList, CXXR::Environment, CXXR::BuiltInFunction, CXXR::Symbol, CXXR::String, CXXR::FixedVector< T, ST, Initializer >, CXXR::Closure, CXXR::ExternalPointer, CXXR::Promise, CXXR::HandleVector< T, ST >, CXXR::DumbVector< T, ST >, CXXR::UncachedString, CXXR::CachedString, CXXR::Expression, and CXXR::S4Object.
|
virtual |
Interpret the gp
bits field used in CR.
This function is used to interpret the sxpinfo_struct.gp
field used in CR in a way appropriate to a particular node class. It should be used exclusively for deserialization. Refer to the 'R Internals' document for details of this field.
gpbits | the gp bits field (within the least significant 16 bits). |
Reimplemented in CXXR::PairList, CXXR::Environment, and CXXR::WeakRef.
|
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.
v | Pointer to the visitor object. |
Reimplemented from CXXR::GCNode.
Reimplemented in CXXR::Environment, CXXR::ConsCell, CXXR::Symbol, CXXR::FixedVector< T, ST, Initializer >, CXXR::Closure, CXXR::ExternalPointer, CXXR::Promise, and CXXR::HandleVector< T, ST >.