CXXR (C++ R) API
|
Mapping from Symbols to R objects. More...
#include <Frame.hpp>
Classes | |
class | Binding |
Representation of a binding of a Symbol to an RObject. More... |
Public Types | |
typedef boost::any_range < const Binding, boost::forward_traversal_tag, const Binding &, std::ptrdiff_t > | BindingRange |
Allow iteration over a Frame object's Bindings. | |
typedef void(* | monitor )(const Binding &) |
Function type for read and write monitors. |
Public Member Functions | |
Frame (const Frame &source) | |
Copy constructor. | |
PairList * | asPairList () const |
Get contents as a PairList. | |
Binding * | bind (const Symbol *symbol, RObject *value, Frame::Binding::Origin origin=Frame::Binding::EXPLICIT) |
Bind a Symbol to a specified value. | |
virtual Binding * | binding (const Symbol *symbol)=0 |
Access binding of an already-defined Symbol. | |
virtual const Binding * | binding (const Symbol *symbol) const =0 |
Access const binding of an already-defined Symbol. | |
virtual BindingRange | bindingRange () const =0 |
Obtain a BindingRange for this Frame. | |
void | clear () |
Remove all symbols from the Frame. | |
virtual Frame * | clone () const =0 |
Return pointer to a copy of this Frame. | |
void | enableReadMonitoring (bool on) const |
Enable monitored reading of Symbol values. | |
void | enableWriteMonitoring (bool on) const |
Enable monitored writing of Symbol values. | |
bool | erase (const Symbol *symbol) |
Remove the Binding (if any) of a Symbol. | |
bool | isLocked () const |
Is the Frame locked? | |
void | lock (bool lock_bindings) |
Lock this Frame. | |
virtual void | lockBindings ()=0 |
Lock all Bindings in this Frame. | |
Binding * | obtainBinding (const Symbol *symbol) |
Get or create a Binding for a Symbol. | |
virtual std::size_t | size () const =0 |
Number of Bindings in Frame. | |
std::vector< const Symbol * > | symbols (bool include_dotsymbols) const |
Symbols bound by this Frame. | |
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 | |
static monitor | setReadMonitor (monitor new_monitor) |
Define function to monitor reading of Symbol values. | |
static monitor | setWriteMonitor (monitor new_monitor) |
Define function to monitor writing of Symbol values. | |
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 | |
void | statusChanged (const Symbol *sym) |
Report change in the bound/unbound status of Symbol objects. | |
void | detachReferents () |
Null out all references from this node to other nodes. | |
Protected Member Functions inherited from CXXR::GCNode | |
virtual | ~GCNode () |
Protected Member Functions inherited from CXXR::HeterogeneousListBase::Link | |
virtual | ~Link () |
Friends | |
class | Environment |
class | boost::serialization::access |
class | Binding |
Mapping from Symbols to R objects.
A Frame defines a mapping from (pointers to) CXXR::Symbol objects to (pointers to) arbitrary objects of classes derived from RObject. A Frame is usually, but not necessarily, associated with an Frame object. Frame itself is an abstract class; for most purposes its embodiment StdFrame should be used.
typedef boost::any_range<const Binding, boost::forward_traversal_tag, const Binding&, std::ptrdiff_t> CXXR::Frame::BindingRange |
typedef void(* CXXR::Frame::monitor)(const Binding &) |
Function type for read and write monitors.
See the documentation for setReadMonitor() and setWriteMonitor().
|
inline |
Copy constructor.
The copy will define the same mapping from Symbols to R objects as source; neither the R objects, nor of course the Symbols, are copied as part of the cloning.
The copy will be locked if source is locked. However, the copy will not have a read or write monitor.
PairList* CXXR::Frame::asPairList | ( | ) | const |
Get contents as a PairList.
Access the contents of this Frame expressed as a PairList, with the tag of each PairList element representing a Symbol and the car value representing the object to which that Symbol is mapped, and with the Binding's active, locked and missing status indicated as in CR's FRAME() function.
|
inline |
Bind a Symbol to a specified value.
symbol | Non-null pointer to the Symbol to be bound or rebound. |
value | Pointer, possibly null, to the RObject to which symbol is now to be bound. Any previous binding of symbol is overwritten. |
origin | Origin of the newly bound value. |
Access binding of an already-defined Symbol.
This function provides a pointer to the Binding of a Symbol. In this variant the pointer is non-const, and consequently the calling code can use it to modify the Binding (provided the Binding is not locked).
symbol | The Symbol for which a mapping is sought. |
Implemented in CXXR::StdFrame.
Access const binding of an already-defined Symbol.
This function provides a pointer to a PairList element representing the binding of a symbol. In this variant the pointer is const, and consequently the calling code can use it only to examine the binding.
symbol | The Symbol for which a mapping is sought. |
Implemented in CXXR::StdFrame.
|
pure virtual |
Obtain a BindingRange for this Frame.
Implemented in CXXR::StdFrame.
void CXXR::Frame::clear | ( | ) |
|
pure virtual |
Return pointer to a copy of this Frame.
This function creates a copy of this Frame, and returns a pointer to that copy. The copy will define the same mapping from Symbols to R objects as this Frame; neither the R objects, nor of course the Symbols, are copied as part of the cloning.
The created copy will be locked if this Frame is locked. However, it will not have a read or write monitor.
Implemented in CXXR::StdFrame.
|
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()).
Reimplemented from CXXR::GCNode.
void CXXR::Frame::enableReadMonitoring | ( | bool | on | ) | const |
Enable monitored reading of Symbol values.
This function determines whether the read monitor function set with setReadMonitor() will be called whenever a Symbol's value is read from a Binding within this Frame.
In the case of an active Binding, the monitor is called whenever the encapsulated function is accessed: note that this includes calls to Binding::assign().
on | True if monitoring is be enabled (in which case a read monitor must already have been set), false if it is to be disabled. |
void CXXR::Frame::enableWriteMonitoring | ( | bool | on | ) | const |
Enable monitored writing of Symbol values.
This function determines whether the write monitor function set with setWriteMonitor() will be called whenever a Symbol's value is modified a Binding within this Frame.
In the case of an active Binding, the monitor is called only when the encapsulated function is initially set or changed: in particular the monitor is not invoked by calls to Binding::assign().
The monitor is not called when a Binding is newly created within a Frame (with the Symbol bound by default to a null pointer).
on | True if monitoring is be enabled (in which case a write monitor must already have been set), false if it is to be disabled. |
bool CXXR::Frame::erase | ( | const Symbol * | symbol | ) |
|
inline |
|
inline |
Lock this Frame.
Locking a Frame prevents the addition or removal of Bindings. Optionally, the existing bindings can be locked, preventing them from being modified.
This operation is permitted even if the Frame is already locked, but will have no effect unless it newly locks the Bindings in the Frame.
lock_bindings | true iff all the existing Bindings in the Frame are to be locked. |
|
pure virtual |
Lock all Bindings in this Frame.
This operation affects only Bindings currently existing. It does not prevent Bindings being added subsequently, and such Bindings will not be locked.
It is permitted to apply this function to a locked Frame.
Implemented in CXXR::StdFrame.
Get or create a Binding for a Symbol.
If the Frame already contains a Binding for a specified Symbol, the function returns it. Otherwise a Binding to the null pointer is created, and a pointer to that Binding returned.
An error is raised if a new Binding needs to be created and the Frame is locked.
Define function to monitor reading of Symbol values.
This function allows the user to define a function to be called whenever a Symbol's value is read from a Binding within a Frame. Even if such a function has been defined, the monitoring is off by default: it must be enabled for particular Frame objects by calling enableReadMonitoring(). See the description of enableReadMonitoring() for further information.
new_monitor | Pointer, possibly null, to the new monitor function. A null pointer signifies that no read monitoring is to take place, which is the default state. |
Define function to monitor writing of Symbol values.
This function allows the user to define a function to be called whenever a Symbol's value is modified in a Binding within a Frame. Even if such a function has been defined, the monitoring is off by default: it must be enabled for particular Frame objects by calling enableWriteMonitoring(). See the description of enableWriteMonitoring() for further information.
new_monitor | Pointer, possibly null, to the new monitor function. A null pointer signifies that no read monitoring is to take place, which is the default state. |
|
pure virtual |
Number of Bindings in Frame.
Implemented in CXXR::StdFrame.
|
inlineprotected |
std::vector<const Symbol*> CXXR::Frame::symbols | ( | bool | include_dotsymbols | ) | 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.
v | Pointer to the visitor object. |
Reimplemented from CXXR::GCNode.