[Rcpp-commits] r370 - in pkg: inst src src/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 13 09:34:13 CET 2010
Author: romain
Date: 2010-01-13 09:34:13 +0100 (Wed, 13 Jan 2010)
New Revision: 370
Modified:
pkg/inst/ChangeLog
pkg/src/CharacterVector.cpp
pkg/src/ComplexVector.cpp
pkg/src/ExpressionVector.cpp
pkg/src/GenericVector.cpp
pkg/src/LogicalVector.cpp
pkg/src/NumericVector.cpp
pkg/src/RawVector.cpp
pkg/src/Rcpp/CharacterVector.h
pkg/src/Rcpp/ComplexVector.h
pkg/src/Rcpp/ExpressionVector.h
pkg/src/Rcpp/GenericVector.h
pkg/src/Rcpp/LogicalVector.h
pkg/src/Rcpp/NumericVector.h
pkg/src/Rcpp/RawVector.h
Log:
using VectorBase to reduce code size
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/inst/ChangeLog 2010-01-13 08:34:13 UTC (rev 370)
@@ -2,6 +2,7 @@
* src/Rcpp/VectorBase.h: new virtual class Rcpp::VectorBase
to manage common things of all vectors (length, names, etc ...)
+ all Vector classes now derive from VectorBase
* src/Rcpp/Environment.h: Environment::Binding gains a templated
conversion operator, to facilitate distance 2 implicit conversion
Modified: pkg/src/CharacterVector.cpp
===================================================================
--- pkg/src/CharacterVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/CharacterVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -26,7 +26,7 @@
namespace Rcpp{
- CharacterVector::CharacterVector(SEXP x) throw(not_compatible) : RObject() {
+ CharacterVector::CharacterVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case STRSXP:
setSEXP( x ) ;
@@ -42,15 +42,15 @@
}
}
- CharacterVector::CharacterVector(int size) : RObject() {
+ CharacterVector::CharacterVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(STRSXP, size) ) ;
}
- CharacterVector::CharacterVector( const std::string& x){
+ CharacterVector::CharacterVector( const std::string& x) : VectorBase() {
setSEXP( Rf_mkString(x.c_str()) ) ;
}
- CharacterVector::CharacterVector( const std::vector<std::string>& x){
+ CharacterVector::CharacterVector( const std::vector<std::string>& x): VectorBase() {
SEXP y = PROTECT( Rf_allocVector( STRSXP, x.size() ) );
int n = x.size() ;
std::vector<std::string>::const_iterator iter = x.begin() ;
@@ -62,7 +62,7 @@
}
#ifdef HAS_INIT_LISTS
- CharacterVector::CharacterVector( std::initializer_list<std::string> list ) {
+CharacterVector::CharacterVector( std::initializer_list<std::string> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( STRSXP, list.size() ) ) ;
const std::string *p = list.begin() ;
int n = list.size() ;
@@ -74,22 +74,6 @@
}
#endif
-SEXP CharacterVector::get( const int& i ) const {
- return STRING_ELT(m_sexp, i) ;
-}
-
-void CharacterVector::set( const int& i, const std::string& value ){
- SET_STRING_ELT(m_sexp,i, Rf_mkChar(value.c_str()) ) ;
-}
-
-// SEXP* CharacterVector::begin(){
-// return RCPP_VECTOR_PTR(m_sexp) ;
-// }
-//
-// SEXP* CharacterVector::end(){
-// return RCPP_VECTOR_PTR(m_sexp) + LENGTH(m_sexp) ;
-// }
-
/* proxy stuff */
CharacterVector::StringProxy::StringProxy(CharacterVector& v, int i) :
Modified: pkg/src/ComplexVector.cpp
===================================================================
--- pkg/src/ComplexVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/ComplexVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -26,7 +26,7 @@
namespace Rcpp{
- ComplexVector::ComplexVector(SEXP x) throw(not_compatible) : RObject() {
+ ComplexVector::ComplexVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case CPLXSXP:
setSEXP( x ) ;
@@ -42,12 +42,12 @@
}
}
- ComplexVector::ComplexVector(int size) : RObject() {
+ ComplexVector::ComplexVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(CPLXSXP, size) ) ;
}
#ifdef HAS_INIT_LISTS
- ComplexVector::ComplexVector( std::initializer_list<Rcomplex> list ) {
+ComplexVector::ComplexVector( std::initializer_list<Rcomplex> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( CPLXSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), COMPLEX(x) );
setSEXP(x) ;
@@ -55,15 +55,4 @@
}
#endif
-Rcomplex& ComplexVector::operator[]( int i ) const throw(index_out_of_bounds){
- if( i<0 || i>= length()) throw index_out_of_bounds() ;
- return COMPLEX(m_sexp)[i] ;
-}
-Rcomplex* ComplexVector::begin() const {
- return COMPLEX(m_sexp) ;
-}
-Rcomplex* ComplexVector::end() const {
- return COMPLEX(m_sexp) + LENGTH(m_sexp);
-}
-
} // namespace
Modified: pkg/src/ExpressionVector.cpp
===================================================================
--- pkg/src/ExpressionVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/ExpressionVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -28,7 +28,7 @@
namespace Rcpp{
- ExpressionVector::ExpressionVector(SEXP x) throw(not_compatible) : RObject() {
+ ExpressionVector::ExpressionVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case EXPRSXP:
setSEXP( x ) ;
@@ -46,12 +46,12 @@
}
}
- ExpressionVector::ExpressionVector(int size) : RObject() {
+ ExpressionVector::ExpressionVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(EXPRSXP, size) ) ;
}
#ifdef HAS_INIT_LISTS
- ExpressionVector::ExpressionVector( std::initializer_list<RObject> list ) {
+ ExpressionVector::ExpressionVector( std::initializer_list<RObject> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( EXPRSXP, list.size() ) ) ;
const RObject* p = list.begin() ;
for( size_t i=0; i<list.size() ; i++, p++){
@@ -62,16 +62,6 @@
}
#endif
-// SEXP* ExpressionVector::begin(){
-// return RCPP_VECTOR_PTR(m_sexp) ;
-// }
-//
-// SEXP* ExpressionVector::end(){
-// return RCPP_VECTOR_PTR(m_sexp) + LENGTH(m_sexp) ;
-// }
-
-/* proxy stuff */
-
ExpressionVector::Proxy::Proxy(ExpressionVector& v, int i) :
parent(v), index(i){}
Modified: pkg/src/GenericVector.cpp
===================================================================
--- pkg/src/GenericVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/GenericVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -28,7 +28,7 @@
namespace Rcpp{
- GenericVector::GenericVector(SEXP x) throw(not_compatible) : RObject() {
+ GenericVector::GenericVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case VECSXP:
setSEXP( x ) ;
@@ -46,12 +46,12 @@
}
}
- GenericVector::GenericVector(int size) : RObject() {
+ GenericVector::GenericVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(VECSXP, size) ) ;
}
#ifdef HAS_INIT_LISTS
- GenericVector::GenericVector( std::initializer_list<RObject> list ) {
+GenericVector::GenericVector( std::initializer_list<RObject> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( VECSXP, list.size() ) ) ;
const RObject* p = list.begin() ;
for( size_t i=0; i<list.size() ; i++, p++){
@@ -62,14 +62,6 @@
}
#endif
-// SEXP* GenericVector::begin(){
-// return RCPP_VECTOR_PTR(m_sexp) ;
-// }
-//
-// SEXP* GenericVector::end(){
-// return RCPP_VECTOR_PTR(m_sexp) + LENGTH(m_sexp) ;
-// }
-
/* proxy stuff */
GenericVector::Proxy::Proxy(GenericVector& v, int i) :
Modified: pkg/src/LogicalVector.cpp
===================================================================
--- pkg/src/LogicalVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/LogicalVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -26,7 +26,7 @@
namespace Rcpp{
- LogicalVector::LogicalVector(SEXP x) throw(not_compatible) : RObject() {
+ LogicalVector::LogicalVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case LGLSXP:
setSEXP( x ) ;
@@ -41,24 +41,24 @@
}
}
- LogicalVector::LogicalVector(int size) : RObject() {
+ LogicalVector::LogicalVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(LGLSXP, size) ) ;
}
#ifdef HAS_INIT_LISTS
- LogicalVector::LogicalVector( std::initializer_list<int> list ) {
+ LogicalVector::LogicalVector( std::initializer_list<int> list ) : VectorBase(){
SEXP x = PROTECT( Rf_allocVector( INTSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), INTEGER(x) );
setSEXP( Rf_coerceVector( x, LGLSXP ) ) ;
UNPROTECT( 1 ); /* x */
}
- LogicalVector::LogicalVector( std::initializer_list<Rboolean> list ) {
+ LogicalVector::LogicalVector( std::initializer_list<Rboolean> list ): VectorBase() {
SEXP x = PROTECT( Rf_allocVector( LGLSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), LOGICAL(x) );
setSEXP(x) ;
UNPROTECT( 1 ); /* x */
}
- LogicalVector::LogicalVector( std::initializer_list<bool> list ) {
+ LogicalVector::LogicalVector( std::initializer_list<bool> list ) : VectorBase(){
SEXP x = PROTECT( Rf_allocVector( LGLSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), LOGICAL(x) );
setSEXP(x) ;
Modified: pkg/src/NumericVector.cpp
===================================================================
--- pkg/src/NumericVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/NumericVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -25,7 +25,7 @@
namespace Rcpp{
- NumericVector::NumericVector(SEXP x) throw(not_compatible) : RObject() {
+ NumericVector::NumericVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case REALSXP:
setSEXP( x ) ;
@@ -40,18 +40,18 @@
}
}
- NumericVector::NumericVector(int size) : RObject() {
+ NumericVector::NumericVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(REALSXP, size) ) ;
}
#ifdef HAS_INIT_LISTS
- NumericVector::NumericVector( std::initializer_list<int> list ) {
+NumericVector::NumericVector( std::initializer_list<int> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( REALSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), REAL(x) );
setSEXP(x) ;
UNPROTECT( 1 ); /* x */
}
- NumericVector::NumericVector( std::initializer_list<double> list ) {
+ NumericVector::NumericVector( std::initializer_list<double> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( REALSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), REAL(x) );
setSEXP(x) ;
Modified: pkg/src/RawVector.cpp
===================================================================
--- pkg/src/RawVector.cpp 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/RawVector.cpp 2010-01-13 08:34:13 UTC (rev 370)
@@ -26,7 +26,7 @@
namespace Rcpp{
- RawVector::RawVector(SEXP x) throw(not_compatible) : RObject() {
+ RawVector::RawVector(SEXP x) throw(not_compatible) : VectorBase() {
switch( TYPEOF( x ) ){
case RAWSXP:
setSEXP( x ) ;
@@ -41,18 +41,18 @@
}
}
- RawVector::RawVector(int size) : RObject() {
+ RawVector::RawVector(int size) : VectorBase() {
setSEXP( Rf_allocVector(RAWSXP, size) ) ;
}
#ifdef HAS_INIT_LISTS
- RawVector::RawVector( std::initializer_list<int> list ) {
+ RawVector::RawVector( std::initializer_list<int> list ) : VectorBase() {
SEXP x = PROTECT( Rf_allocVector( RAWSXP, list.size() ) ) ;
std::copy( list.begin(), list.end(), RAW(x) );
setSEXP(x) ;
UNPROTECT( 1 ); /* x */
}
- RawVector::RawVector( std::initializer_list<Rbyte> list ) {
+ RawVector::RawVector( std::initializer_list<Rbyte> list ) : VectorBase() {
/* FIXME: we need to take care of coercion, so
transform is probably better */
SEXP x = PROTECT( Rf_allocVector( RAWSXP, list.size() ) ) ;
Modified: pkg/src/Rcpp/CharacterVector.h
===================================================================
--- pkg/src/Rcpp/CharacterVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/CharacterVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -24,6 +24,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -32,7 +33,7 @@
namespace Rcpp{
-class CharacterVector : public RObject {
+class CharacterVector : public VectorBase {
public:
/* much inspired from item 30 of more effective C++ */
@@ -56,37 +57,20 @@
int index ;
} ;
-
CharacterVector(SEXP x) throw(not_compatible);
CharacterVector(int size) ;
CharacterVector( const std::string& x );
CharacterVector( const std::vector<std::string>& x );
-
+
#ifdef HAS_INIT_LISTS
CharacterVector( std::initializer_list<std::string> list ) ;
#endif
-
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return Rf_length( m_sexp ) ; }
-
- /**
- * alias of length
- */
- inline int size() const { return Rf_length( m_sexp ) ; }
-
- SEXP get(const int& i) const ;
- void set(const int& i, const std::string& value ) ;
-
- SEXP* begin();
- SEXP* end() ;
-
+
const StringProxy operator[]( int i ) const throw(index_out_of_bounds);
StringProxy operator[]( int i ) throw(index_out_of_bounds);
-
+
friend class StringProxy;
-
+
} ;
typedef CharacterVector StringVector ;
Modified: pkg/src/Rcpp/ComplexVector.h
===================================================================
--- pkg/src/Rcpp/ComplexVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/ComplexVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -24,6 +24,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -32,7 +33,7 @@
namespace Rcpp{
-class ComplexVector : public RObject {
+class ComplexVector : public VectorBase {
public:
ComplexVector(SEXP x) throw(not_compatible);
@@ -42,20 +43,10 @@
ComplexVector( std::initializer_list<Rcomplex> list ) ;
#endif
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return Rf_length( m_sexp ) ; }
+ inline Rcomplex& operator[]( int i ) const { return COMPLEX(m_sexp)[i] ; }
+ inline Rcomplex* begin() const { return COMPLEX(m_sexp) ; }
+ inline Rcomplex* end() const { return COMPLEX(m_sexp) + LENGTH(m_sexp) ; }
- /**
- * alias of length
- */
- inline int size() const { return Rf_length( m_sexp ) ; }
-
- Rcomplex& operator[]( int i ) const throw(index_out_of_bounds) ;
- Rcomplex* begin() const ;
- Rcomplex* end() const ;
-
typedef Rcomplex* iterator ;
} ;
Modified: pkg/src/Rcpp/ExpressionVector.h
===================================================================
--- pkg/src/Rcpp/ExpressionVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/ExpressionVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -24,6 +24,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -32,7 +33,7 @@
namespace Rcpp{
-class ExpressionVector : public RObject {
+class ExpressionVector : public VectorBase {
public:
/* much inspired from item 30 of more effective C++ */
@@ -65,19 +66,6 @@
ExpressionVector( std::initializer_list<RObject> list ) ;
#endif
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return Rf_length( m_sexp ) ; }
-
- /**
- * alias of length
- */
- inline int size() const { return Rf_length( m_sexp ) ; }
-
- SEXP* begin();
- SEXP* end() ;
-
const Proxy operator[]( int i ) const throw(index_out_of_bounds);
Proxy operator[]( int i ) throw(index_out_of_bounds) ;
Modified: pkg/src/Rcpp/GenericVector.h
===================================================================
--- pkg/src/Rcpp/GenericVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/GenericVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -25,6 +25,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
#include <Rcpp/Environment.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -33,7 +34,7 @@
namespace Rcpp{
-class GenericVector : public RObject {
+class GenericVector : public VectorBase {
public:
/* much inspired from item 30 of more effective C++ */
@@ -68,19 +69,6 @@
GenericVector( std::initializer_list<RObject> list ) ;
#endif
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return Rf_length( m_sexp ) ; }
-
- /**
- * alias of length
- */
- inline int size() const { return Rf_length( m_sexp ) ; }
-
- // SEXP* begin();
- // SEXP* end() ;
-
const Proxy operator[]( int i ) const throw(index_out_of_bounds);
Proxy operator[]( int i ) throw(index_out_of_bounds) ;
Modified: pkg/src/Rcpp/LogicalVector.h
===================================================================
--- pkg/src/Rcpp/LogicalVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/LogicalVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -24,6 +24,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -32,7 +33,7 @@
namespace Rcpp{
-class LogicalVector : public RObject {
+class LogicalVector : public VectorBase {
public:
LogicalVector(SEXP x) throw(not_compatible);
@@ -44,16 +45,6 @@
LogicalVector( std::initializer_list<bool> list ) ;
#endif
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return Rf_length( m_sexp ) ; }
-
- /**
- * alias of length
- */
- inline int size() const { return Rf_length( m_sexp ) ; }
-
typedef int* iterator ;
inline int& operator[]( int i ) const { return LOGICAL(m_sexp)[i] ;}
Modified: pkg/src/Rcpp/NumericVector.h
===================================================================
--- pkg/src/Rcpp/NumericVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/NumericVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -24,6 +24,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -32,7 +33,7 @@
namespace Rcpp{
-class NumericVector : public RObject {
+class NumericVector : public VectorBase {
public:
NumericVector(SEXP x) throw(not_compatible);
@@ -42,25 +43,15 @@
NumericVector( std::initializer_list<int> list ) ;
NumericVector( std::initializer_list<double> list ) ;
#endif
-
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return LENGTH( m_sexp ) ; }
-
- /**
- * alias of length
- */
- inline int size() const { return LENGTH( m_sexp ) ; }
-
+
inline double& operator[]( const int& i ) { return REAL(m_sexp)[i]; }
inline const double& operator[]( const int& i ) const { return REAL(m_sexp)[i]; }
-
+
inline double* begin() const { return REAL(m_sexp) ; }
inline double* end() const { return REAL(m_sexp)+LENGTH(m_sexp);}
-
+
typedef double* iterator ;
-
+
} ;
} // namespace
Modified: pkg/src/Rcpp/RawVector.h
===================================================================
--- pkg/src/Rcpp/RawVector.h 2010-01-13 08:19:09 UTC (rev 369)
+++ pkg/src/Rcpp/RawVector.h 2010-01-13 08:34:13 UTC (rev 370)
@@ -24,6 +24,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -32,7 +33,7 @@
namespace Rcpp{
-class RawVector : public RObject {
+class RawVector : public VectorBase {
public:
RawVector(SEXP x) throw(not_compatible);
@@ -43,16 +44,6 @@
RawVector( std::initializer_list<int> list ) ;
#endif
- /**
- * the length of the vector, uses Rf_length
- */
- inline int length() const { return Rf_length( m_sexp ) ; }
-
- /**
- * alias of length
- */
- inline int size() const { return Rf_length( m_sexp ) ; }
-
inline Rbyte& operator[]( int i ) const { return RAW(m_sexp)[i] ; }
inline Rbyte* begin() const { return RAW(m_sexp) ; }
inline Rbyte* end() const { return RAW(m_sexp) + LENGTH(m_sexp) ; }
More information about the Rcpp-commits
mailing list