[Rcpp-commits] r2397 - in pkg/Rcpp/inst/include/Rcpp: . module
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Nov 5 13:35:45 CET 2010
Author: romain
Date: 2010-11-05 13:35:44 +0100 (Fri, 05 Nov 2010)
New Revision: 2397
Added:
pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_constructor.h
pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_signature.h
Removed:
pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h
Modified:
pkg/Rcpp/inst/include/Rcpp/Module.h
Log:
some changes about constructors
Modified: pkg/Rcpp/inst/include/Rcpp/Module.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Module.h 2010-11-05 01:14:05 UTC (rev 2396)
+++ pkg/Rcpp/inst/include/Rcpp/Module.h 2010-11-05 12:35:44 UTC (rev 2397)
@@ -169,6 +169,8 @@
#include <Rcpp/module/Module_generated_CppMethod.h>
#include <Rcpp/module/Module_generated_Pointer_CppMethod.h>
+typedef bool (*ValidConstructor)(SEXP*,int) ;
+
template <typename Class>
class CppProperty {
public:
@@ -216,40 +218,67 @@
#include <Rcpp/module/Module_Property.h>
#include <Rcpp/module/Module_generated_Constructor.h>
+#include <Rcpp/module/Module_generated_class_signature.h>
-template <typename Class, typename INIT = init_0>
+template <typename Class>
+class SignedConstructor {
+public:
+
+ SignedConstructor(
+ Constructor_Base<Class>* ctor_,
+ ValidConstructor valid_
+ ) : ctor(ctor_), valid(valid_){}
+
+ Constructor_Base<Class>* ctor ;
+ ValidConstructor valid ;
+} ;
+
+template <typename Class>
class class_ : public class_Base {
public:
- typedef class_<Class,INIT> self ;
+ typedef class_<Class> self ;
typedef CppMethod<Class> method_class ;
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 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_ ) :
- class_Base(name_), methods(), properties(), finalizer_pointer(0), specials(0), ctor(0)
+ class_Base(name_), methods(), properties(), finalizer_pointer(0), specials(0), constructors()
{
if( !singleton ){
singleton = new self ;
singleton->name = name_ ;
singleton->finalizer_pointer = new finalizer_class ;
- singleton->ctor = get_constructor(INIT()) ;
getCurrentScope()->AddClass( name_, singleton ) ;
}
}
-
-#include <Rcpp/module/Module_generated_class_get_constructor.h>
-
+
+ ~class_(){}
+
+
+ self& AddConstructor( constructor_class* ctor, ValidConstructor valid = &yes ){
+ singleton->constructors.push_back( new signed_constructor_class( ctor, valid ) );
+ return *this ;
+ }
+
+ self& default_constructor( ValidConstructor valid = &yes ){
+ return constructor( init_0(), valid ) ;
+ }
+
+#include <Rcpp/module/Module_generated_class_constructor.h>
+
public:
SEXP newInstance( SEXP* args, int nargs ){
- SEXP out = XP( ctor->get_new(args,nargs), true ) ;
+ SEXP out = XP( constructors[0]->ctor->get_new(args,nargs), true ) ;
return out ;
}
@@ -447,14 +476,14 @@
static self* singleton ;
finalizer_class* finalizer_pointer ;
int specials ;
- constructor_class* ctor ;
+ vec_signed_constructor constructors ;
class_( ) : class_Base(), methods(), properties(), specials(0) {};
} ;
-template <typename Class,typename INIT>
-class_<Class,INIT>* class_<Class,INIT>::singleton ;
+template <typename Class>
+class_<Class>* class_<Class>::singleton ;
// function factories
#include <Rcpp/module/Module_generated_function.h>
Added: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_constructor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_constructor.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_constructor.h 2010-11-05 12:35:44 UTC (rev 2397)
@@ -0,0 +1,42 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Module_generated_class_constructor.h: Rcpp R/C++ interface class library -- Rcpp modules
+//
+// Copyright (C) 2010 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_generated_class_constructor_h
+#define Rcpp_Module_generated_class_constructor_h
+
+ self& constructor( init_0, ValidConstructor valid = &yes ){
+ AddConstructor( new Constructor_0<Class>, valid ) ;
+ return *this ;
+ }
+
+ template <typename U0>
+ self& constructor( init_1<U0>, ValidConstructor valid = &yes_arity<1> ){
+ AddConstructor( new Constructor_1<Class,U0>, valid) ;
+ return *this ;
+ }
+
+ template <typename U0, typename U1>
+ self& constructor( init_2<U0,U1>, ValidConstructor valid = &yes_arity<2> ){
+ AddConstructor( new Constructor_2<Class,U0,U1>, valid ) ;
+ return *this ;
+ }
+
+#endif
Deleted: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h 2010-11-05 01:14:05 UTC (rev 2396)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_get_constructor.h 2010-11-05 12:35:44 UTC (rev 2397)
@@ -1,38 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// Module_generated_class_get_constructor.h: Rcpp R/C++ interface class library -- Rcpp modules
-//
-// Copyright (C) 2010 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_generated_class_get_Constructor_h
-#define Rcpp_Module_generated_class_get_Constructor_h
-
-private:
- constructor_class* get_constructor( init_0 ){
- return new Constructor_0<Class> ;
- }
- template <typename U0>
- constructor_class* get_constructor( init_1<U0> ){
- return new Constructor_1<Class,U0>() ;
- }
- template <typename U0, typename U1>
- constructor_class* get_constructor( init_2<U0,U1> ){
- return new Constructor_2<Class,U0,U1>() ;
- }
-
-#endif
Added: pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_signature.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_signature.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/module/Module_generated_class_signature.h 2010-11-05 12:35:44 UTC (rev 2397)
@@ -0,0 +1,34 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// Module_generated_Constructor.h: Rcpp R/C++ interface class library -- Rcpp modules
+//
+// Copyright (C) 2010 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_generated_class_signature_h
+#define Rcpp_Module_generated_class_signature_h
+
+inline bool yes( SEXP* args, int nargs){
+ return true ;
+}
+
+template<int n>
+bool yes_arity( SEXP* args, int nargs){
+ return nargs == n ;
+}
+
+#endif
More information about the Rcpp-commits
mailing list