[Rcpp-commits] r566 - in pkg: inst src src/Rcpp src/Rcpp/internal

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 4 13:08:45 CET 2010


Author: romain
Date: 2010-02-04 13:08:45 +0100 (Thu, 04 Feb 2010)
New Revision: 566

Modified:
   pkg/inst/ChangeLog
   pkg/src/Rcpp/DottedPair.h
   pkg/src/Rcpp/Function.h
   pkg/src/Rcpp/Language.h
   pkg/src/Rcpp/Pairlist.h
   pkg/src/Rcpp/grow.h
   pkg/src/Rcpp/internal/wrap.h
   pkg/src/grow.cpp
Log:
some code bloat to work around compilers without variadic templates

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/inst/ChangeLog	2010-02-04 12:08:45 UTC (rev 566)
@@ -1,5 +1,12 @@
-2010-02-03  Romain Francois <francoisromain at free.fr>
+2010-02-04  Romain Francois <francoisromain at free.fr>
 
+	* src/Rcpp/DottedPair.h: code bloat to allow creation of 
+	DottedPair containing up to 5 objects without variadic templates
+	RInside for example needs this. 
+	* src/Rcpp/Language.h: same
+	* src/Rcpp/Pairlist.h: same
+	* src/Rcpp/grow.h: same
+
 	* src/Rcpp/internal/wrap.h : one more level of dispatch to 
 	identify if there needs a cast between the primitive
 	iterated over and the target storage type. For example

Modified: pkg/src/Rcpp/DottedPair.h
===================================================================
--- pkg/src/Rcpp/DottedPair.h	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/Rcpp/DottedPair.h	2010-02-04 12:08:45 UTC (rev 566)
@@ -40,6 +40,29 @@
 	DottedPair( const Args&... args) : RObject() {
 		setSEXP( pairlist(args...) ) ;
 	}
+#else
+/* <code-bloat> */
+template <typename T1>
+DottedPair( const T1& t1) : RObject() {
+	setSEXP( pairlist(t1) );
+}
+template <typename T1, typename T2>
+DottedPair( const T1& t1, const T2& t2) : RObject(){
+	setSEXP( pairlist(t1,t2) ); 
+}
+template <typename T1, typename T2, typename T3>
+DottedPair( const T1& t1, const T2& t2, const T3& t3): RObject() {
+	setSEXP( pairlist(t1,t2,t3) );
+}
+template <typename T1, typename T2, typename T3, typename T4>
+DottedPair( const T1& t1, const T2& t2, const T3& t3, const T4& t4): RObject(){
+	setSEXP( pairlist(t1,t2,t3,t4) );
+}
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+DottedPair( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) : RObject() {
+	setSEXP( pairlist(t1,t2,t3,t4,t5) );
+}
+/* </code-bloat> */
 #endif	
 
 	/**

Modified: pkg/src/Rcpp/Function.h
===================================================================
--- pkg/src/Rcpp/Function.h	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/Rcpp/Function.h	2010-02-04 12:08:45 UTC (rev 566)
@@ -92,6 +92,29 @@
 	SEXP operator()( const Args&... args) /* throw(Evaluator::eval_error) */ {
 		return internal::try_catch( Rf_lcons( m_sexp, pairlist(args...) ) ) ;
 	}
+#else
+/* <code-bloat> */
+template <typename T1>
+SEXP operator()( const T1& t1){
+	return internal::try_catch( Rf_lcons( m_sexp, pairlist(t1) ) ) ;
+}
+template <typename T1, typename T2>
+SEXP operator()( const T1& t1, const T2& t2){
+	return internal::try_catch( Rf_lcons( m_sexp, pairlist(t1,t2) ) ) ;
+}
+template <typename T1, typename T2, typename T3>
+SEXP operator()( const T1& t1, const T2& t2, const T3& t3){
+		return internal::try_catch( Rf_lcons( m_sexp, pairlist(t1, t2, t3) ) ) ;
+}
+template <typename T1, typename T2, typename T3, typename T4>
+SEXP operator()( const T1& t1, const T2& t2, const T3& t3, const T4& t4){
+		return internal::try_catch( Rf_lcons( m_sexp, pairlist(t1,t2,t3,t4) ) ) ;
+}
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+SEXP operator()( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5){
+		return internal::try_catch( Rf_lcons( m_sexp, pairlist(t1,t2,t3,t4,t5) ) ) ;
+}
+/* </code-bloat> */
 #endif
 	
 	/**

Modified: pkg/src/Rcpp/Language.h
===================================================================
--- pkg/src/Rcpp/Language.h	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/Rcpp/Language.h	2010-02-04 12:08:45 UTC (rev 566)
@@ -103,6 +103,33 @@
 Language( const Function& function, const Args&... args) : DottedPair(function, args...) {
 	update() ;
 }
+#else
+/* <code-bloat> */
+template <typename T1> 
+Language( const std::string& symbol, const T1& t1) : DottedPair(symbol, t1) {} 
+
+template <typename T1, typename T2>
+Language( const std::string& symbol, const T1& t1, const T2& t2) : DottedPair(symbol, t1,t2){}
+
+template <typename T1, typename T2, typename T3>
+Language( const std::string& symbol, const T1& t1, const T2& t2, const T3& t3): DottedPair(symbol, t1,t2,t3) {}
+
+template <typename T1, typename T2, typename T3, typename T4>
+Language( const std::string& symbol, const T1& t1, const T2& t2, const T3& t3, const T4& t4): DottedPair(symbol, t1,t2,t3,t4){}
+
+
+template <typename T1> 
+Language( const Function& function, const T1& t1) : DottedPair(function, t1) {} 
+
+template <typename T1, typename T2>
+Language( const Function& function, const T1& t1, const T2& t2) : DottedPair(function, t1,t2){}
+
+template <typename T1, typename T2, typename T3>
+Language( const Function& function, const T1& t1, const T2& t2, const T3& t3): DottedPair(function, t1,t2,t3) {}
+
+template <typename T1, typename T2, typename T3, typename T4>
+Language( const Function& function, const T1& t1, const T2& t2, const T3& t3, const T4& t4): DottedPair(function, t1,t2,t3,t4){}
+/* </code-bloat> */
 #endif	
 	
 	/**

Modified: pkg/src/Rcpp/Pairlist.h
===================================================================
--- pkg/src/Rcpp/Pairlist.h	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/Rcpp/Pairlist.h	2010-02-04 12:08:45 UTC (rev 566)
@@ -36,7 +36,25 @@
 #ifdef HAS_VARIADIC_TEMPLATES
 template<typename... Args> 
 	Pairlist( const Args&... args) : DottedPair(args...) {}
-#endif	
+#else
+/* <code-bloat> */
+template <typename T1> 
+Pairlist( const T1& t1) : DottedPair(t1) {} 
+
+template <typename T1, typename T2>
+Pairlist( const T1& t1, const T2& t2) : DottedPair(t1,t2){}
+
+template <typename T1, typename T2, typename T3>
+Pairlist( const T1& t1, const T2& t2, const T3& t3): DottedPair(t1,t2,t3) {}
+
+template <typename T1, typename T2, typename T3, typename T4>
+Pairlist( const T1& t1, const T2& t2, const T3& t3, const T4& t4): DottedPair(t1,t2,t3,t4){}
+
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+Pairlist( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) : DottedPair(t1,t2,t3,t4,t5) {}
+/* </code-bloat> */
+#endif
+
 	~Pairlist() ;
 		
 } ;

Modified: pkg/src/Rcpp/grow.h
===================================================================
--- pkg/src/Rcpp/grow.h	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/Rcpp/grow.h	2010-02-04 12:08:45 UTC (rev 566)
@@ -41,6 +41,25 @@
 SEXP pairlist( const T& first, const Args&... args ){
 	return grow(first, pairlist(args...) ) ;
 }
+#else
+/* <code-bloat> */
+template <typename T1, typename T2>
+SEXP pairlist( const T1& t1, const T2& t2){
+	return grow(t1, grow(t2, R_NilValue) );
+}
+template <typename T1, typename T2, typename T3>
+SEXP pairlist( const T1& t1, const T2& t2, const T3& t3){
+	return grow(t1, grow(t2, grow(t3,R_NilValue)));
+}
+template <typename T1, typename T2, typename T3, typename T4>
+SEXP pairlist( const T1& t1, const T2& t2, const T3& t3, const T4& t4){
+	return grow(t1, grow(t2, grow(t3,grow(t4,R_NilValue))));
+}
+template <typename T1, typename T2, typename T3, typename T4, typename T5>
+SEXP pairlist( const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5){
+	return grow(t1, grow(t2, grow(t3,grow(t4, grow(t5,R_NilValue)))));
+}
+/* </code-bloat> */
 #endif
 	
 	
@@ -52,7 +71,7 @@
 SEXP grow(const T& head, SEXP tail){
 	return Rf_cons( wrap(head), tail ) ;
 }
-SEXP grow(const Named& head, SEXP tail) ;
+template<> SEXP grow<Named>(const Named& head, SEXP tail) ;
 
 
 } // namespace Rcpp

Modified: pkg/src/Rcpp/internal/wrap.h
===================================================================
--- pkg/src/Rcpp/internal/wrap.h	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/Rcpp/internal/wrap.h	2010-02-04 12:08:45 UTC (rev 566)
@@ -189,8 +189,8 @@
 	size_t i =0;
 	std::string buf ; 
 	for( ; i<size; i++, ++first){
-		start[i] = static_cast<CTYPE>( (*first).second );
-		buf = (*first).first ;
+		start[i] = static_cast<CTYPE>( first->second );
+		buf = first->first ;
 		SET_STRING_ELT( names, i, Rf_mkChar(buf.c_str()) ) ;
 	}
 	::Rf_setAttrib( x, R_NamesSymbol, names ) ;

Modified: pkg/src/grow.cpp
===================================================================
--- pkg/src/grow.cpp	2010-02-04 10:56:11 UTC (rev 565)
+++ pkg/src/grow.cpp	2010-02-04 12:08:45 UTC (rev 566)
@@ -25,7 +25,7 @@
 
 SEXP pairlist(){ return R_NilValue ; }
 
-SEXP grow(const Named& head, SEXP tail){
+template<> SEXP grow<Named>(const Named& head, SEXP tail){
 	SEXP x;
 	x = PROTECT( Rf_cons( head.getSEXP(), tail) ) ;
 	SET_TAG( x, Rf_install( head.getTag().c_str() ) ); 



More information about the Rcpp-commits mailing list