CXXR (C++ R) API
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
CXXR::FixedVector< T, ST, Initializer > Class Template Reference

R data vector primarily intended for fixed-size use. More...

#include <FixedVector.hpp>

Inheritance diagram for CXXR::FixedVector< T, ST, Initializer >:
Inheritance graph
[legend]
Collaboration diagram for CXXR::FixedVector< T, ST, Initializer >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T value_type
typedef T * iterator
typedef const T * const_iterator

Public Member Functions

 FixedVector (std::size_t sz)
 Create a vector, leaving its contents uninitialized (for POD types) or default constructed.
template<typename U >
 FixedVector (std::size_t sz, const U &fill_value)
 Create a vector, and fill with a specified initial value.
template<typename V >
 FixedVector (const V &source, size_t index)
 Pick a single element from a vector.
 FixedVector (const FixedVector< T, ST, Initializer > &pattern)
 Copy constructor.
template<typename FwdIter >
 FixedVector (FwdIter from, FwdIter to)
 Constructor from range.
T & operator[] (unsigned int index)
 Element access.
const T & operator[] (unsigned int index) const
 Read-only element access.
iterator begin ()
 Iterator designating first element.
const_iterator begin () const
 Const iterator designating first element.
iterator end ()
 One-past-the-end iterator.
const_iterator end () const
 One-past-the-end const_iterator.
void setSize (std::size_t new_size)
 Adjust the number of elements in the vector.
FixedVector< T, ST, Initializer > * clone () const
 Return pointer to a copy of this object.
const char * typeName () const
 Name within R of this type of object.
void visitReferents (const_visitor *v) const
 Conduct a visitor to the nodes referred to by this one.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
template<>
const char * staticTypeName ()
 The name by which this type is known in R.
- Public Member Functions inherited from CXXR::VectorBase
 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.
std::size_t size () const
 Number of elements in the vector.
- 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 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

static const char * staticTypeName ()
 Name by which this type is known in R.
- Static Public Member Functions inherited from CXXR::VectorBase
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 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

 ~FixedVector ()
void detachReferents ()
 Null out all references from this node to other nodes.
- Protected Member Functions inherited from CXXR::VectorBase
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

Additional Inherited Members

- Public Attributes inherited from CXXR::VectorBase
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

Detailed Description

template<typename T, SEXPTYPE ST, typename Initializer>
class CXXR::FixedVector< T, ST, Initializer >

R data vector primarily intended for fixed-size use.

This is a general-purpose class template to represent an R data vector, and is intended particularly for the case where the size of the vector is fixed when it is constructed.

Having said that, the template does implement setSize(), primarily to service CR code's occasional use of SETLENGTH(); however, the implementation of this is rather inefficient.

CXXR implements all of CR's built-in vector types using this template.

Template Parameters:
TThe type of the elements of the vector.
STThe required SEXPTYPE of the vector.
Initializer(optional). Class of function object defining a static member function initialize(RObject*). (Any return value is discarded.) When a FixedVector object is constructed, this member function is applied to it. This can be used, for example, to apply an R class attribute etc. The default is to do nothing.

Constructor & Destructor Documentation

template<typename T, SEXPTYPE ST, typename Initializer>
CXXR::FixedVector< T, ST, Initializer >::FixedVector ( std::size_t  sz)
inline

Create a vector, leaving its contents uninitialized (for POD types) or default constructed.

Parameters:
szNumber of elements required. Zero is permissible.
template<typename T , SEXPTYPE ST, typename Initr >
template<typename U >
CXXR::FixedVector< T, ST, Initr >::FixedVector ( std::size_t  sz,
const U &  fill_value 
)

Create a vector, and fill with a specified initial value.

Template Parameters:
Utype assignable to T .
Parameters:
szNumber of elements required. Zero is permissible.
fill_valueInitial value to be assigned to every element.
template<typename T, SEXPTYPE ST, typename Initializer>
template<typename V >
CXXR::FixedVector< T, ST, Initializer >::FixedVector ( const V &  source,
size_t  index 
)
inline

Pick a single element from a vector.

This function creates a singleton vector, with its sole element initialized to be a copy of a specified element of another vector-like object.

Template Parameters:
VObject amenable to indexing using [], whose elements are of a type from which T objects can be constructed.
Parameters:
sourceV object from which an element is to be selected.
indexThe constructed object will be initialised from source[index].
template<typename T, SEXPTYPE ST, typename Initializer>
CXXR::FixedVector< T, ST, Initializer >::FixedVector ( const FixedVector< T, ST, Initializer > &  pattern)

Copy constructor.

Parameters:
patternFixedVector to be copied.
template<typename T , SEXPTYPE ST, typename Initr >
template<typename FwdIter >
CXXR::FixedVector< T, ST, Initr >::FixedVector ( FwdIter  from,
FwdIter  to 
)

Constructor from range.

Template Parameters:
Aniterator type, at least a forward iterator.
Parameters:
fromIterator designating the start of the range from which the FixedVector is to be constructed.
toIterator designating 'one past the end' of the range from which the FixedVector is to be constructed.
template<typename T, SEXPTYPE ST, typename Initializer>
CXXR::FixedVector< T, ST, Initializer >::~FixedVector ( )
inlineprotected

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


Member Function Documentation

template<typename T, SEXPTYPE ST, typename Initializer>
iterator CXXR::FixedVector< T, ST, Initializer >::begin ( )
inline

Iterator designating first element.

Returns:
An iterator designating the first element of the vector. Returns end() if the vector is empty.
template<typename T, SEXPTYPE ST, typename Initializer>
const_iterator CXXR::FixedVector< T, ST, Initializer >::begin ( ) const
inline

Const iterator designating first element.

Returns:
A const_iterator designating the first element of the vector. Returns end() if the vector is empty.
template<typename T , SEXPTYPE ST, typename Initr >
CXXR::FixedVector< T, ST, Initr > * CXXR::FixedVector< T, ST, Initr >::clone ( ) const
virtual

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::VectorBase.

template<typename T , SEXPTYPE ST, typename Initr >
void CXXR::FixedVector< T, ST, Initr >::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.

template<typename T, SEXPTYPE ST, typename Initializer>
iterator CXXR::FixedVector< T, ST, Initializer >::end ( )
inline

One-past-the-end iterator.

Returns:
An iterator designating a position 'one past the end' of the vector.
template<typename T, SEXPTYPE ST, typename Initializer>
const_iterator CXXR::FixedVector< T, ST, Initializer >::end ( ) const
inline

One-past-the-end const_iterator.

Returns:
A const_iterator designating a position 'one past the end' of the vector.
template<typename T, SEXPTYPE ST, typename Initializer>
T& CXXR::FixedVector< T, ST, Initializer >::operator[] ( unsigned int  index)
inline

Element access.

Parameters:
indexIndex of required element (counting from zero). No bounds checking is applied.
Returns:
Reference to the specified element.
template<typename T, SEXPTYPE ST, typename Initializer>
const T& CXXR::FixedVector< T, ST, Initializer >::operator[] ( unsigned int  index) const
inline

Read-only element access.

Parameters:
indexIndex of required element (counting from zero). No bounds checking is applied.
Returns:
const reference to the specified element.
template<typename T , SEXPTYPE ST, typename Initr >
void CXXR::FixedVector< T, ST, Initr >::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 from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< int, LGLSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< RHandle<>, VECSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< RHandle<>, EXPRSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< int, INTSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< double, REALSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< Rbyte, RAWSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< RHandle< String >, STRSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<>
const char * CXXR::FixedVector< Complex, CPLXSXP >::staticTypeName ( )
inline

The name by which this type is known in R.

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

Reimplemented from CXXR::VectorBase.

template<typename T, SEXPTYPE ST, typename Initializer>
static const char* CXXR::FixedVector< T, ST, Initializer >::staticTypeName ( )
static

Name by which this type is known in R.

Returns:
the name by which this type is known in R.
Note:
This function is declared but not defined as part of the FixedVector template. It must be defined as a specialization for each instantiation of the template for which it or typeName() is used.

Reimplemented from CXXR::VectorBase.

template<typename T , SEXPTYPE ST, typename Initr >
const char * CXXR::FixedVector< T, ST, Initr >::typeName ( ) const
virtual

Name within R of this type of object.

Returns:
the name by which this type of object is known within R.

Reimplemented from CXXR::RObject.

template<typename T , SEXPTYPE ST, typename Initr >
void CXXR::FixedVector< T, ST, Initr >::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: