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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 31 13:54:38 CET 2012


Author: romain
Date: 2012-10-31 13:54:38 +0100 (Wed, 31 Oct 2012)
New Revision: 3867

Added:
   pkg/Rcpp/inst/include/Rcpp/module/class.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/src/Module.cpp
Log:
first attempt at implementing inheritance between exposed classes

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-10-31 07:42:53 UTC (rev 3866)
+++ pkg/Rcpp/ChangeLog	2012-10-31 12:54:38 UTC (rev 3867)
@@ -1,3 +1,12 @@
+2012-10-31  Romain Francois <romain at r-enthusiasts.com>
+
+        * include/Rcpp/module/class.h: factored out of Module.h which started to 
+        be too big. class_ gains a derives<Parent>( "Parent" ) for so that the 
+        class inherits method that were exposed by its parent. 
+        * include/Rcpp/Module.h: template class CppInheritedMethod for implementing
+        inherited method
+        * src/Module.cpp: get_class_pointer implementation
+        
 2012-10-30  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/Rcpp/Rmath.h: Finalised adding Rmath functions

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2012-10-31 07:42:53 UTC (rev 3866)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2012-10-31 12:54:38 UTC (rev 3867)
@@ -206,7 +206,8 @@
         }
                 
         Rcpp::CppClass get_class(const std::string& ) ;
-                
+        class_Base* get_class_pointer(const std::string& ) ;
+        
         std::string name ;
            
         void add_enum( const std::string& parent_class_typeinfo_name, const std::string& enum_name, const std::map<std::string, int>& value ) ;
@@ -236,6 +237,28 @@
         virtual bool is_const(){ return false ; }
         virtual void signature(std::string& s, const char* name ){ s = name ; }
     } ;
+    
+    template <typename Class, typename Parent>
+    class CppInheritedMethod : public CppMethod<Class> {
+    public:
+        typedef Rcpp::XPtr<Class> XP ;
+        typedef CppMethod<Parent> ParentMethod ;
+        
+        CppInheritedMethod( ParentMethod* parent_method_pointer_ ) : 
+            parent_method_pointer(parent_method_pointer_) 
+        {}
+        
+        SEXP operator()( Class* object, SEXP* args){
+			return (*parent_method_pointer)( (Parent*)object, args ) ;  
+		}
+		inline int nargs(){ return parent_method_pointer->nargs() ; }
+		inline bool is_void(){ return parent_method_pointer->is_void() ; }
+		inline bool is_const(){ return parent_method_pointer->is_const() ; }
+		inline void signature(std::string& s, const char* name){ return parent_method_pointer->signature(s, name) ; }
+		
+    private:
+        ParentMethod* parent_method_pointer ;
+    } ;
 
 #include <Rcpp/module/Module_generated_ctor_signature.h>
 #include <Rcpp/module/Module_generated_Constructor.h>
@@ -405,438 +428,8 @@
 
 #include <Rcpp/module/Module_Property.h>
 
-    template <typename Class>
-    class class_ : public class_Base {
-    public:
-        typedef class_<Class> self ;
-        typedef CppMethod<Class> method_class ;
-        
-        typedef SignedMethod<Class> signed_method_class ;
-        typedef std::vector<signed_method_class*> vec_signed_method ;
-        typedef std::map<std::string,vec_signed_method*> map_vec_signed_method ;
-        typedef std::pair<std::string,vec_signed_method*> vec_signed_method_pair ;
-        
-        typedef std::map<std::string,method_class*> METHOD_MAP ;
-        typedef std::pair<const std::string,method_class*> PAIR ;
-        
-        typedef Rcpp::XPtr<Class> XP ;
-        typedef CppFinalizer<Class> finalizer_class ;
-        
-        typedef Constructor_Base<Class> constructor_class ;
-        typedef SignedConstructor<Class> signed_constructor_class ;
-        typedef std::vector<signed_constructor_class*> vec_signed_constructor ;
-        
-        typedef Factory_Base<Class> factory_class ;
-        typedef SignedFactory<Class> signed_factory_class ;
-        typedef std::vector<signed_factory_class*> vec_signed_factory ;
-        
-        typedef CppProperty<Class> prop_class ;
-        typedef std::map<std::string,prop_class*> PROPERTY_MAP ;
-        typedef std::pair<const std::string,prop_class*> PROP_PAIR ;
-        
-        class_( const char* name_, const char* doc = 0) : 
-            class_Base(name_, 0), 
-            vec_methods(), 
-            properties(), 
-            finalizer_pointer(0), 
-            specials(0), 
-            constructors(),
-            factories(),
-            class_pointer(0), 
-            typeinfo_name("")
-        {
-            Rcpp::Module* module = getCurrentScope() ;
-            if( ! module->has_class(name_) ){
-                class_pointer = new self ;
-                class_pointer->name = name_ ;
-                class_pointer->docstring = std::string( doc == 0 ? "" : doc );
-                class_pointer->finalizer_pointer = new finalizer_class ;
-                class_pointer->typeinfo_name = typeid(Class).name() ;
-                module->AddClass( name_, class_pointer ) ;
-            }
-        }
-         
-        ~class_(){}
-        
-        self& AddConstructor( constructor_class* ctor, ValidConstructor valid, const char* docstring = 0 ){
-            class_pointer->constructors.push_back( new signed_constructor_class( ctor, valid, docstring ) );  
-            return *this ;
-        }
-        
-        self& AddFactory( factory_class* fact, ValidConstructor valid, const char* docstring = 0 ){
-            class_pointer->factories.push_back( new signed_factory_class( fact, valid, docstring ) ) ;
-            return *this ;
-        }
-        
-        self& default_constructor( const char* docstring= 0, ValidConstructor valid = &yes_arity<0> ){
-            return constructor( docstring, valid ) ;  
-        }
-                
-#include <Rcpp/module/Module_generated_class_constructor.h>
-#include <Rcpp/module/Module_generated_class_factory.h>
-        
-    public:
-        
-        std::string get_typeinfo_name(){
-            return typeinfo_name ;    
-        }
-    
-        SEXP newInstance( SEXP* args, int nargs ){
-            BEGIN_RCPP
-                signed_constructor_class* p ;
-            int n = constructors.size() ;
-            for( int i=0; i<n; i++ ){
-                p = constructors[i];
-                bool ok = (p->valid)(args, nargs) ;
-                if( ok ){
-                    Class* ptr = p->ctor->get_new( args, nargs ) ;
-                    return XP( ptr, true ) ;
-                }
-            }
-            
-            signed_factory_class* pfact ;
-            n = factories.size() ;
-            for( int i=0; i<n; i++){
-              pfact = factories[i] ;
-              bool ok = (pfact->valid)(args, nargs) ;
-              if( ok ){
-                Class* ptr = pfact->fact->get_new( args, nargs ) ;
-                return XP( ptr, true ) ;
-              }
-            }
-            
-            throw std::range_error( "no valid constructor available for the argument list" ) ;
-            END_RCPP
-                }
-        
-        bool has_default_constructor(){ 
-            int n = constructors.size() ;
-            signed_constructor_class* p ;
-            for( int i=0; i<n; i++ ){
-                p = constructors[i];
-                if( p->nargs() == 0 ) return true ;
-            }
-            n = factories.size() ;
-            signed_factory_class* pfact ;
-            for( int i=0; i<n; i++ ){
-                pfact = factories[i];
-                if( pfact->nargs() == 0 ) return true ;
-            }
-            return false ;
-        }
-        
-        SEXP invoke( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
-            BEGIN_RCPP
-                
-                vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( EXTPTR_PTR( method_xp ) ) ;
-            typename vec_signed_method::iterator it = mets->begin() ;
-            int n = mets->size() ;
-            method_class* m = 0 ;
-            bool ok = false ; 
-            for( int i=0; i<n; i++, ++it ){
-                if( ( (*it)->valid )( args, nargs) ){
-                    m = (*it)->method ;
-                    ok = true ; 
-                    break ;
-                }
-            }
-            if( !ok ){
-                throw std::range_error( "could not find valid method" ) ;   
-            }
-            if( m->is_void() ){
-                m->operator()( XP(object), args ); 
-                return Rcpp::List::create( true ) ;
-            } else {
-                return Rcpp::List::create( false, m->operator()( XP(object), args ) ) ;
-            }
-            END_RCPP        
-                }
-        
-        SEXP invoke_void( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
-            BEGIN_RCPP
-                
-                vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( EXTPTR_PTR( method_xp ) ) ;
-            typename vec_signed_method::iterator it = mets->begin() ;
-            int n = mets->size() ;
-            method_class* m = 0 ;
-            bool ok = false ; 
-            for( int i=0; i<n; i++, ++it ){
-                if( ( (*it)->valid )( args, nargs) ){
-                    m = (*it)->method ;
-                    ok = true ; 
-                    break ;
-                }
-            }
-            if( !ok ){
-                throw std::range_error( "could not find valid method" ) ;   
-            }
-            m->operator()( XP(object), args ); 
-            END_RCPP        
-                }
-        
-        SEXP invoke_notvoid( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
-            BEGIN_RCPP
-                
-                vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( EXTPTR_PTR( method_xp ) ) ;
-            typename vec_signed_method::iterator it = mets->begin() ;
-            int n = mets->size() ;
-            method_class* m = 0 ;
-            bool ok = false ; 
-            for( int i=0; i<n; i++, ++it ){
-                if( ( (*it)->valid )( args, nargs) ){
-                    m = (*it)->method ;
-                    ok = true ; 
-                    break ;
-                }
-            }
-            if( !ok ){
-                throw std::range_error( "could not find valid method" ) ;   
-            }
-            return m->operator()( XP(object), args ) ;
-            END_RCPP        
-                }
-        
-        
-        self& AddMethod( const char* name_, method_class* m, ValidMethod valid = &yes, const char* docstring = 0){
-            typename map_vec_signed_method::iterator it = class_pointer->vec_methods.find( name_ ) ; 
-            if( it == class_pointer->vec_methods.end() ){
-                it = class_pointer->vec_methods.insert( vec_signed_method_pair( name_, new vec_signed_method() ) ).first ;
-            } 
-            (it->second)->push_back( new signed_method_class(m, valid, docstring ) ) ;
-            if( *name_ == '[' ) class_pointer->specials++ ;
-            return *this ;
-        }
-        
-        self& AddProperty( const char* name_, prop_class* p){
-            class_pointer->properties.insert( PROP_PAIR( name_, p ) ) ;
-            return *this ;
-        }
+#include <Rcpp/module/class.h>
 
-#include <Rcpp/module/Module_generated_method.h>
-#include <Rcpp/module/Module_generated_Pointer_method.h>
-        
-        bool has_method( const std::string& m){
-            return vec_methods.find(m) != vec_methods.end() ;
-        }
-        bool has_property( const std::string& m){
-            return properties.find(m) != properties.end() ;
-        }
-        bool property_is_readonly( const std::string& p) {
-            typename PROPERTY_MAP::iterator it = properties.find( p ) ;
-            if( it == properties.end() ) throw std::range_error( "no such property" ) ;
-            return it->second->is_readonly() ;
-        }
-        std::string property_class(const std::string& p) {
-            typename PROPERTY_MAP::iterator it = properties.find( p ) ;
-            if( it == properties.end() ) throw std::range_error( "no such property" ) ;
-            return it->second->get_class() ;
-        }
-        
-        Rcpp::CharacterVector method_names(){
-            int n = 0 ; 
-            int s = vec_methods.size() ;
-            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
-            for( int i=0; i<s; i++, ++it){
-                n += (it->second)->size() ;
-            }
-            Rcpp::CharacterVector out(n) ;
-            it = vec_methods.begin() ;
-            int k = 0 ;
-            for( int i=0; i<s; i++, ++it){
-                n = (it->second)->size() ;
-                std::string name = it->first ;
-                for( int j=0; j<n; j++, k++){
-                    out[k] = name ;
-                }
-            } 
-            return out ;
-        }
-        
-        Rcpp::IntegerVector methods_arity(){
-            int n = 0 ; 
-            int s = vec_methods.size() ;
-            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
-            for( int i=0; i<s; i++, ++it){
-                n += (it->second)->size() ;
-            }
-            Rcpp::CharacterVector mnames(n) ;
-            Rcpp::IntegerVector res(n) ;
-            it = vec_methods.begin() ;
-            int k = 0 ;
-            for( int i=0; i<s; i++, ++it){
-                n = (it->second)->size() ;
-                std::string name = it->first ;
-                typename vec_signed_method::iterator m_it = (it->second)->begin() ;
-                for( int j=0; j<n; j++, k++, ++m_it){
-                    mnames[k] = name ;
-                    res[k] = (*m_it)->nargs() ;
-                }
-            }
-            res.names( ) = mnames ;
-            return res ;
-        }
-        
-        Rcpp::LogicalVector methods_voidness(){
-            int n = 0 ; 
-            int s = vec_methods.size() ;
-            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
-            for( int i=0; i<s; i++, ++it){
-                n += (it->second)->size() ;
-            }
-            Rcpp::CharacterVector mnames(n) ;
-            Rcpp::LogicalVector res(n) ;
-            it = vec_methods.begin() ;
-            int k = 0 ;
-            for( int i=0; i<s; i++, ++it){
-                n = (it->second)->size() ;
-                std::string name = it->first ;
-                typename vec_signed_method::iterator m_it = (it->second)->begin() ;
-                for( int j=0; j<n; j++, k++, ++m_it){
-                    mnames[k] = name ;
-                    res[k] = (*m_it)->is_void() ;
-                }
-            }
-            res.names( ) = mnames ;
-            return res ;
-        }
-        
-        
-        Rcpp::CharacterVector property_names(){
-            int n = properties.size() ;
-            Rcpp::CharacterVector out(n) ;
-            typename PROPERTY_MAP::iterator it = properties.begin( ) ;
-            for( int i=0; i<n; i++, ++it){
-                out[i] = it->first ;
-            } 
-            return out ;
-        }
-        
-        Rcpp::List property_classes(){
-            int n = properties.size() ;
-            Rcpp::CharacterVector pnames(n) ;
-            Rcpp::List out(n) ;
-            typename PROPERTY_MAP::iterator it = properties.begin( ) ;
-            for( int i=0; i<n; i++, ++it){
-                pnames[i] = it->first ;
-                out[i] = it->second->get_class() ; 
-            } 
-            out.names() = pnames ;
-            return out ;
-        }
-        
-        Rcpp::CharacterVector complete(){
-            int n = vec_methods.size() - specials ;
-            int ntotal = n + properties.size() ;
-            Rcpp::CharacterVector out(ntotal) ;
-            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
-            std::string buffer ;
-            int i=0 ;
-            for( ; i<n; ++it){  
-                buffer = it->first ;
-                if( buffer[0] == '[' ) continue ;
-                // if( (it->second)->nargs() == 0){
-                //      buffer += "() " ;
-                // } else {
-                //      buffer += "( " ;
-                // } 
-                buffer += "( " ;
-                out[i] = buffer ;
-                i++ ;
-            }
-            typename PROPERTY_MAP::iterator prop_it = properties.begin(); 
-            for( ; i<ntotal; i++, ++prop_it){
-                out[i] = prop_it->first ;
-            }
-            return out ;
-        }
-        
-        SEXP getProperty( SEXP field_xp , SEXP object) {
-            BEGIN_RCPP
-                prop_class* prop = reinterpret_cast< prop_class* >( EXTPTR_PTR( field_xp ) ) ;
-            return prop->get( XP(object) ); 
-            END_RCPP
-                }
-        
-        void setProperty( SEXP field_xp, SEXP object, SEXP value)  {
-            BEGIN_RCPP
-                prop_class* prop = reinterpret_cast< prop_class* >( EXTPTR_PTR( field_xp ) ) ;
-            return prop->set( XP(object), value ); 
-            VOID_END_RCPP
-                }
-        
-        
-        Rcpp::List fields( SEXP class_xp ){
-            int n = properties.size() ;
-            Rcpp::CharacterVector pnames(n) ;
-            Rcpp::List out(n) ;
-            typename PROPERTY_MAP::iterator it = properties.begin( ) ;
-            for( int i=0; i<n; i++, ++it){
-                pnames[i] = it->first ;
-                out[i] = S4_field<Class>( it->second, class_xp ) ; 
-            } 
-            out.names() = pnames ;
-            return out ;
-        }
-
-        Rcpp::List getMethods( SEXP class_xp, std::string& buffer){
-            int n = vec_methods.size() ;
-            Rcpp::CharacterVector mnames(n) ;
-            Rcpp::List res(n) ;
-            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
-            vec_signed_method* v; 
-            for( int i=0; i<n; i++, ++it){
-                mnames[i] = it->first ;
-                v = it->second ;
-                res[i] = S4_CppOverloadedMethods<Class>( v , class_xp, it->first.c_str(), buffer ) ;
-            }
-            res.names() = mnames ;
-            return res ;
-        }
-        
-        Rcpp::List getConstructors( SEXP class_xp, std::string& buffer){
-            int n = constructors.size() ;
-            Rcpp::List out(n) ;
-            typename vec_signed_constructor::iterator it = constructors.begin( ) ;
-            for( int i=0; i<n; i++, ++it){
-                out[i] = S4_CppConstructor<Class>( *it , class_xp, name, buffer ) ; 
-            } 
-            return out ;
-        }
-
-#include <Rcpp/module/Module_Field.h>
-
-#include <Rcpp/module/Module_Add_Property.h>
-
-        self& finalizer( void (*f)(Class*) ){
-            SetFinalizer( new FunctionFinalizer<Class>( f ) ) ;
-            return *this ;
-        }    
-
-        virtual void run_finalizer( SEXP object ){
-            finalizer_pointer->run( XP(object) ) ;
-        }
-    
-    private:
-    
-        void SetFinalizer( finalizer_class* f ){
-            if( class_pointer->finalizer_pointer ) delete class_pointer->finalizer_pointer ;
-            class_pointer->finalizer_pointer = f ; 
-        }
-    
-        map_vec_signed_method vec_methods ;
-        PROPERTY_MAP properties ;
-        
-        finalizer_class* finalizer_pointer ;
-        int specials ;
-        vec_signed_constructor constructors ;
-        vec_signed_factory factories ;
-        self* class_pointer ;
-        std::string typeinfo_name ;
-    
-        class_( ) : class_Base(), vec_methods(), properties(), specials(0), constructors(), factories() {}; 
-        
-    } ;   
-
     template <typename Enum, typename Parent>
     class enum_ {
         public:

Added: pkg/Rcpp/inst/include/Rcpp/module/class.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/class.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/class.h	2012-10-31 12:54:38 UTC (rev 3867)
@@ -0,0 +1,493 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// class.h: Rcpp R/C++ interface class library -- Rcpp modules
+//
+// 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_Module_CLASS_h
+#define Rcpp_Module_CLASS_h
+
+    template <typename Class>
+    class class_ : public class_Base {
+    public:
+        typedef class_<Class> self ;
+        typedef CppMethod<Class> method_class ;
+        
+        typedef SignedMethod<Class> signed_method_class ;
+        typedef std::vector<signed_method_class*> vec_signed_method ;
+        typedef std::map<std::string,vec_signed_method*> map_vec_signed_method ;
+        typedef std::pair<std::string,vec_signed_method*> vec_signed_method_pair ;
+        
+        typedef std::map<std::string,method_class*> METHOD_MAP ;
+        typedef std::pair<const std::string,method_class*> PAIR ;
+        
+        typedef Rcpp::XPtr<Class> XP ;
+        typedef CppFinalizer<Class> finalizer_class ;
+        
+        typedef Constructor_Base<Class> constructor_class ;
+        typedef SignedConstructor<Class> signed_constructor_class ;
+        typedef std::vector<signed_constructor_class*> vec_signed_constructor ;
+        
+        typedef Factory_Base<Class> factory_class ;
+        typedef SignedFactory<Class> signed_factory_class ;
+        typedef std::vector<signed_factory_class*> vec_signed_factory ;
+        
+        typedef CppProperty<Class> prop_class ;
+        typedef std::map<std::string,prop_class*> PROPERTY_MAP ;
+        typedef std::pair<const std::string,prop_class*> PROP_PAIR ;
+        
+        class_( const char* name_, const char* doc = 0) : 
+            class_Base(name_, 0), 
+            vec_methods(), 
+            properties(), 
+            finalizer_pointer(0), 
+            specials(0), 
+            constructors(),
+            factories(),
+            class_pointer(0), 
+            typeinfo_name("")
+        {
+            Rcpp::Module* module = getCurrentScope() ;
+            if( ! module->has_class(name_) ){
+                class_pointer = new self ;
+                class_pointer->name = name_ ;
+                class_pointer->docstring = std::string( doc == 0 ? "" : doc );
+                class_pointer->finalizer_pointer = new finalizer_class ;
+                class_pointer->typeinfo_name = typeid(Class).name() ;
+                module->AddClass( name_, class_pointer ) ;
+            }
+        }
+         
+        ~class_(){}
+        
+        self& AddConstructor( constructor_class* ctor, ValidConstructor valid, const char* docstring = 0 ){
+            class_pointer->constructors.push_back( new signed_constructor_class( ctor, valid, docstring ) );  
+            return *this ;
+        }
+        
+        self& AddFactory( factory_class* fact, ValidConstructor valid, const char* docstring = 0 ){
+            class_pointer->factories.push_back( new signed_factory_class( fact, valid, docstring ) ) ;
+            return *this ;
+        }
+        
+        self& default_constructor( const char* docstring= 0, ValidConstructor valid = &yes_arity<0> ){
+            return constructor( docstring, valid ) ;  
+        }
+                
+#include <Rcpp/module/Module_generated_class_constructor.h>
+#include <Rcpp/module/Module_generated_class_factory.h>
+        
+    public:
+        
+        std::string get_typeinfo_name(){
+            return typeinfo_name ;    
+        }
+    
+        SEXP newInstance( SEXP* args, int nargs ){
+            BEGIN_RCPP
+                signed_constructor_class* p ;
+            int n = constructors.size() ;
+            for( int i=0; i<n; i++ ){
+                p = constructors[i];
+                bool ok = (p->valid)(args, nargs) ;
+                if( ok ){
+                    Class* ptr = p->ctor->get_new( args, nargs ) ;
+                    return XP( ptr, true ) ;
+                }
+            }
+            
+            signed_factory_class* pfact ;
+            n = factories.size() ;
+            for( int i=0; i<n; i++){
+              pfact = factories[i] ;
+              bool ok = (pfact->valid)(args, nargs) ;
+              if( ok ){
+                Class* ptr = pfact->fact->get_new( args, nargs ) ;
+                return XP( ptr, true ) ;
+              }
+            }
+            
+            throw std::range_error( "no valid constructor available for the argument list" ) ;
+            END_RCPP
+                }
+        
+        bool has_default_constructor(){ 
+            int n = constructors.size() ;
+            signed_constructor_class* p ;
+            for( int i=0; i<n; i++ ){
+                p = constructors[i];
+                if( p->nargs() == 0 ) return true ;
+            }
+            n = factories.size() ;
+            signed_factory_class* pfact ;
+            for( int i=0; i<n; i++ ){
+                pfact = factories[i];
+                if( pfact->nargs() == 0 ) return true ;
+            }
+            return false ;
+        }
+        
+        SEXP invoke( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
+            BEGIN_RCPP
+                
+                vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( EXTPTR_PTR( method_xp ) ) ;
+            typename vec_signed_method::iterator it = mets->begin() ;
+            int n = mets->size() ;
+            method_class* m = 0 ;
+            bool ok = false ; 
+            for( int i=0; i<n; i++, ++it ){
+                if( ( (*it)->valid )( args, nargs) ){
+                    m = (*it)->method ;
+                    ok = true ; 
+                    break ;
+                }
+            }
+            if( !ok ){
+                throw std::range_error( "could not find valid method" ) ;   
+            }
+            if( m->is_void() ){
+                m->operator()( XP(object), args ); 
+                return Rcpp::List::create( true ) ;
+            } else {
+                return Rcpp::List::create( false, m->operator()( XP(object), args ) ) ;
+            }
+            END_RCPP        
+                }
+        
+        SEXP invoke_void( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
+            BEGIN_RCPP
+                
+                vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( EXTPTR_PTR( method_xp ) ) ;
+            typename vec_signed_method::iterator it = mets->begin() ;
+            int n = mets->size() ;
+            method_class* m = 0 ;
+            bool ok = false ; 
+            for( int i=0; i<n; i++, ++it ){
+                if( ( (*it)->valid )( args, nargs) ){
+                    m = (*it)->method ;
+                    ok = true ; 
+                    break ;
+                }
+            }
+            if( !ok ){
+                throw std::range_error( "could not find valid method" ) ;   
+            }
+            m->operator()( XP(object), args ); 
+            END_RCPP        
+                }
+        
+        SEXP invoke_notvoid( SEXP method_xp, SEXP object, SEXP *args, int nargs ){ 
+            BEGIN_RCPP
+                
+                vec_signed_method* mets = reinterpret_cast< vec_signed_method* >( EXTPTR_PTR( method_xp ) ) ;
+            typename vec_signed_method::iterator it = mets->begin() ;
+            int n = mets->size() ;
+            method_class* m = 0 ;
+            bool ok = false ; 
+            for( int i=0; i<n; i++, ++it ){
+                if( ( (*it)->valid )( args, nargs) ){
+                    m = (*it)->method ;
+                    ok = true ; 
+                    break ;
+                }
+            }
+            if( !ok ){
+                throw std::range_error( "could not find valid method" ) ;   
+            }
+            return m->operator()( XP(object), args ) ;
+            END_RCPP        
+                }
+        
+        
+        self& AddMethod( const char* name_, method_class* m, ValidMethod valid = &yes, const char* docstring = 0){
+            typename map_vec_signed_method::iterator it = class_pointer->vec_methods.find( name_ ) ; 
+            if( it == class_pointer->vec_methods.end() ){
+                it = class_pointer->vec_methods.insert( vec_signed_method_pair( name_, new vec_signed_method() ) ).first ;
+            } 
+            (it->second)->push_back( new signed_method_class(m, valid, docstring ) ) ;
+            if( *name_ == '[' ) class_pointer->specials++ ;
+            return *this ;
+        }
+        
+        self& AddProperty( const char* name_, prop_class* p){
+            class_pointer->properties.insert( PROP_PAIR( name_, p ) ) ;
+            return *this ;
+        }
+
+#include <Rcpp/module/Module_generated_method.h>
+#include <Rcpp/module/Module_generated_Pointer_method.h>
+        
+        bool has_method( const std::string& m){
+            return vec_methods.find(m) != vec_methods.end() ;
+        }
+        bool has_property( const std::string& m){
+            return properties.find(m) != properties.end() ;
+        }
+        bool property_is_readonly( const std::string& p) {
+            typename PROPERTY_MAP::iterator it = properties.find( p ) ;
+            if( it == properties.end() ) throw std::range_error( "no such property" ) ;
+            return it->second->is_readonly() ;
+        }
+        std::string property_class(const std::string& p) {
+            typename PROPERTY_MAP::iterator it = properties.find( p ) ;
+            if( it == properties.end() ) throw std::range_error( "no such property" ) ;
+            return it->second->get_class() ;
+        }
+        
+        Rcpp::CharacterVector method_names(){
+            int n = 0 ; 
+            int s = vec_methods.size() ;
+            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
+            for( int i=0; i<s; i++, ++it){
+                n += (it->second)->size() ;
+            }
+            Rcpp::CharacterVector out(n) ;
+            it = vec_methods.begin() ;
+            int k = 0 ;
+            for( int i=0; i<s; i++, ++it){
+                n = (it->second)->size() ;
+                std::string name = it->first ;
+                for( int j=0; j<n; j++, k++){
+                    out[k] = name ;
+                }
+            } 
+            return out ;
+        }
+        
+        Rcpp::IntegerVector methods_arity(){
+            int n = 0 ; 
+            int s = vec_methods.size() ;
+            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
+            for( int i=0; i<s; i++, ++it){
+                n += (it->second)->size() ;
+            }
+            Rcpp::CharacterVector mnames(n) ;
+            Rcpp::IntegerVector res(n) ;
+            it = vec_methods.begin() ;
+            int k = 0 ;
+            for( int i=0; i<s; i++, ++it){
+                n = (it->second)->size() ;
+                std::string name = it->first ;
+                typename vec_signed_method::iterator m_it = (it->second)->begin() ;
+                for( int j=0; j<n; j++, k++, ++m_it){
+                    mnames[k] = name ;
+                    res[k] = (*m_it)->nargs() ;
+                }
+            }
+            res.names( ) = mnames ;
+            return res ;
+        }
+        
+        Rcpp::LogicalVector methods_voidness(){
+            int n = 0 ; 
+            int s = vec_methods.size() ;
+            typename map_vec_signed_method::iterator it = vec_methods.begin( ) ;
+            for( int i=0; i<s; i++, ++it){
+                n += (it->second)->size() ;
+            }
+            Rcpp::CharacterVector mnames(n) ;
+            Rcpp::LogicalVector res(n) ;
+            it = vec_methods.begin() ;
+            int k = 0 ;
+            for( int i=0; i<s; i++, ++it){
+                n = (it->second)->size() ;
+                std::string name = it->first ;
+                typename vec_signed_method::iterator m_it = (it->second)->begin() ;
+                for( int j=0; j<n; j++, k++, ++m_it){
+                    mnames[k] = name ;
+                    res[k] = (*m_it)->is_void() ;
+                }
+            }
+            res.names( ) = mnames ;
+            return res ;
+        }
+        
+        
+        Rcpp::CharacterVector property_names(){
+            int n = properties.size() ;
+            Rcpp::CharacterVector out(n) ;
+            typename PROPERTY_MAP::iterator it = properties.begin( ) ;
+            for( int i=0; i<n; i++, ++it){
+                out[i] = it->first ;
+            } 
+            return out ;
+        }
+        
+        Rcpp::List property_classes(){
+            int n = properties.size() ;
+            Rcpp::CharacterVector pnames(n) ;
+            Rcpp::List out(n) ;
+            typename PROPERTY_MAP::iterator it = properties.begin( ) ;
+            for( int i=0; i<n; i++, ++it){
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rcpp -r 3867


More information about the Rcpp-commits mailing list