[Rcpp-commits] r4400 - in pkg/Rcpp: . inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 23 22:42:59 CEST 2013


Author: romain
Date: 2013-07-23 22:42:59 +0200 (Tue, 23 Jul 2013)
New Revision: 4400

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/src/attributes.cpp
Log:
attributes taking advantage of more flexible as<>

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-07-23 17:01:42 UTC (rev 4399)
+++ pkg/Rcpp/ChangeLog	2013-07-23 20:42:59 UTC (rev 4400)
@@ -8,6 +8,8 @@
         with as<T*> and as<const T*>
         * unitTests/runit.Module.R: testing as<T*> and as<const T*>
         * unitTests/cpp/Module.cpp: idem
+        * src/attributes.cpp: take advantage of a more flexible as<>. The Type
+        class gains a full_name() method that shows const-ness and reference-ness 
 
 2013-07-17  Romain Francois <romain at r-enthusiasts.com>
 

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-07-23 17:01:42 UTC (rev 4399)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-07-23 20:42:59 UTC (rev 4400)
@@ -10,7 +10,8 @@
       \item Add \code{#defined(__sun)} to lists of operating systems to
       test for when checking for lack of \code{backtrace()} needed for
       stack traces.
-      \item \code{as<T&>} and \code{as<const T&>} is now supported, when 
+      \item \code{as<T*>}, \code{as<const T*>}, \code{as<T&>} and
+      \code{as<const T&>} are now supported, when 
       T is a class exposed by modules, i.e. with \code{RCPP_EXPOSED_CLASS}
       \item \code{DoubleVector} as been added as an alias to 
       \code{NumericVector}
@@ -26,7 +27,12 @@
         in a file that is processed by \code{sourceCpp}) are now directly 
         available in the environment. We used to make the module object
         available, which was less useful.
-	\item A plugin for 'openmp' has been added to support use of OpenMP.
+        \item A plugin for 'openmp' has been added to support use of OpenMP.
+        \item \code{Rcpp::export} now takes advantage of the more flexible 
+        \code{as<>}, handling constness and referenceness of the input types. 
+        For users, it means that for the parameters of function exported by modules, 
+        we can now use references, pointers and const versions of them.
+        The Module.cpp file has an example. 
     }
 
     \item Changes in Modules:

Modified: pkg/Rcpp/src/attributes.cpp
===================================================================
--- pkg/Rcpp/src/attributes.cpp	2013-07-23 17:01:42 UTC (rev 4399)
+++ pkg/Rcpp/src/attributes.cpp	2013-07-23 20:42:59 UTC (rev 4400)
@@ -112,6 +112,13 @@
         bool empty() const { return name().empty(); }
         
         const std::string& name() const { return name_; }
+        std::string full_name() const {
+            std::string res ;
+            if( isConst() ) res += "const " ;
+            res += name() ;
+            if( isReference() ) res += "&" ;
+            return res ;
+        }
         
         bool isVoid() const { return name() == "void"; }
         bool isConst() const { return isConst_; }
@@ -1228,7 +1235,7 @@
         // if the type is now empty because of some strange parse then bail
         if (type.empty())
             return Type();
-            
+          
         return Type(type, isConst, isReference);
     }
     
@@ -2141,9 +2148,8 @@
             for (size_t i = 0; i<arguments.size(); i++) {
                 const Argument& argument = arguments[i];
                 
-                // Rcpp::as to c++ type
-                ostr << "        " << argument.type().name() << " " << argument.name() 
-                     << " = " << "Rcpp::as<"  << argument.type().name() << " >(" 
+                ostr << "        " << argument.type().full_name() << " " << argument.name() 
+                     << " = " << "Rcpp::as<"  << argument.type().full_name() << " >(" 
                      << argument.name() << "SEXP);" << std::endl;
             }
             



More information about the Rcpp-commits mailing list