[Rcpp-commits] r3897 - in pkg/Rcpp: . inst/include/Rcpp inst/include/Rcpp/module

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 5 20:55:56 CET 2012


Author: romain
Date: 2012-11-05 20:55:56 +0100 (Mon, 05 Nov 2012)
New Revision: 3897

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/inst/include/Rcpp/module/class.h
Log:
property inheritance

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-05 18:36:29 UTC (rev 3896)
+++ pkg/Rcpp/ChangeLog	2012-11-05 19:55:56 UTC (rev 3897)
@@ -1,3 +1,9 @@
+2012-11-05  Romain Francois <romain at r-enthusiasts.com>
+
+        * include/Rcpp/Module.h: added class CppInheritedProperty to handle 
+        inherited properties
+        * include/Rcpp/module/class.h: implemented inheritance of properties
+
 2012-11-05  JJ Allaire <jj at rstudio.org>
 
         * R/Attributes.R: use modules for attribute code generation

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2012-11-05 18:36:29 UTC (rev 3896)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2012-11-05 19:55:56 UTC (rev 3897)
@@ -327,6 +327,25 @@
                 
         std::string docstring ;
     } ;
+    
+    template <typename Class, typename Parent>
+    class CppInheritedProperty : public CppProperty<Class> {
+    public:
+        typedef CppProperty<Class> Base ;
+        
+        CppInheritedProperty( CppProperty<Parent>* parent_property_ ) : 
+            Base( parent_property_->docstring.c_str() ), 
+            parent_property(parent_property_) 
+        {}
+        
+        SEXP get( Class* obj ){ return parent_property->get( (Parent*)obj ) ; }
+        void set( Class* obj, SEXP s) { parent_property->set( (Parent*)obj, s ) ; }
+        bool is_readonly(){ return parent_property->is_readonly() ; }
+        std::string get_class(){ return parent_property->get_class() ; }
+        
+    private:
+        CppProperty<Parent>* parent_property ;    
+    } ;
 
     template <typename Class>
     class CppFinalizer{ 

Modified: pkg/Rcpp/inst/include/Rcpp/module/class.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/class.h	2012-11-05 18:36:29 UTC (rev 3896)
+++ pkg/Rcpp/inst/include/Rcpp/module/class.h	2012-11-05 19:55:56 UTC (rev 3897)
@@ -483,7 +483,22 @@
                      AddMethod( method_name.c_str(), method,  signed_method->valid , signed_method->docstring.c_str() ) ;
                 }
             }
-                
+             
+            
+            // importing properties
+            typedef typename parent_class_::prop_class parent_prop_class ;
+            typedef typename parent_class_::PROPERTY_MAP parent_PROPERTY_MAP ;
+            typedef typename parent_PROPERTY_MAP::iterator parent_PROPERTY_MAP_iterator ;
+            
+            parent_PROPERTY_MAP_iterator parent_property_it = parent_class_pointer->properties.begin() ;
+            parent_PROPERTY_MAP_iterator parent_property_end = parent_class_pointer->properties.end() ;
+            for( ; parent_property_it != parent_property_end; parent_property_it++){
+                AddProperty( 
+                    parent_property_it->first.c_str(), 
+                    new CppInheritedProperty<Class,PARENT>( parent_property_it->second )
+                ) ;
+            }
+            
             return *this ;
         }
         



More information about the Rcpp-commits mailing list