[Rcpp-commits] r3887 - 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
Fri Nov 2 19:36:44 CET 2012


Author: romain
Date: 2012-11-02 19:36:44 +0100 (Fri, 02 Nov 2012)
New Revision: 3887

Added:
   pkg/Rcpp/inst/include/Rcpp/module/Module.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Module.h
   pkg/Rcpp/src/Module.cpp
Log:
factor out the Module class in its own file

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-02 16:08:32 UTC (rev 3886)
+++ pkg/Rcpp/ChangeLog	2012-11-02 18:36:44 UTC (rev 3887)
@@ -4,6 +4,9 @@
         and added the get_function_ptr virtual method. added documentation
         * include/Rcpp/module/Module_generated_CppFunction.h: implementation 
         of get_function_ptr in classes that derive CppFunction
+        * src/Module.cpp: s/get_function_ptr/get_function/
+        * include/Rcpp/module/Module.h : factored out and documented. 
+        s/get_function_ptr/get_function/
 
 2012-11-01  Dirk Eddelbuettel  <edd at debian.org>
 

Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h	2012-11-02 16:08:32 UTC (rev 3886)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h	2012-11-02 18:36:44 UTC (rev 3887)
@@ -152,58 +152,7 @@
         ENUM_MAP enums ;
         
     } ;
-
-    class Module {
-    public:    
-        typedef std::map<std::string,CppFunction*> MAP ;
-        typedef std::pair<const std::string,CppFunction*> FUNCTION_PAIR ;
-                
-        typedef std::map<std::string,class_Base*> CLASS_MAP ;
-        typedef std::pair<const std::string,class_Base*> CLASS_PAIR ;
-        typedef CLASS_MAP::iterator CLASS_ITERATOR ;
-        
-        Module()  ;
-        Module(const char* name_)  ;
-                      
-        SEXP invoke( const std::string& /* name */,  SEXP* /* args */, int /* nargs */ ) ;                        
-                
-        Rcpp::IntegerVector functions_arity() ;
-        Rcpp::CharacterVector functions_names() ;
-                
-        Rcpp::CharacterVector class_names() ;
-        Rcpp::List classes_info() ;
-        Rcpp::CharacterVector complete() ;
-        SEXP get_function_ptr( const std::string& ) ;
-                
-        inline void Add( const char* name_ , CppFunction* ptr){
-            functions.insert( FUNCTION_PAIR( name_ , ptr ) ) ;
-        }
-                
-        inline void AddClass(const char* name_ , class_Base* cptr){
-            classes.insert( CLASS_PAIR( name_ , cptr ) ) ;
-        }
-
-        inline bool has_function( const std::string& m){
-            return functions.find(m) != functions.end() ;
-        }
-                
-        inline bool has_class( const std::string& m){
-            return classes.find(m) != classes.end() ;
-        }
-                
-        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 ) ;
-        
-    private:
-        MAP functions ;
-        CLASS_MAP classes ;
-                           
-    };
-
+#include <Rcpp/module/Module.h>
 }
 extern "C" Rcpp::Module* getCurrentScope() ;
 extern "C" void setCurrentScope( Rcpp::Module* ) ;

Added: pkg/Rcpp/inst/include/Rcpp/module/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module.h	2012-11-02 18:36:44 UTC (rev 3887)
@@ -0,0 +1,116 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Module.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_Module_h
+#define Rcpp_Module_Module_h
+       
+    /**
+     * holds information about exposed functions and classes
+     */
+    class Module {
+    public:    
+        typedef std::map<std::string,CppFunction*> MAP ;
+        typedef std::pair<const std::string,CppFunction*> FUNCTION_PAIR ;
+                
+        typedef std::map<std::string,class_Base*> CLASS_MAP ;
+        typedef std::pair<const std::string,class_Base*> CLASS_PAIR ;
+        typedef CLASS_MAP::iterator CLASS_ITERATOR ;
+        
+        Module()  ;
+        Module(const char* name_)  ;
+          
+        /**
+         * calls a function from that module with the specified arguments
+         *
+         * @param name the name of the function to call
+         * @param args an array of R objects to use as arguments for the function
+         * @param nargs number of arguments
+         */
+        SEXP invoke( const std::string& /* name */,  SEXP* /* args */, int /* nargs */ ) ;                        
+                
+        /**
+         * vector of arity of all the functions exported by the module 
+         */
+        Rcpp::IntegerVector functions_arity() ;
+        
+        /**
+         * vector of names of the functions
+         */
+        Rcpp::CharacterVector functions_names() ;
+                
+        /** 
+         * exposed class names
+         */
+        Rcpp::CharacterVector class_names() ;
+        
+        /** 
+         * information about the classes
+         */
+        Rcpp::List classes_info() ;
+        
+        /**
+         * completion information
+         */
+        Rcpp::CharacterVector complete() ;
+        
+        /**
+         * Returns a list that contains: 
+         * - an external pointer that encapsulates a CppFunction*
+         * - voidness of the function (logical)
+         * - docstring (character)
+         * - signature (character)
+         * - formal arguments of the function
+         *
+         * The R code in Module.R uses this information to create a C++Function 
+         * object
+         */
+        SEXP get_function( const std::string& ) ;
+                
+        inline void Add( const char* name_ , CppFunction* ptr){
+            functions.insert( FUNCTION_PAIR( name_ , ptr ) ) ;
+        }
+                
+        inline void AddClass(const char* name_ , class_Base* cptr){
+            classes.insert( CLASS_PAIR( name_ , cptr ) ) ;
+        }
+
+        inline bool has_function( const std::string& m){
+            return functions.find(m) != functions.end() ;
+        }
+                
+        inline bool has_class( const std::string& m){
+            return classes.find(m) != classes.end() ;
+        }
+                
+        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 ) ;
+        
+    private:
+        MAP functions ;
+        CLASS_MAP classes ;
+                           
+    };
+
+#endif

Modified: pkg/Rcpp/src/Module.cpp
===================================================================
--- pkg/Rcpp/src/Module.cpp	2012-11-02 16:08:32 UTC (rev 3886)
+++ pkg/Rcpp/src/Module.cpp	2012-11-02 18:36:44 UTC (rev 3887)
@@ -31,7 +31,7 @@
     return cl->has_default_constructor() ;
 }
 RCPP_FUNCTION_2( SEXP, Module__get_function, XP_Module module, std::string fun ){
-    return module->get_function_ptr( fun ) ;
+    return module->get_function( fun ) ;
 }
 RCPP_FUNCTION_2( bool, Class__has_method, XP_Class cl, std::string m){
 	return cl->has_method(m) ;
@@ -290,7 +290,7 @@
 		END_RCPP
 	}                                                                                  
 	
-	SEXP Module::get_function_ptr( const std::string& name ){
+	SEXP Module::get_function( const std::string& name ){
 	    MAP::iterator it = functions.begin() ;
 	    int n = functions.size() ;
 	    CppFunction* fun = 0 ;



More information about the Rcpp-commits mailing list