[Rcpp-commits] r369 - in pkg: inst src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 13 09:19:09 CET 2010


Author: romain
Date: 2010-01-13 09:19:09 +0100 (Wed, 13 Jan 2010)
New Revision: 369

Added:
   pkg/src/Rcpp/VectorBase.h
   pkg/src/VectorBase.cpp
Modified:
   pkg/inst/ChangeLog
   pkg/src/GenericVector.cpp
   pkg/src/IntegerVector.cpp
   pkg/src/Rcpp/GenericVector.h
   pkg/src/Rcpp/IntegerVector.h
Log:
+Rcpp::VectorBase

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-13 07:50:10 UTC (rev 368)
+++ pkg/inst/ChangeLog	2010-01-13 08:19:09 UTC (rev 369)
@@ -1,11 +1,18 @@
 2010-01-13  Romain Francois <francoisromain at free.fr>
 
+	* src/Rcpp/VectorBase.h: new virtual class Rcpp::VectorBase
+	to manage common things of all vectors (length, names, etc ...)
+
 	* src/Rcpp/Environment.h: Environment::Binding gains a templated
 	conversion operator, to facilitate distance 2 implicit conversion
 	making this possible: 
 	Environment env("package:stats") ;
 	Function f = env["rnorm"] ;
 
+	* src/Rcpp/GenericVector.h: GenericVector::Proxy gains an 
+	assignement operator to deal with Environment::Binding. This is
+	to work around distance 1 implicit conversion restrictions
+
 	* src/Rcpp/NumericVector.h: operator[], begiun and end are
 	promoted to inline member functions
 	* src/Rcpp/IntegerVector.h: idem

Modified: pkg/src/GenericVector.cpp
===================================================================
--- pkg/src/GenericVector.cpp	2010-01-13 07:50:10 UTC (rev 368)
+++ pkg/src/GenericVector.cpp	2010-01-13 08:19:09 UTC (rev 369)
@@ -89,6 +89,11 @@
 	return *this ;
 }
 
+GenericVector::Proxy& GenericVector::Proxy::operator=( const Environment::Binding& rhs){
+	SET_VECTOR_ELT( parent, index, rhs ) ;
+	return *this ;
+}
+
 const GenericVector::Proxy GenericVector::operator[](int i) const throw(index_out_of_bounds){
 	if( i<0 || i>=length()) throw index_out_of_bounds() ;
 	return Proxy(const_cast<GenericVector&>(*this), i) ;

Modified: pkg/src/IntegerVector.cpp
===================================================================
--- pkg/src/IntegerVector.cpp	2010-01-13 07:50:10 UTC (rev 368)
+++ pkg/src/IntegerVector.cpp	2010-01-13 08:19:09 UTC (rev 369)
@@ -26,7 +26,7 @@
 
 namespace Rcpp{
 	
-	IntegerVector::IntegerVector(SEXP x) throw(not_compatible) : RObject() {
+	IntegerVector::IntegerVector(SEXP x) throw(not_compatible) : VectorBase() {
 		switch( TYPEOF( x ) ){
 			case INTSXP:
 				setSEXP( x ) ;
@@ -41,7 +41,7 @@
 		}
 	}
 	
-	IntegerVector::IntegerVector(int size) : RObject() {
+	IntegerVector::IntegerVector(int size) : VectorBase() {
 		setSEXP( Rf_allocVector(INTSXP, size) ) ;
 	}
 

Modified: pkg/src/Rcpp/GenericVector.h
===================================================================
--- pkg/src/Rcpp/GenericVector.h	2010-01-13 07:50:10 UTC (rev 368)
+++ pkg/src/Rcpp/GenericVector.h	2010-01-13 08:19:09 UTC (rev 369)
@@ -24,6 +24,7 @@
 
 #include <RcppCommon.h>
 #include <Rcpp/RObject.h>
+#include <Rcpp/Environment.h>
 
 #ifdef HAS_INIT_LISTS
 #include <initializer_list>
@@ -49,6 +50,7 @@
 			SET_VECTOR_ELT( parent, index, wrap(rhs) ) ;
 			return *this; 
 		}
+		Proxy& operator=( const Environment::Binding& rhs) ;
 		
 		/* rvalue use */
 		operator SEXP() const ;

Modified: pkg/src/Rcpp/IntegerVector.h
===================================================================
--- pkg/src/Rcpp/IntegerVector.h	2010-01-13 07:50:10 UTC (rev 368)
+++ pkg/src/Rcpp/IntegerVector.h	2010-01-13 08:19:09 UTC (rev 369)
@@ -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 IntegerVector : public RObject {     
+class IntegerVector : public VectorBase {     
 public:
 
 	IntegerVector(SEXP x) throw(not_compatible);
@@ -42,18 +43,8 @@
 	IntegerVector( std::initializer_list<int> list ) ;
 	IntegerVector( std::initializer_list<double> 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 int& operator[]( int i ) const{ return INTEGER(m_sexp)[i] } ;
+
+	inline int& operator[]( int i ) const{ return INTEGER(m_sexp)[i] ; }
 	inline int* begin() const { return INTEGER(m_sexp) ; }
 	inline int* end() const { return INTEGER(m_sexp) + LENGTH(m_sexp) ; }
 	

Added: pkg/src/Rcpp/VectorBase.h
===================================================================
--- pkg/src/Rcpp/VectorBase.h	                        (rev 0)
+++ pkg/src/Rcpp/VectorBase.h	2010-01-13 08:19:09 UTC (rev 369)
@@ -0,0 +1,50 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// VectorBase.h: Rcpp R/C++ interface class library -- base class for all vectors
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp_VectorBase_h
+#define Rcpp_VectorBase_h
+
+#include <RcppCommon.h>
+#include <Rcpp/RObject.h>
+
+namespace Rcpp{ 
+
+class VectorBase : public RObject {     
+public:
+	
+	VectorBase() ;
+	virtual ~VectorBase() = 0;
+	
+	/**
+	 * 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 ) ; }
+	
+} ;
+
+} // namespace
+
+#endif

Added: pkg/src/VectorBase.cpp
===================================================================
--- pkg/src/VectorBase.cpp	                        (rev 0)
+++ pkg/src/VectorBase.cpp	2010-01-13 08:19:09 UTC (rev 369)
@@ -0,0 +1,30 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// VectorBase.h: Rcpp R/C++ interface class library -- base vector class
+//
+// Copyright (C) 2010	Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#include <RcppCommon.h>
+#include <Rcpp/RObject.h>
+#include <Rcpp/VectorBase.h>
+
+namespace Rcpp{
+	VectorBase::VectorBase(): RObject(){} ;
+	VectorBase::~VectorBase(){}
+
+} // namespace 



More information about the Rcpp-commits mailing list