[Rcpp-commits] r4093 - in pkg/Rcpp: . inst/include inst/include/Rcpp inst/include/Rcpp/api inst/include/Rcpp/api/meat inst/include/Rcpp/macros src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 5 23:39:34 CET 2012


Author: romain
Date: 2012-12-05 23:39:33 +0100 (Wed, 05 Dec 2012)
New Revision: 4093

Added:
   pkg/Rcpp/inst/include/Rcpp/api/
   pkg/Rcpp/inst/include/Rcpp/api/meat/
   pkg/Rcpp/inst/include/Rcpp/api/meat/RObject.h
   pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h
   pkg/Rcpp/inst/include/Rcpp/macros/debug.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp.h
   pkg/Rcpp/inst/include/Rcpp/RObject.h
   pkg/Rcpp/inst/include/Rcpp/exceptions.h
   pkg/Rcpp/inst/include/RcppCommon.h
   pkg/Rcpp/src/RObject.cpp
   pkg/Rcpp/src/debugging.cpp
Log:
separating RObject and implement templates using warp and as later

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/ChangeLog	2012-12-05 22:39:33 UTC (rev 4093)
@@ -7,6 +7,11 @@
         * include/Rcpp/iostream/Rstreambuf.h: make Rstreambuf a template
         * src/AttributesGen.cpp : include exceptions.h which was included 
         implicitely by Rostream.h before
+        * include/Rcpp/macros/debug.h : factor out the debugging macros
+        * include/Rcpp/api/meat/RObject.h : only declare templates that use
+        as and wrap. they are implemented later in the meat directory
+        * include/Rcpp/api/meat/meat.h: directory containing implementations
+        of templates using as and wrap
         
 2012-12-05  JJ Allaire <jj at rstudio.org>
 

Modified: pkg/Rcpp/inst/include/Rcpp/RObject.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/RObject.h	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/inst/include/Rcpp/RObject.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -2,7 +2,7 @@
 //
 // RObject.h: Rcpp R/C++ interface class library -- general R object wrapper
 //
-// Copyright (C) 2009 - 2011    Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2009 - 2012    Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -22,29 +22,15 @@
 #ifndef Rcpp_RObject_h
 #define Rcpp_RObject_h
 
-#include <RcppCommon.h>
+#define R_NO_REMAP
+#include <R.h>
+#include <Rcpp/macros/debug.h>
+#include <Rinternals.h>
+#include <vector>
+#include <string>
 
 namespace Rcpp{ 
 
-    namespace internal{
-     
-        class SEXPstack {
-        public:
-            SEXPstack() ;
-            void preserve( SEXP ) ;
-            void release( SEXP ) ;
-        private:
-            SEXP stack ;
-            SEXP* data ;
-            int len, top ;
-            
-            void grow( ) ;
-        } ;
-    
-    }
-    
-    
-    
     class RObject {
     public:
         
@@ -137,19 +123,16 @@
              *
              * @param rhs wrappable object
              */
-            template <typename T> AttributeProxy& operator=(const T& rhs){
-                set( wrap(rhs) ) ;
-                return *this ;
-            }
+            template <typename T> AttributeProxy& operator=(const T& rhs) ; 
                 
             /**
              * rhs use. Retrieves the current value for the target
              * attribute and structure it as a T object using as
              */
-            template <typename T> operator T() const {
-                return as<T>(get()) ;
-            }
-                
+            template <typename T> operator T() const ;
+            
+            inline operator SEXP() const { return get() ; }
+            
         private:
             const RObject& parent; 
             std::string attr_name ;
@@ -187,20 +170,16 @@
              *
              * @param rhs wrappable object
              */
-            template <typename T> SlotProxy& operator=(const T& rhs){
-                set( wrap(rhs) ) ;
-                return *this ;
-            }
+            template <typename T> SlotProxy& operator=(const T& rhs) ;
                 
             /**
              * rhs use. Retrieves the current value of the slot
              * and structures it as a T object. This only works 
              * when as<T> makes sense
              */ 
-            template <typename T> operator T() const {
-                return as<T>(get()) ;
-            }
-                
+            template <typename T> operator T() const ;
+            inline operator SEXP() const { return get() ; }
+            
         private:
             const RObject& parent; 
             std::string slot_name ;
@@ -284,15 +263,11 @@
     
     private:
 
-        //    static internal::SEXPstack PPstack ;
-        //    void preserve(){ if( m_sexp != R_NilValue ) PPstack.preserve(m_sexp) ; } 
-        //    void release() { if( m_sexp != R_NilValue ) PPstack.release(m_sexp) ; }
-
         void preserve(){ if( m_sexp != R_NilValue ) R_PreserveObject(m_sexp) ; }
         void release() { if( m_sexp != R_NilValue ) R_ReleaseObject(m_sexp) ; } 
     
-        virtual void update() {
-            RCPP_DEBUG_1( "RObject::update(SEXP = <%p> )", m_sexp ) ; 
+        virtual void update(){
+            RCPP_DEBUG_1( "RObject::update(SEXP = <%p> )", m_sexp ) 
         } ;
     
     };

Added: pkg/Rcpp/inst/include/Rcpp/api/meat/RObject.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/RObject.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/RObject.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -0,0 +1,51 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// RObject.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2012    Dirk Eddelbuettel and 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_api_meat_RObject_h
+#define Rcpp_api_meat_RObject_h
+
+namespace Rcpp{ 
+
+    template <typename T> 
+    RObject::AttributeProxy& RObject::AttributeProxy::operator=( const T& rhs ){
+        set( wrap( rhs ) ) ;
+        return *this ;
+    }
+    
+    template <typename T>
+    RObject::AttributeProxy::operator T() const {
+        return as<T>(get()) ;    
+    }
+    
+    template <typename T> 
+    RObject::SlotProxy& RObject::SlotProxy::operator=( const T& rhs ){
+        set( wrap( rhs ) ) ;
+        return *this ;
+    }
+    template <typename T>
+    RObject::SlotProxy::operator T() const {
+        return as<T>(get()) ;    
+    }
+   
+    
+} // namespace Rcpp
+
+#endif

Added: pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -0,0 +1,27 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// backward.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2012    Dirk Eddelbuettel and 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_api_meat_backward_h
+#define Rcpp_api_meat_backward_h
+
+#include <Rcpp/api/meat/RObject.h>
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/exceptions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/exceptions.h	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/inst/include/Rcpp/exceptions.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -22,6 +22,8 @@
 #ifndef Rcpp__exceptions__h
 #define Rcpp__exceptions__h
 
+#include <sstream>
+
 namespace Rcpp{
 
 class exception : public std::exception {

Added: pkg/Rcpp/inst/include/Rcpp/macros/debug.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/macros/debug.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/macros/debug.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -0,0 +1,56 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// debug.h: Rcpp R/C++ interface class library -- debug macros
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and 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_macros_debug_h
+#define Rcpp_macros_debug_h
+
+// simple logging help
+#ifndef RCPP_DEBUG_LEVEL
+#define RCPP_DEBUG_LEVEL 0
+#endif
+
+#ifndef logTxt
+    #if RCPP_DEBUG_LEVEL > 0
+        #define logTxt(x) ::logTxtFunction(__FILE__, __LINE__, x);
+    #else
+        #define logTxt(x)
+    #endif
+#endif
+
+const char* short_file_name(const char* file) ;
+
+#if RCPP_DEBUG_LEVEL > 0
+    #define RCPP_DEBUG( MSG ) Rprintf( "%40s:%4d %s\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
+    #define RCPP_DEBUG_1( fmt, MSG ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
+    #define RCPP_DEBUG_2( fmt, M1, M2 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2 ) ;
+    #define RCPP_DEBUG_3( fmt, M1, M2, M3 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3) ;
+    #define RCPP_DEBUG_4( fmt, M1, M2, M3, M4 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3, M4) ;
+    #define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3, M4, M5) ;
+#else
+    #define RCPP_DEBUG( MSG )
+    #define RCPP_DEBUG_1( fmt, MSG )
+    #define RCPP_DEBUG_2( fmt, M1, M2 )
+    #define RCPP_DEBUG_3( fmt, M1, M2, M3 )
+    #define RCPP_DEBUG_4( fmt, M1, M2, M3, M4 )
+    #define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 )
+#endif
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp.h	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/inst/include/Rcpp.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -75,4 +75,6 @@
 // 'see' all versions of wrap
 #include <Rcpp/internal/wrap_end.h>
 
+#include <Rcpp/api/meat/meat.h>
+
 #endif

Modified: pkg/Rcpp/inst/include/RcppCommon.h
===================================================================
--- pkg/Rcpp/inst/include/RcppCommon.h	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/inst/include/RcppCommon.h	2012-12-05 22:39:33 UTC (rev 4093)
@@ -301,42 +301,8 @@
 
 } // namespace Rcpp
 
-// simple logging help
-#ifndef RCPP_DEBUG_LEVEL
-#define RCPP_DEBUG_LEVEL 0
-#endif
+#include <Rcpp/macros/debug.h>
 
-#ifndef logTxt
-    #if RCPP_DEBUG_LEVEL > 0
-        #define logTxt(x) ::logTxtFunction(__FILE__, __LINE__, x);
-    #else
-        #define logTxt(x)
-    #endif
-#endif
-
-inline const char* short_file_name(const char* file){
-    std::string f(file) ;
-    size_t index = f.find("/include/") ;
-    if( index != std::string::npos ){ f = f.substr( index + 9 ) ;}
-    return f.c_str() ;
-}
-
-#if RCPP_DEBUG_LEVEL > 0
-    #define RCPP_DEBUG( MSG ) Rprintf( "%40s:%4d %s\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
-    #define RCPP_DEBUG_1( fmt, MSG ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
-    #define RCPP_DEBUG_2( fmt, M1, M2 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2 ) ;
-    #define RCPP_DEBUG_3( fmt, M1, M2, M3 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3) ;
-    #define RCPP_DEBUG_4( fmt, M1, M2, M3, M4 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3, M4) ;
-    #define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3, M4, M5) ;
-#else
-    #define RCPP_DEBUG( MSG )
-    #define RCPP_DEBUG_1( fmt, MSG )
-    #define RCPP_DEBUG_2( fmt, M1, M2 )
-    #define RCPP_DEBUG_3( fmt, M1, M2, M3 )
-    #define RCPP_DEBUG_4( fmt, M1, M2, M3, M4 )
-    #define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 )
-#endif
-
 SEXP stack_trace( const char *file, int line) ;
 #define GET_STACKTRACE() stack_trace( __FILE__, __LINE__ )
 #define Rcpp_error(MESSAGE) throw Rcpp::exception( MESSAGE, __FILE__, __LINE__ ) 

Modified: pkg/Rcpp/src/RObject.cpp
===================================================================
--- pkg/Rcpp/src/RObject.cpp	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/src/RObject.cpp	2012-12-05 22:39:33 UTC (rev 4093)
@@ -2,7 +2,7 @@
 //
 // RObject.cpp: Rcpp R/C++ interface class library -- R Object support
 //
-// Copyright (C) 2009 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -19,49 +19,11 @@
 // You should have received a copy of the GNU General Public License
 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <RcppCommon.h>
 #include <Rcpp/RObject.h>
+#include <Rcpp/exceptions.h>
 
 namespace Rcpp {
-    namespace internal{
-
-        SEXPstack::SEXPstack() : 
-            stack( Rf_allocVector(VECSXP,1000) ), 
-            data( get_vector_ptr(stack) ), 
-            len( 1000 ), 
-            top( 0 )
-        {
-            R_PreserveObject( stack ) ;  
-        }
     
-        void SEXPstack::preserve( SEXP object){
-            if( top == len-1) grow() ;
-            SET_VECTOR_ELT( stack, top++, object ) ;
-        }
-    
-        void SEXPstack::release( SEXP object ){
-            int n = top - 1 ;
-            while( n > -1 && data[n] != object ) n-- ;
-            while( n < top - 1 ){ 
-                data[n] = data[n+1] ; 
-                n++ ;
-            }
-            data[--top] = R_NilValue ;
-        }
-    
-        void SEXPstack::grow( ){
-            int newsize = len * 2 ;
-            SEXP x = PROTECT( Rf_allocVector( VECSXP, newsize ) ) ;
-            SEXP* x_data = get_vector_ptr( x) ;
-            std::copy( data, data + len, x_data ) ;
-            stack = x ;
-            UNPROTECT(1);
-            data = x_data ;
-        }
-    }
-
-    // internal::SEXPstack RObject::PPstack ;    
-    
     void RObject::setSEXP(SEXP x){
         RCPP_DEBUG_1( "RObject::setSEXP(SEXP = <%p> )", x ) ; 
     

Modified: pkg/Rcpp/src/debugging.cpp
===================================================================
--- pkg/Rcpp/src/debugging.cpp	2012-12-05 21:42:32 UTC (rev 4092)
+++ pkg/Rcpp/src/debugging.cpp	2012-12-05 22:39:33 UTC (rev 4093)
@@ -21,6 +21,15 @@
 
 #include <Rcpp.h>
 
+#include <string>
+
+const char* short_file_name(const char* file){
+    std::string f(file) ;
+    size_t index = f.find("/include/") ;
+    if( index != std::string::npos ){ f = f.substr( index + 9 ) ;}
+    return f.c_str() ;
+}
+
 #if defined(__GNUC__)
 #if defined(WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__)
 // Simpler version for Windows and *BSD 



More information about the Rcpp-commits mailing list