CXXR (C++ R)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Friends
CXXR::VectorBase Class Reference

Untemplated base class for R vectors. More...

#include <VectorBase.h>

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

List of all members.

Public Member Functions

 VectorBase (SEXPTYPE stype, std::size_t sz)
 VectorBase (const VectorBase &pattern)
 Copy constructor.
const ListVectordimensionNames () const
 Names associated with the rows, columns or other dimensions of an R matrix or array.
const StringVectordimensionNames (unsigned int d) const
 Names associated with a particular dimension of an R matrix or array.
const IntVectordimensions () const
 Dimensions of R matrix or array.
const StringVectornames () const
 Names of vector elements.
void setDimensionNames (ListVector *names)
 Associate names with the rows, columns or other dimensions of an R matrix or array.
void setDimensionNames (unsigned int d, StringVector *names)
 Associate names with a particular dimension of an R matrix or array.
void setDimensions (IntVector *dims)
 Define the dimensions of R matrix or array.
void setNames (StringVector *names)
 Associate names with the elements of a VectorBase.
virtual void setSize (std::size_t new_size)
 Adjust the number of elements in the vector.
std::size_t size () const
 Number of elements in the vector.
VectorBaseclone () const
 Return pointer to a copy of this object.
- Public Member Functions inherited from CXXR::RObject
virtual const PairListattributes () const
 Get object attributes.
virtual void clearAttributes ()
 Remove all attributes.
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.
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?

Static Public Member Functions

template<class V >
static V * resize (const V *pattern, std::size_t new_size)
 Create an extended or shrunken copy of an R vector.
static PairListresizeAttributes (const PairList *attributes, std::size_t new_size)
 Adjust attributes for a resized vector.
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.

Public Attributes

R_len_t m_truelength
- 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

Protected Member Functions

void adjustSize (std::size_t new_size)
 Adjust the number of elements in the vector.
- 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

Detailed Description

Untemplated base class for R vectors.


Constructor & Destructor Documentation

CXXR::VectorBase::VectorBase ( SEXPTYPE  stype,
std::size_t  sz 
)
inline
Parameters:
stypeThe required SEXPTYPE.
szThe required number of elements in the vector.
CXXR::VectorBase::VectorBase ( const VectorBase pattern)
inline

Copy constructor.

Parameters:
patternVectorBase to be copied.

Member Function Documentation

void CXXR::VectorBase::adjustSize ( std::size_t  new_size)
inlineprotected

Adjust the number of elements in the vector.

Used by derived classes to modify the recorded size of the vector, and to adjust its attributes accordingly.

Parameters:
new_sizeNew size required.
VectorBase* CXXR::VectorBase::clone ( ) const
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.

Returns:
a pointer to a clone of this object, or a null pointer if this object cannot be cloned.
Note:
Derived classes should exploit the covariant return type facility to return a pointer to the type of object being cloned.

Reimplemented from CXXR::RObject.

Reimplemented in CXXR::FixedVector< T, ST, Initializer >.

const ListVector * VectorBase::dimensionNames ( ) const

Names associated with the rows, columns or other dimensions of an R matrix or array.

Returns:
A null pointer signifies that there are no names associated with any of the dimensions of *this ; a null pointer will always be returned if *this is not an R matrix or array. Otherwise the return value will be a pointer to ListVector with as many elements as *this has dimensions. Each element of the ListVector is either a null pointer, signifying that there are no names associated with the corresponding dimension, or a pointer to a StringVector with as many elements as the size of the array along the corresponding dimension, giving the names of the 'slices' along that dimension. For example the zeroth element of the ListVector, if non-null, will give the row names, and the following element will give the column names.
const StringVector * VectorBase::dimensionNames ( unsigned int  d) const

Names associated with a particular dimension of an R matrix or array.

Parameters:
dDimension number (counting from 1) for which dimension names are required. Must be non-zero (not checked).
Returns:
A null pointer if no names are associated with dimension d of *this , if *this does not have as many as d dimensions, or if *this is not an R matrix or array. Otherwise a pointer to a StringVector with as many elements as the size of *this along the corresponding dimension, giving the names of the 'slices' along that dimension.
const IntVector * VectorBase::dimensions ( ) const

Dimensions of R matrix or array.

Returns:
A null pointer if *this is not an R matrix or array. Otherwise a pointer to an IntVector with one or more elements, the product of the elements being equal to the number of elements in *this . The number of elements in the return value is the dimensionality of the array (e.g. 2 for a matrix), and each element gives the size of the array along the respective dimension.
const StringVector * VectorBase::names ( ) const

Names of vector elements.

Returns:
either a null pointer (if the elements do not have names), or a pointer to a StringVector with the same number of elements as *this .
template<class V >
V * CXXR::VectorBase::resize ( const V *  pattern,
std::size_t  new_size 
)
static

Create an extended or shrunken copy of an R vector.

Template Parameters:
VA type inheriting from VectorBase.
Parameters:
patternNon-null pointer to the vector to be copied.
new_sizeRequired size of the copy, which may be smaller than, equal to or larger than the current size. Zero is permissible.
Returns:
Pointer to the copied vector. If new_size is smaller than the size of pattern , supernumerary elements at the end of pattern are not included in the copy. If new_size is greater than the size of pattern, extra elements are appended to the result and set to the NA value of V::value_type . If pattern has a names attribute, then the result is given a names attribute obtained by recursively applying this resize() function to the names of pattern . Other attributes are copied across by calling copyAttributesOnResize().
PairList * VectorBase::resizeAttributes ( const PairList attributes,
std::size_t  new_size 
)
static

Adjust attributes for a resized vector.

When a vector is resized (either by VectorBase::resize() or VectorBase::setSize() ), this function is used to determine the attributes of the resized vector. 'dim' and 'dimnames' attributes are discarded, and any 'names' attribute is itself resized. Other attributes are carried across unchanged.

Parameters:
attributesPointer, possibly null, to the attribute list of the original vector.
new_sizeSize of the resized vector.
Returns:
attribute list (possibly null) for the resized vector.
void VectorBase::setDimensionNames ( ListVector names)

Associate names with the rows, columns or other dimensions of an R matrix or array.

Parameters:
namesIf this is a null pointer, any names currently associated with the dimensions of *this will be removed. Otherwise names must be a pointer to ListVector with as many elements as *this has dimensions. Each element of the ListVector must be either a null pointer, signifying that no names are to be associated with the corresponding dimension, or a pointer to a StringVector with as many elements as the size of the array along the corresponding dimension, giving the names to be given to the 'slices' along that dimension. For example the zeroth element of the ListVector, if non-null, will give the row names, and the following element will give the column names. *this will assume ownership of this ListVector (rather than duplicating it), so the calling code must not subsequently modify it.
void VectorBase::setDimensionNames ( unsigned int  d,
StringVector names 
)

Associate names with a particular dimension of an R matrix or array.

Parameters:
dDimension number (counting from 1) with which dimension names are to be associated. Must not be greater than the * number of dimensions of *this (checked).
namesIf this is a null pointer, any names currently associated with dimension d of *this are removed. Otherwise names must be a pointer to a StringVector with as many elements as the size of *this along the corresponding dimension, giving the names to be given to the 'slices' along that dimension. *this will assume ownership of this StringVector (rather than duplicating it), so the calling code must not subsequently modify it.
void VectorBase::setDimensions ( IntVector dims)

Define the dimensions of R matrix or array.

As a side-effect, this function will remove any dimension names.

Parameters:
dimsIf this is a null pointer, any existing dimensions associated will be removed, and *this will cease to be a R matrix/array. Otherwise dims must be a pointer to an IntVector with one or more elements, the product of the elements being equal to the number of elements in *this . The number of elements in dims is the required dimensionality of the array (e.g. 2 for a matrix), and each element gives the required size of the array along the respective dimension. *this will assume ownership of this IntVector (rather than duplicating it), so the calling code must not subsequently modify it.
void VectorBase::setNames ( StringVector names)

Associate names with the elements of a VectorBase.

Parameters:
namesEither a null pointer, in which case any existing names will be removed, or a pointer to a StringVector with the same number of elements as *this . *this will assume ownership of this StringVector (rather than duplicating it), so the calling code must not subsequently modify it.
void VectorBase::setSize ( std::size_t  new_size)
virtual

Adjust the number of elements in the vector.

The default implementation is simply to raise an error.

Parameters:
new_sizeNew size required. Zero is permissible. If the size is increased, the extra elements will be initialized with NA<T>(), where T is the element type.

Reimplemented in CXXR::FixedVector< T, ST, Initializer >.

std::size_t CXXR::VectorBase::size ( ) const
inline

Number of elements in the vector.

Returns:
The number of elements in the vector.
static const char* CXXR::VectorBase::staticTypeName ( )
inlinestatic

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