[Rcpp-commits] r235 - in pkg: inst src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 30 14:48:14 CET 2009


Author: romain
Date: 2009-12-30 14:48:14 +0100 (Wed, 30 Dec 2009)
New Revision: 235

Added:
   pkg/src/Rcpp/
   pkg/src/Rcpp/RObject.h
   pkg/src/Rcpp/XPtr.h
Removed:
   pkg/src/Rcpp_RObject.h
   pkg/src/Rcpp_XPtr.h
Modified:
   pkg/inst/ChangeLog
   pkg/src/Makevars
   pkg/src/Makevars.win
   pkg/src/RObject.cpp
   pkg/src/Rcpp.h
Log:
include <Rcpp/RObject.h> instead of <Rcpp_RObject.h>

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/inst/ChangeLog	2009-12-30 13:48:14 UTC (rev 235)
@@ -1,5 +1,15 @@
 2009-12-30  Romain Francois <francoisromain at free.fr>
 
+	* src/Makevars* : adapt for allowong copy of the Rcpp directory
+	
+	* src/Rcpp_RObject.h: replace by src/Rcpp/RObject.h
+	
+	* src/Rcpp_XPtr.h: replaced by src/Rcpp/XPtr.h
+	
+	* src/*.cpp: adapt to the Rcpp directory
+
+2009-12-30  Romain Francois <francoisromain at free.fr>
+
 	* inst/unitTests/runit.RObject.R: new unit tests
 
 	* inst/unitTests/runit.exceptions.R: idem

Modified: pkg/src/Makevars
===================================================================
--- pkg/src/Makevars	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/src/Makevars	2009-12-30 13:48:14 UTC (rev 235)
@@ -29,8 +29,10 @@
 
 userLibrary: 	$(USERLIB) $(USERLIBST)
 		- at if test ! -e $(USERDIR)$(R_ARCH); then mkdir -p $(USERDIR)$(R_ARCH); fi
+		- at if test ! -e $(USERDIR)$(R_ARCH)/Rcpp; then mkdir -p $(USERDIR)$(R_ARCH)/Rcpp; fi
 		cp $(USERLIB) $(USERDIR)$(R_ARCH)
 		cp Rcpp*.h $(USERDIR)$(R_ARCH)
+		cp Rcpp/*.h $(USERDIR)$(R_ARCH)/Rcpp
 		cp $(USERLIBST) $(USERDIR)$(R_ARCH)
 		rm $(USERLIB) $(USERLIBST)
 

Modified: pkg/src/Makevars.win
===================================================================
--- pkg/src/Makevars.win	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/src/Makevars.win	2009-12-30 13:48:14 UTC (rev 235)
@@ -56,10 +56,11 @@
 		$(CXX) -shared -o $(PKGLIB) $(PKGOBJ) $(PKG_LIBS)
 
 $(USERLIB):	$(USEROBJ)
-		-mkdir -p $(USERDIR) 2>/dev/null
+		-mkdir -p $(USERDIR)/Rcpp 2>/dev/null
 		ar r $(USERLIB) $(USEROBJ)
 		ranlib $(USERLIB)
 		cp -vax Rcp*.h $(USERDIR)
+		cp -vax Rcpp/*.h $(USERDIR)/Rcpp
 
 
 

Modified: pkg/src/RObject.cpp
===================================================================
--- pkg/src/RObject.cpp	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/src/RObject.cpp	2009-12-30 13:48:14 UTC (rev 235)
@@ -20,7 +20,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <Rcpp_RObject.h>
+#include <Rcpp/RObject.h>
 #include <algorithm>
 
 namespace Rcpp {

Added: pkg/src/Rcpp/RObject.h
===================================================================
--- pkg/src/Rcpp/RObject.h	                        (rev 0)
+++ pkg/src/Rcpp/RObject.h	2009-12-30 13:48:14 UTC (rev 235)
@@ -0,0 +1,165 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Rcpp_RObject.h: Rcpp R/C++ interface class library -- super class of all R objects wrapped in C++ classes
+//
+// Copyright (C) 2009 - 2010	Dirk Eddelbuettel
+// Copyright (C) 2009 - 2010	Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp_RObject_h
+#define Rcpp_RObject_h
+
+#include <RcppCommon.h>
+#include <set>
+
+namespace Rcpp{ 
+
+class RObject{
+public:
+	
+	/**
+	 * wraps a SEXP. The SEXP is not automatically 
+	 * protected from garbage collection because it might be 
+	 * protected from elsewhere (e.g. if it comes from the 
+	 * R side). See protect and release for ways to protect
+	 * the SEXP from garbage collection, and release to 
+	 * remove the protection
+	 */
+	RObject(SEXP m_sexp = R_NilValue) : m_sexp(m_sexp) {};
+    
+    /**
+	 * if this object is protected rom R's GC, then it is released
+	 * and become subject to garbage collection. See protect 
+	 * and release member functions.
+	 */
+    ~RObject() ;
+	
+    RObject(const double & v);
+    RObject(const int & v);
+    RObject(const Rbyte & v);
+    RObject(const std::string & v);
+    RObject(const bool & v);
+    
+    RObject(const std::vector<int> & v);
+    RObject(const std::vector<double> & v);
+    RObject(const std::vector<std::string> & v);
+    RObject(const std::vector<Rbyte> & v);
+    RObject(const std::vector<bool> & v);
+    
+    RObject(const std::set<int> & v);
+    RObject(const std::set<double> & v);
+    RObject(const std::set<std::string> & v);
+    RObject(const std::set<Rbyte> & v);
+    
+    
+    /* we don't provide implicit converters because 
+       of Item 5 in More Effective C++ */
+    bool                     asBool() const;
+    double                   asDouble() const;
+    int                      asInt() const;
+    Rbyte                    asRaw() const;
+    std::string              asStdString() const;
+    std::vector<int>         asStdVectorInt() const;
+    std::vector<double>      asStdVectorDouble() const;
+    std::vector<std::string> asStdVectorString() const;
+    std::vector<Rbyte>       asStdVectorRaw() const;
+    std::vector<bool>        asStdVectorBool() const;
+    
+    
+    /**
+	 * protects the wrapped SEXP from garbage collection. This 
+	 * calls the R_PreserveObject function on the underlying SEXP.
+	 *
+	 * Note that this does not use the PROTECT/UNPROTECT dance
+	 */
+	void protect();
+	
+	/**
+	 * explicitely release this object to R garbage collection. This
+	 * calls the R_ReleaseObject function on the underlying SEXP. 
+	 * This is automatically done by the destructor if we protected 
+	 * the SEXP (using the protect member function)
+	 */
+	void release();
+	
+	/**
+	 * implicit conversion to SEXP
+	 */
+	inline operator SEXP() const {
+		return m_sexp ;
+	}
+	
+	
+	/* attributes */
+	
+	/**
+	 * extracts the names of the attributes of the wrapped SEXP
+	 */
+    std::vector<std::string> attributeNames() const ;
+    
+    /**
+     * Identifies if the SEXP has the given attribute
+     */
+	bool hasAttribute( const std::string& attr) const ; 
+    
+    /**
+     * extract the given attribute
+     */
+    SEXP attr( const std::string& name) const  ;
+    
+    /**
+     * is this object NULL
+     */
+    inline bool isNULL() const{
+    	return m_sexp == R_NilValue ;
+    }
+    
+    /**
+     * The SEXP typeof, calls TYPEOF on the underlying SEXP
+     */
+    inline int sexp_type() const {
+    	return TYPEOF(m_sexp) ;
+    }
+    
+    /** 
+	 * explicit conversion to SEXP
+	 */
+	inline SEXP asSexp() const {
+		return m_sexp ;
+	}
+	
+protected:
+	
+	/**
+	 * The SEXP this is wrapping
+	 */
+	SEXP m_sexp ;
+	
+	/**
+	 * true if this protects the SEXP from garbage collection
+	 * using R_ReleaseObject/R_PreserveObject strategy
+	 *
+	 * if this is true then the object will be release and become
+	 * subject to R garbage collection when this object is deleted
+	 */
+	bool isProtected ;    
+    
+};
+
+} // namespace Rcpp
+
+#endif

Added: pkg/src/Rcpp/XPtr.h
===================================================================
--- pkg/src/Rcpp/XPtr.h	                        (rev 0)
+++ pkg/src/Rcpp/XPtr.h	2009-12-30 13:48:14 UTC (rev 235)
@@ -0,0 +1,129 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// XPtr.h: Rcpp R/C++ interface class library -- smart external pointers
+//
+// Copyright (C) 2009 - 2010	Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef Rcpp_XPtr_h
+#define Rcpp_XPtr_h
+
+#include <RcppCommon.h>
+#include <Rcpp/RObject.h>
+
+namespace Rcpp{
+
+template <typename T>
+void delete_finalizer(SEXP p){
+	if( TYPEOF(p) == EXTPTRSXP ){
+		T* ptr = (T*) EXTPTR_PTR(p) ;
+		delete ptr ;
+	}
+}
+
+template <typename T>
+class XPtr : public RObject {
+	public:
+		
+		/** 
+		 * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
+		 *
+		 * @param xp external pointer to wrap
+		 */
+		 explicit XPtr(SEXP m_sexp) : RObject::RObject(m_sexp){} ;
+		
+		/**
+		 * creates a new external pointer wrapping the dumb pointer p. 
+		 * This calls R_PreserveObject to prevent the external pointer 
+		 * from R garbage collection
+		 * 
+		 * @param p dumb pointer to some object
+		 * @param set_delete_finalizer if set to true, a finalizer will 
+		 *        be registered for the external pointer. The finalizer
+		 *        is called when the xp is garbage collected. The finalizer 
+		 *        is merely a call to the delete operator or the pointer
+		 *        so you need to make sure the pointer can be deleted. 
+		 */
+  		explicit XPtr(T* p, bool set_delete_finalizer) ;
+
+  		/**
+  		 * Returns a reference to the object wrapped. This allows this
+  		 * object to look and feel like a dumb pointer to T
+  		 */
+  		T& operator*() const ;
+  		
+  		/**
+  		 * Returns the dumb pointer. This allows to call the -> operator 
+  		 * on this as if it was the dumb pointer
+  		 */
+  		T* operator->() const ;
+  		
+  		/**
+  		 * Returns the 'protected' part of the external pointer, this is 
+  		 * the SEXP that is passed in as the third argument of the 
+  		 * R_MakeExternalPointer function. See Writing R extensions
+  		 */
+  		SEXP getProtected() ;
+  		
+  		/** 
+  		 * Returns the 'tag' part of the external pointer, this is the 
+  		 * SEXP that is passed in as the 2nd argument of the 
+  		 * R_MakeExternalPointer function. See Writing R extensions
+  		 */
+  		SEXP getTag() ;
+  		
+  		void setDeleteFinalizer() ;
+  		
+};
+
+template<typename T>
+XPtr<T>::XPtr(T* p, bool set_delete_finalizer = true) : RObject::RObject() {
+	m_sexp = R_MakeExternalPtr( (void*)p , R_NilValue, R_NilValue) ;
+	if( set_delete_finalizer ){
+		setDeleteFinalizer() ;
+	}
+	protect() ;
+}
+
+template<typename T>
+void XPtr<T>::setDeleteFinalizer(){
+	R_RegisterCFinalizerEx( m_sexp, delete_finalizer<T> , FALSE) ; 
+}
+
+template<typename T>
+T& XPtr<T>::operator*() const {
+	return *((T*)EXTPTR_PTR( m_sexp )) ;
+}
+
+template<typename T>
+T* XPtr<T>::operator->() const {
+	return (T*)(EXTPTR_PTR(m_sexp));
+}
+
+template<typename T>
+SEXP XPtr<T>::getProtected(){
+	return EXTPTR_PROT(m_sexp) ;
+}
+
+template<typename T>
+SEXP XPtr<T>::getTag(){
+	return EXTPTR_TAG(m_sexp) ;
+}
+
+} // namespace Rcpp 
+
+#endif

Modified: pkg/src/Rcpp.h
===================================================================
--- pkg/src/Rcpp.h	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/src/Rcpp.h	2009-12-30 13:48:14 UTC (rev 235)
@@ -42,7 +42,7 @@
 #include <RcppVectorView.h>
 
 /* new api */
-#include <Rcpp_RObject.h>
-#include <Rcpp_XPtr.h>
+#include <Rcpp/RObject.h>
+#include <Rcpp/XPtr.h>
 
 #endif

Deleted: pkg/src/Rcpp_RObject.h
===================================================================
--- pkg/src/Rcpp_RObject.h	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/src/Rcpp_RObject.h	2009-12-30 13:48:14 UTC (rev 235)
@@ -1,165 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// Rcpp_RObject.h: Rcpp R/C++ interface class library -- super class of all R objects wrapped in C++ classes
-//
-// Copyright (C) 2009 - 2010	Dirk Eddelbuettel
-// Copyright (C) 2009 - 2010	Romain Francois
-//
-// This file is part of Rcpp.
-//
-// Rcpp is free software: you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// (at your option) any later version.
-//
-// Rcpp is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef Rcpp_RObject_h
-#define Rcpp_RObject_h
-
-#include <RcppCommon.h>
-#include <set>
-
-namespace Rcpp{ 
-
-class RObject{
-public:
-	
-	/**
-	 * wraps a SEXP. The SEXP is not automatically 
-	 * protected from garbage collection because it might be 
-	 * protected from elsewhere (e.g. if it comes from the 
-	 * R side). See protect and release for ways to protect
-	 * the SEXP from garbage collection, and release to 
-	 * remove the protection
-	 */
-	RObject(SEXP m_sexp = R_NilValue) : m_sexp(m_sexp) {};
-    
-    /**
-	 * if this object is protected rom R's GC, then it is released
-	 * and become subject to garbage collection. See protect 
-	 * and release member functions.
-	 */
-    ~RObject() ;
-	
-    RObject(const double & v);
-    RObject(const int & v);
-    RObject(const Rbyte & v);
-    RObject(const std::string & v);
-    RObject(const bool & v);
-    
-    RObject(const std::vector<int> & v);
-    RObject(const std::vector<double> & v);
-    RObject(const std::vector<std::string> & v);
-    RObject(const std::vector<Rbyte> & v);
-    RObject(const std::vector<bool> & v);
-    
-    RObject(const std::set<int> & v);
-    RObject(const std::set<double> & v);
-    RObject(const std::set<std::string> & v);
-    RObject(const std::set<Rbyte> & v);
-    
-    
-    /* we don't provide implicit converters because 
-       of Item 5 in More Effective C++ */
-    bool                     asBool() const;
-    double                   asDouble() const;
-    int                      asInt() const;
-    Rbyte                    asRaw() const;
-    std::string              asStdString() const;
-    std::vector<int>         asStdVectorInt() const;
-    std::vector<double>      asStdVectorDouble() const;
-    std::vector<std::string> asStdVectorString() const;
-    std::vector<Rbyte>       asStdVectorRaw() const;
-    std::vector<bool>        asStdVectorBool() const;
-    
-    
-    /**
-	 * protects the wrapped SEXP from garbage collection. This 
-	 * calls the R_PreserveObject function on the underlying SEXP.
-	 *
-	 * Note that this does not use the PROTECT/UNPROTECT dance
-	 */
-	void protect();
-	
-	/**
-	 * explicitely release this object to R garbage collection. This
-	 * calls the R_ReleaseObject function on the underlying SEXP. 
-	 * This is automatically done by the destructor if we protected 
-	 * the SEXP (using the protect member function)
-	 */
-	void release();
-	
-	/**
-	 * implicit conversion to SEXP
-	 */
-	inline operator SEXP() const {
-		return m_sexp ;
-	}
-	
-	
-	/* attributes */
-	
-	/**
-	 * extracts the names of the attributes of the wrapped SEXP
-	 */
-    std::vector<std::string> attributeNames() const ;
-    
-    /**
-     * Identifies if the SEXP has the given attribute
-     */
-	bool hasAttribute( const std::string& attr) const ; 
-    
-    /**
-     * extract the given attribute
-     */
-    SEXP attr( const std::string& name) const  ;
-    
-    /**
-     * is this object NULL
-     */
-    inline bool isNULL() const{
-    	return m_sexp == R_NilValue ;
-    }
-    
-    /**
-     * The SEXP typeof, calls TYPEOF on the underlying SEXP
-     */
-    inline int sexp_type() const {
-    	return TYPEOF(m_sexp) ;
-    }
-    
-    /** 
-	 * explicit conversion to SEXP
-	 */
-	inline SEXP asSexp() const {
-		return m_sexp ;
-	}
-	
-protected:
-	
-	/**
-	 * The SEXP this is wrapping
-	 */
-	SEXP m_sexp ;
-	
-	/**
-	 * true if this protects the SEXP from garbage collection
-	 * using R_ReleaseObject/R_PreserveObject strategy
-	 *
-	 * if this is true then the object will be release and become
-	 * subject to R garbage collection when this object is deleted
-	 */
-	bool isProtected ;    
-    
-};
-
-} // namespace Rcpp
-
-#endif

Deleted: pkg/src/Rcpp_XPtr.h
===================================================================
--- pkg/src/Rcpp_XPtr.h	2009-12-30 13:31:44 UTC (rev 234)
+++ pkg/src/Rcpp_XPtr.h	2009-12-30 13:48:14 UTC (rev 235)
@@ -1,129 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// XPtr.h: Rcpp R/C++ interface class library -- smart external pointers
-//
-// Copyright (C) 2009 - 2010	Romain Francois
-//
-// This file is part of Rcpp.
-//
-// Rcpp is free software: you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// (at your option) any later version.
-//
-// Rcpp is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef Rcpp_XPtr_h
-#define Rcpp_XPtr_h
-
-#include <RcppCommon.h>
-#include <Rcpp_RObject.h>
-
-namespace Rcpp{
-
-template <typename T>
-void delete_finalizer(SEXP p){
-	if( TYPEOF(p) == EXTPTRSXP ){
-		T* ptr = (T*) EXTPTR_PTR(p) ;
-		delete ptr ;
-	}
-}
-
-template <typename T>
-class XPtr : public RObject {
-	public:
-		
-		/** 
-		 * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
-		 *
-		 * @param xp external pointer to wrap
-		 */
-		 explicit XPtr(SEXP m_sexp) : RObject::RObject(m_sexp){} ;
-		
-		/**
-		 * creates a new external pointer wrapping the dumb pointer p. 
-		 * This calls R_PreserveObject to prevent the external pointer 
-		 * from R garbage collection
-		 * 
-		 * @param p dumb pointer to some object
-		 * @param set_delete_finalizer if set to true, a finalizer will 
-		 *        be registered for the external pointer. The finalizer
-		 *        is called when the xp is garbage collected. The finalizer 
-		 *        is merely a call to the delete operator or the pointer
-		 *        so you need to make sure the pointer can be deleted. 
-		 */
-  		explicit XPtr(T* p, bool set_delete_finalizer) ;
-
-  		/**
-  		 * Returns a reference to the object wrapped. This allows this
-  		 * object to look and feel like a dumb pointer to T
-  		 */
-  		T& operator*() const ;
-  		
-  		/**
-  		 * Returns the dumb pointer. This allows to call the -> operator 
-  		 * on this as if it was the dumb pointer
-  		 */
-  		T* operator->() const ;
-  		
-  		/**
-  		 * Returns the 'protected' part of the external pointer, this is 
-  		 * the SEXP that is passed in as the third argument of the 
-  		 * R_MakeExternalPointer function. See Writing R extensions
-  		 */
-  		SEXP getProtected() ;
-  		
-  		/** 
-  		 * Returns the 'tag' part of the external pointer, this is the 
-  		 * SEXP that is passed in as the 2nd argument of the 
-  		 * R_MakeExternalPointer function. See Writing R extensions
-  		 */
-  		SEXP getTag() ;
-  		
-  		void setDeleteFinalizer() ;
-  		
-};
-
-template<typename T>
-XPtr<T>::XPtr(T* p, bool set_delete_finalizer = true) : RObject::RObject() {
-	m_sexp = R_MakeExternalPtr( (void*)p , R_NilValue, R_NilValue) ;
-	if( set_delete_finalizer ){
-		setDeleteFinalizer() ;
-	}
-	protect() ;
-}
-
-template<typename T>
-void XPtr<T>::setDeleteFinalizer(){
-	R_RegisterCFinalizerEx( m_sexp, delete_finalizer<T> , FALSE) ; 
-}
-
-template<typename T>
-T& XPtr<T>::operator*() const {
-	return *((T*)EXTPTR_PTR( m_sexp )) ;
-}
-
-template<typename T>
-T* XPtr<T>::operator->() const {
-	return (T*)(EXTPTR_PTR(m_sexp));
-}
-
-template<typename T>
-SEXP XPtr<T>::getProtected(){
-	return EXTPTR_PROT(m_sexp) ;
-}
-
-template<typename T>
-SEXP XPtr<T>::getTag(){
-	return EXTPTR_TAG(m_sexp) ;
-}
-
-} // namespace Rcpp 
-
-#endif



More information about the Rcpp-commits mailing list