[Rcpp-commits] r305 - in pkg: inst src src/Rcpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jan 7 18:55:03 CET 2010
Author: romain
Date: 2010-01-07 18:55:03 +0100 (Thu, 07 Jan 2010)
New Revision: 305
Modified:
pkg/inst/ChangeLog
pkg/src/Rcpp/wrap.h
pkg/src/wrap.cpp
Log:
make wrap dispatch to the appropriate C++ class
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-01-07 17:28:37 UTC (rev 304)
+++ pkg/inst/ChangeLog 2010-01-07 17:55:03 UTC (rev 305)
@@ -1,5 +1,10 @@
2010-01-07 Romain Francois <francoisromain at free.fr>
+ * src/Rcpp/wrap.h : now the result type of the various wrap
+ functions depends on the parameters. wrap( bool ) makes a
+ LogicalVector, etc ... wrap(SEXP) dispatches to the
+ appropriate Rcpp:: class depending on TYPEOF
+
* src/Rcpp/RObject.h: added methods "isS4", "slot"
and "hasSlot" to deal with S4 objects
* inst/unitTests/runit.S4.R: unit tests
Modified: pkg/src/Rcpp/wrap.h
===================================================================
--- pkg/src/Rcpp/wrap.h 2010-01-07 17:28:37 UTC (rev 304)
+++ pkg/src/Rcpp/wrap.h 2010-01-07 17:55:03 UTC (rev 305)
@@ -34,6 +34,7 @@
#include <Rcpp/NumericVector.h>
#include <Rcpp/LogicalVector.h>
#include <Rcpp/GenericVector.h>
+#include <Rcpp/CharacterVector.h>
namespace Rcpp{
@@ -41,30 +42,31 @@
RObject wrap(SEXP m_sexp) ;
-RObject wrap(const bool & v);
-RObject wrap(const double & v);
-RObject wrap(const int & v);
-RObject wrap(const char* const v);
-RObject wrap(const Rbyte & v);
-RObject wrap(const std::string & v);
+LogicalVector wrap(const bool & v);
+NumericVector wrap(const double & v);
+IntegerVector wrap(const int & v);
+CharacterVector wrap(const char* const v);
+RawVector wrap(const Rbyte & v);
+CharacterVector wrap(const std::string & v);
-RObject wrap(const std::vector<int> & v);
-RObject wrap(const std::vector<double> & v);
-RObject wrap(const std::vector<std::string> & v);
-RObject wrap(const std::vector<Rbyte> & v);
-RObject wrap(const std::vector<bool> & v);
+IntegerVector wrap(const std::vector<int> & v);
+NumericVector wrap(const std::vector<double> & v);
+CharacterVector wrap(const std::vector<std::string> & v);
+RawVector wrap(const std::vector<Rbyte> & v);
+LogicalVector wrap(const std::vector<bool> & v);
-RObject wrap(const std::set<int> & v);
-RObject wrap(const std::set<double> & v);
-RObject wrap(const std::set<std::string> & v);
-RObject wrap(const std::set<Rbyte> & v);
+IntegerVector wrap(const std::set<int> & v);
+NumericVector wrap(const std::set<double> & v);
+CharacterVector wrap(const std::set<std::string> & v);
+RawVector wrap(const std::set<Rbyte> & v);
#ifdef HAS_INIT_LISTS
IntegerVector wrap( std::initializer_list<int> list) ;
NumericVector wrap( std::initializer_list<double> list) ;
LogicalVector wrap( std::initializer_list<bool> list) ;
RawVector wrap(std::initializer_list<Rbyte> list) ;
-// List wrap( std::initializer_list<RObject> list) ;
+CharacterVector wrap(std::initializer_list<std::string> list );
+List wrap( std::initializer_list<RObject> list) ;
#endif
} // namespace Rcpp
Modified: pkg/src/wrap.cpp
===================================================================
--- pkg/src/wrap.cpp 2010-01-07 17:28:37 UTC (rev 304)
+++ pkg/src/wrap.cpp 2010-01-07 17:55:03 UTC (rev 305)
@@ -19,109 +19,153 @@
// 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/wrap.h>
-#include <Rcpp/Symbol.h>
-#include <Rcpp/Environment.h>
+#include <Rcpp.h>
+
#include <algorithm>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
#endif
+
+#include <Rcpp/pairlist.h>
+#include <Rcpp/grow.h>
+#include <Rcpp/wrap.h>
+#include <Rcpp/as.h>
+#include <Rcpp/RObject.h>
+#include <Rcpp/XPtr.h>
+#include <Rcpp/Environment.h>
+#include <Rcpp/Evaluator.h>
+#include <Rcpp/Symbol.h>
+#include <Rcpp/Language.h>
+#include <Rcpp/Named.h>
+#include <Rcpp/Pairlist.h>
+#include <Rcpp/Function.h>
#include <Rcpp/IntegerVector.h>
+#include <Rcpp/NumericVector.h>
#include <Rcpp/RawVector.h>
-#include <Rcpp/NumericVector.h>
#include <Rcpp/LogicalVector.h>
#include <Rcpp/GenericVector.h>
+#include <Rcpp/WeakReference.h>
+#include <Rcpp/CharacterVector.h>
+#include <Rcpp/ExpressionVector.h>
+#include <Rcpp/ComplexVector.h>
namespace Rcpp{
RObject wrap(SEXP m_sexp=R_NilValue){
switch( TYPEOF(m_sexp) ){
- case ENVSXP:
- return Environment(m_sexp);
case SYMSXP:
return Symbol(m_sexp) ;
+ case ENVSXP:
+ return Environment(m_sexp);
+ case LISTSXP:
+ case DOTSXP: /* maybe change this later */
+ return Pairlist(m_sexp);
+ case CLOSXP:
+ case SPECIALSXP: /* maybe change this later */
+ case BUILTINSXP: /* maybe change this later */
+ return Function(m_sexp);
+ case LANGSXP:
+ return Language(m_sexp);
+ case LGLSXP:
+ return LogicalVector(m_sexp);
+ case INTSXP:
+ return IntegerVector(m_sexp);
+ case REALSXP:
+ return NumericVector(m_sexp);
+ case CPLXSXP:
+ return ComplexVector(m_sexp);
+ case STRSXP:
+ return CharacterVector(m_sexp);
+ case VECSXP:
+ return List(m_sexp);
+ case EXPRSXP:
+ return ExpressionVector(m_sexp);
+ case WEAKREFSXP:
+ return WeakReference(m_sexp);
+ case RAWSXP:
+ return RawVector(m_sexp);
default:
break ;
}
+ /* for all other, just use RObject */
return RObject(m_sexp) ;
}
-RObject wrap(const bool & v){
+LogicalVector wrap(const bool & v){
logTxt("RObject from bool\n");
- RObject o(Rf_ScalarLogical(v));
+ LogicalVector o(Rf_ScalarLogical(v));
return o ;
}
-RObject wrap(const double & v){
+NumericVector wrap(const double & v){
logTxt("RObject from double\n");
- RObject o(Rf_ScalarReal(v));
+ NumericVector o(Rf_ScalarReal(v));
return o ;
}
-RObject wrap(const int & v){
+IntegerVector wrap(const int & v){
logTxt("RObject from int\n");
- RObject o(Rf_ScalarInteger(v));
+ IntegerVector o(Rf_ScalarInteger(v));
return o ;
}
-RObject wrap(const Rbyte & v){
+RawVector wrap(const Rbyte & v){
logTxt("RObject from raw\n");
- RObject o(Rf_ScalarRaw(v));
+ RawVector o(Rf_ScalarRaw(v));
return o ;
}
-RObject wrap( const char * const v){
+CharacterVector wrap( const char * const v){
return wrap( std::string(v) ) ;
}
-RObject wrap(const std::string & v){
+CharacterVector wrap(const std::string & v){
logTxt("RObject from std::string\n");
- RObject o(Rf_mkString(v.c_str()));
+ CharacterVector o(Rf_mkString(v.c_str()));
return o ;
}
-RObject wrap(const std::vector<bool> & v){
+LogicalVector wrap(const std::vector<bool> & v){
logTxt("RObject from bool vector\n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(LGLSXP, n) );
copy( v.begin(), v.end(), LOGICAL(m_sexp) ) ;
- RObject o(m_sexp) ;
+ LogicalVector o(m_sexp) ;
UNPROTECT(1) ; /* m_sexp now preserved by o */
return o ;
}
-RObject wrap(const std::vector<int> & v){
+IntegerVector wrap(const std::vector<int> & v){
logTxt("RObject from int vector\n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(INTSXP, n) );
copy( v.begin(), v.end(), INTEGER(m_sexp) ) ;
- RObject o(m_sexp) ;
+ IntegerVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
-RObject wrap(const std::vector<double> & v){
+NumericVector wrap(const std::vector<double> & v){
logTxt("RObject from double vector\n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(REALSXP, n) );
copy( v.begin(), v.end(), REAL(m_sexp) ) ;
- RObject o(m_sexp) ;
+ NumericVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
-RObject wrap(const std::vector<Rbyte> & v){
+RawVector wrap(const std::vector<Rbyte> & v){
logTxt("RObject from vector<Rbyte> \n");
int n = v.size();
SEXP m_sexp = PROTECT(Rf_allocVector(RAWSXP, n));
copy( v.begin(), v.end(), RAW(m_sexp) ) ;
- RObject o(m_sexp) ;
+ RawVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
-RObject wrap(const std::vector<std::string> & v){
+CharacterVector wrap(const std::vector<std::string> & v){
logTxt("RObject from std::string vector\n");
int n = v.size();
SEXP m_sexp = PROTECT(Rf_allocVector(STRSXP, n));
@@ -132,44 +176,44 @@
i++ ;
it++;
}
- RObject o(m_sexp) ;
+ CharacterVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
/* sets */
-RObject wrap(const std::set<int> & v){
+IntegerVector wrap(const std::set<int> & v){
logTxt("RObject from set<int>\n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(INTSXP, n) );
copy( v.begin(), v.end(), INTEGER(m_sexp) ) ;
- RObject o(m_sexp) ;
+ IntegerVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
-RObject wrap(const std::set<double> & v){
+NumericVector wrap(const std::set<double> & v){
logTxt("RObject from set<double>\n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(REALSXP, n) );
copy( v.begin(), v.end(), REAL(m_sexp) ) ;
- RObject o(m_sexp) ;
+ NumericVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
-RObject wrap(const std::set<Rbyte> & v){
+RawVector wrap(const std::set<Rbyte> & v){
logTxt("RObject from set<Rbyte> \n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(RAWSXP, n) );
copy( v.begin(), v.end(), RAW(m_sexp) ) ;
- RObject o(m_sexp) ;
+ RawVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
-RObject wrap(const std::set<std::string> & v){
+CharacterVector wrap(const std::set<std::string> & v){
logTxt("RObject from set<string>\n");
int n = v.size();
SEXP m_sexp = PROTECT( Rf_allocVector(STRSXP, n) );
@@ -180,42 +224,30 @@
i++ ;
it++;
}
- RObject o(m_sexp) ;
+ CharacterVector o(m_sexp) ;
UNPROTECT(1) ;
return o ;
}
#ifdef HAS_INIT_LISTS
IntegerVector wrap( std::initializer_list<int> list) {
- SEXP x = PROTECT( Rf_allocVector( INTSXP, list.size() ) ) ;
- std::copy( list.begin(), list.end(), INTEGER(x) ) ;
- UNPROTECT(1) ;
- return IntegerVector( x ) ;
+ return IntegerVector( list ) ;
}
NumericVector wrap( std::initializer_list<double> list) {
- SEXP x = PROTECT( Rf_allocVector( REALSXP, list.size() ) ) ;
- std::copy( list.begin(), list.end(), REAL(x) ) ;
- UNPROTECT(1) ;
- return NumericVector( x ) ;
+ return NumericVector( list ) ;
}
LogicalVector wrap( std::initializer_list<bool> list) {
- SEXP x = PROTECT( Rf_allocVector( LGLSXP, list.size() ) ) ;
- std::copy( list.begin(), list.end(), LOGICAL(x) ) ;
- UNPROTECT(1) ;
- return LogicalVector( x ) ;
+ return LogicalVector( list ) ;
}
RawVector wrap(std::initializer_list<Rbyte> list){
- SEXP x = PROTECT( Rf_allocVector( RAWSXP, list.size() ) ) ;
- std::copy( list.begin(), list.end(), RAW(x) ) ;
- UNPROTECT(1) ;
- return RawVector( x ) ;
+ return RawVector( list ) ;
}
-// List wrap( std::initializer_list<RObject> list){
-// SEXP x = PROTECT( Rf_allocVector( VECSXP, list.size() ) ) ;
-// std::copy( list.begin(), list.end(), VECTOR_PTR(x) ) ;
-// UNPROTECT(1) ;
-// return List( x ) ;
-// }
+CharacterVector wrap(std::initializer_list<std::string> list){
+ return CharacterVector( list ) ;
+}
+List wrap( std::initializer_list<RObject> list){
+ return List( list ) ;
+}
#endif
More information about the Rcpp-commits
mailing list