|
22 | 22 | #ifndef Rcpp_Module_CLASS_h |
23 | 23 | #define Rcpp_Module_CLASS_h |
24 | 24 |
|
| 25 | + template <typename Class, bool ok> |
| 26 | + struct CopyConstructor { |
| 27 | + static Class* get( Class* obj ){ |
| 28 | + return new Class(*obj) ; |
| 29 | + } |
| 30 | + } ; |
| 31 | + |
| 32 | + template <typename Class> |
| 33 | + struct CopyConstructor<Class,false> { |
| 34 | + static Class* get( Class* obj){ |
| 35 | + stop("no copy constructor available") ; |
| 36 | + return obj ; |
| 37 | + } |
| 38 | + } ; |
| 39 | + |
25 | 40 | template <typename Class> |
26 | 41 | class class_ : public class_Base { |
27 | 42 | public: |
|
60 | 75 | constructors(), |
61 | 76 | factories(), |
62 | 77 | class_pointer(0), |
63 | | - typeinfo_name(""), |
64 | | - has_copy_constructor(false) |
| 78 | + typeinfo_name("") |
65 | 79 | { |
66 | 80 | class_pointer = get_instance() ; |
67 | 81 | } |
|
112 | 126 | return constructor( docstring, valid ) ; |
113 | 127 | } |
114 | 128 |
|
115 | | - self& copy_constructor(){ |
116 | | - class_pointer->has_copy_constructor = true ; |
117 | | - return *this ; |
118 | | - } |
119 | | - |
120 | 129 | #include <Rcpp/module/Module_generated_class_constructor.h> |
121 | 130 | #include <Rcpp/module/Module_generated_class_factory.h> |
122 | 131 |
|
|
156 | 165 |
|
157 | 166 | SEXP invoke_copy_constructor( SEXP object ){ |
158 | 167 | BEGIN_RCPP |
159 | | - |
160 | | - if( !has_copy_constructor ) |
161 | | - stop("copy constructor not exposed") ; |
162 | | - |
163 | 168 | XP xp(object) ; |
164 | | - return internal::make_new_object<Class>( new Class(*xp) ) ; |
| 169 | + return internal::make_new_object<Class>( CopyConstructor< Class, traits::has_copy_constructor<Class>::value >::get(xp) ) ; |
165 | 170 | END_RCPP |
166 | 171 | } |
167 | 172 |
|
|
493 | 498 | vec_signed_factory factories ; |
494 | 499 | self* class_pointer ; |
495 | 500 | std::string typeinfo_name ; |
496 | | - bool has_copy_constructor ; |
497 | | - |
| 501 | + |
498 | 502 | class_( ) : class_Base(), vec_methods(), properties(), specials(0), constructors(), factories() {}; |
499 | 503 |
|
500 | 504 |
|
|
0 commit comments