[Rcpp-commits] r3802 - in pkg/Rcpp: . inst/include inst/include/Rcpp inst/include/Rcpp/internal inst/include/Rcpp/traits
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Oct 21 18:42:31 CEST 2012
Author: romain
Date: 2012-10-21 18:42:30 +0200 (Sun, 21 Oct 2012)
New Revision: 3802
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/Module.h
pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
pkg/Rcpp/inst/include/Rcpp/traits/wrap_type_traits.h
pkg/Rcpp/inst/include/RcppCommon.h
Log:
support for wrap()ing module objects
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-10-21 15:09:01 UTC (rev 3801)
+++ pkg/Rcpp/ChangeLog 2012-10-21 16:42:30 UTC (rev 3802)
@@ -1,3 +1,10 @@
+2012-10-21 Romain Francois <romain at r-enthusiasts.com>
+
+ * include/Rcpp/traits/wrap_type_traits.h: support for wrapping module objects
+ * include/Rcpp/internal/wrap.h : idem
+ * include/Rcpp/Module.h: idem
+
+
2012-10-13 Dirk Eddelbuettel <edd at debian.org>
* DESCRIPTION: Release 0.9.15
Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h 2012-10-21 15:09:01 UTC (rev 3801)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h 2012-10-21 16:42:30 UTC (rev 3802)
@@ -2,7 +2,7 @@
//
// Module.h: Rcpp R/C++ interface class library -- Rcpp modules
//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -37,6 +37,15 @@
private:
T* ptr;
} ;
+
+ template <typename T>
+ class object {
+ public:
+ typedef T object_type ;
+ object( T* ptr_ ) : ptr(ptr_){}
+ operator T*(){ return ptr ; }
+ T* ptr ;
+ } ;
namespace internal {
template <typename Class>
Modified: pkg/Rcpp/inst/include/Rcpp/internal/wrap.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/internal/wrap.h 2012-10-21 15:09:01 UTC (rev 3801)
+++ pkg/Rcpp/inst/include/Rcpp/internal/wrap.h 2012-10-21 16:42:30 UTC (rev 3802)
@@ -650,6 +650,11 @@
}
template <typename T>
+inline SEXP wrap_dispatch( const T& object, ::Rcpp::traits::wrap_type_module_object_tag ){
+ return Rcpp::internal::make_new_object< typename T::object_type >( object.ptr ) ;
+}
+
+template <typename T>
inline SEXP wrap_dispatch_eigen( const T& object, ::Rcpp::traits::false_type){
return wrap_dispatch_unknown( object, typename ::Rcpp::traits::is_convertible<T,SEXP>::type() ) ;
}
Modified: pkg/Rcpp/inst/include/Rcpp/traits/wrap_type_traits.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/traits/wrap_type_traits.h 2012-10-21 15:09:01 UTC (rev 3801)
+++ pkg/Rcpp/inst/include/Rcpp/traits/wrap_type_traits.h 2012-10-21 16:42:30 UTC (rev 3802)
@@ -3,7 +3,7 @@
//
// wrap_type_traits.h: Rcpp R/C++ interface class library -- traits to help wrap
//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
@@ -37,6 +37,11 @@
struct wrap_type_unknown_tag{};
/**
+ * module objects. conversion done using make_new_object<>()
+ */
+struct wrap_type_module_object_tag{} ;
+
+/**
* Type trait that helps the dispatch of wrap to the proper method
*
* This builds a struct that contains a typedef called wrap_category
@@ -78,6 +83,9 @@
template <> struct wrap_type_traits<rcpp_ulong_long_type> { typedef wrap_type_primitive_tag wrap_category; } ;
#endif
+template <typename T> struct wrap_type_traits< Rcpp::object<T> > { typedef wrap_type_module_object_tag wrap_category; } ;
+
+
} // namespace traits
} // namespace Rcpp
#endif
Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h 2012-10-21 15:09:01 UTC (rev 3801)
+++ pkg/Rcpp/inst/include/RcppCommon.h 2012-10-21 16:42:30 UTC (rev 3802)
@@ -274,6 +274,13 @@
#endif
#endif
+namespace Rcpp{
+ template <typename T> class object ;
+ namespace internal{
+ template <typename Class> SEXP make_new_object( Class* ptr ) ;
+ }
+}
+
// DO NOT CHANGE THE ORDER OF THESE INCLUDES
#include <Rcpp/traits/integral_constant.h>
#include <Rcpp/traits/same_type.h>
More information about the Rcpp-commits
mailing list