[Rcpp-devel] [Rcpp-commits] r310 - in pkg: inst inst/unitTests src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 7 22:28:09 CET 2010


Author: romain
Date: 2010-01-07 22:28:05 +0100 (Thu, 07 Jan 2010)
New Revision: 310

Modified:
   pkg/inst/ChangeLog
   pkg/inst/unitTests/runit.Pairlist.R
   pkg/src/Rcpp/Pairlist.h
Log:
Pairlist gains push_front method

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-07 21:04:28 UTC (rev 309)
+++ pkg/inst/ChangeLog	2010-01-07 21:28:05 UTC (rev 310)
@@ -1,5 +1,7 @@
 2010-01-07  Romain Francois <francoisromain at free.fr>
 
+	* src/Rcpp/Pairlist.h: gains a push_front method
+
 	* 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 

Modified: pkg/inst/unitTests/runit.Pairlist.R
===================================================================
--- pkg/inst/unitTests/runit.Pairlist.R	2010-01-07 21:04:28 UTC (rev 309)
+++ pkg/inst/unitTests/runit.Pairlist.R	2010-01-07 21:28:05 UTC (rev 310)
@@ -52,3 +52,17 @@
 	}
 }
 
+test.Pairlist.push.front <- function(){
+	funx <- cfunction(signature(), '
+	Pairlist p ;
+	p.push_front( 1 ) ;
+	p.push_front( 10.0 ) ;
+	p.push_front( "foo" ) ;
+	p.push_front( Named( "foobar", 10) ) ;
+	return p ;
+	', Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
+	checkEquals( funx(), 
+		pairlist( foobar = 10, "foo", 10.0, 1L), 
+		msg = "Pairlist::push_front" )
+}
+

Modified: pkg/src/Rcpp/Pairlist.h
===================================================================
--- pkg/src/Rcpp/Pairlist.h	2010-01-07 21:04:28 UTC (rev 309)
+++ pkg/src/Rcpp/Pairlist.h	2010-01-07 21:28:05 UTC (rev 310)
@@ -28,9 +28,9 @@
 namespace Rcpp{ 
 
 /** 
- * C++ wrapper around calls (LANGSXP SEXP)
+ * C++ wrapper around pair lists (LISTSXP SEXP)
  *
- * This represents calls that can be evaluated
+ * This represents dotted pair lists
  */
 class Pairlist : public RObject{
 public:
@@ -64,6 +64,19 @@
 #endif	
 	
 	~Pairlist() ;
+	
+	/**
+	 * wraps an object and add it in front of the pairlist
+	 *
+	 * @param object anything that can be wrapped by one 
+	 * of the wrap functions, or an object of class Named
+	 */
+	template <typename T>
+	void push_front( const T& object){
+		setSEXP( grow(object, m_sexp) ) ;
+	}
+
+	
 };
 
 #ifdef HAS_VARIADIC_TEMPLATES
@@ -80,7 +93,6 @@
 	}
 #endif
 
-
 } // namespace Rcpp
 
 #endif

_______________________________________________
Rcpp-commits mailing list
Rcpp-commits at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-commits


More information about the Rcpp-devel mailing list