Rcpp Version 0.9.10
Module_Property.h
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 //
00003 // Module_Property.h: Rcpp R/C++ interface class library -- Rcpp modules
00004 //
00005 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
00006 //
00007 // This file is part of Rcpp.
00008 //
00009 // Rcpp is free software: you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 2 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // Rcpp is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 #ifndef Rcpp_Module_Property_h
00023 #define Rcpp_Module_Property_h
00024 
00025 // getter through a member function
00026 template <typename Class, typename PROP>
00027 class CppProperty_GetMethod : public CppProperty<Class> {
00028 public:         
00029     typedef PROP (Class::*GetMethod)(void) ;
00030     typedef CppProperty<Class> prop_class ;
00031 
00032     CppProperty_GetMethod( GetMethod getter_, const char* doc = 0 ) : 
00033         prop_class(doc), getter(getter_), class_name(DEMANGLE(PROP)){}
00034                 
00035     SEXP get(Class* object) { return Rcpp::wrap( (object->*getter)() ) ; }
00036     void set(Class*, SEXP) { throw std::range_error("property is read only") ; }                
00037     bool is_readonly(){ return true ; }
00038     std::string get_class(){ return class_name; }
00039                         
00040 private:
00041     GetMethod getter ;
00042     std::string class_name ;
00043                                 
00044 } ;
00045 
00046 // getter through a const member function
00047 template <typename Class, typename PROP>
00048 class CppProperty_GetConstMethod : public CppProperty<Class> {
00049 public:         
00050     typedef PROP (Class::*GetMethod)(void) const ;
00051     typedef CppProperty<Class> prop_class ;
00052 
00053     CppProperty_GetConstMethod( GetMethod getter_ , const char* doc = 0) : 
00054         prop_class(doc), getter(getter_), class_name(DEMANGLE(PROP)){}
00055                 
00056     SEXP get(Class* object) { return Rcpp::wrap( (object->*getter)() ) ; }
00057     void set(Class*, SEXP) { throw std::range_error("property is read only") ; }                
00058     bool is_readonly(){ return true ; }
00059     std::string get_class(){ return class_name; }
00060                         
00061 private:
00062     GetMethod getter ;
00063     std::string class_name ;
00064                                 
00065 } ;
00066 
00067 
00068 // getter through a free function taking a pointer to Class
00069 template <typename Class, typename PROP>
00070 class CppProperty_GetPointerMethod : public CppProperty<Class> {
00071 public:         
00072     typedef PROP (*GetMethod)(Class*) ;
00073     typedef CppProperty<Class> prop_class ;
00074 
00075     CppProperty_GetPointerMethod( GetMethod getter_ , const char* doc = 0) : 
00076         prop_class(doc), getter(getter_), class_name(DEMANGLE(PROP)){}
00077                 
00078     SEXP get(Class* object) { return Rcpp::wrap( getter(object) ) ; }
00079     void set(Class*, SEXP) { throw std::range_error("property is read only") ; }                
00080     bool is_readonly(){ return true ; }
00081     std::string get_class(){ return class_name; }
00082                         
00083 private:
00084     GetMethod getter ;
00085     std::string class_name ;                                
00086 } ;
00087 
00088 
00089 // getter and setter through member functions
00090 template <typename Class, typename PROP>
00091 class CppProperty_GetMethod_SetMethod : public CppProperty<Class> {
00092 public:         
00093     typedef PROP (Class::*GetMethod)(void) ;
00094     typedef void (Class::*SetMethod)(PROP) ;
00095     typedef CppProperty<Class> prop_class ;
00096 
00097     CppProperty_GetMethod_SetMethod( GetMethod getter_, SetMethod setter_, const char* doc = 0) : 
00098         prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
00099                 
00100     SEXP get(Class* object) { 
00101         return Rcpp::wrap( (object->*getter)() ) ; 
00102     }
00103     void set(Class* object, SEXP value) throw(std::range_error,Rcpp::not_compatible){ 
00104         (object->*setter)( 
00105                           Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
00106                            ) ;
00107     }               
00108     bool is_readonly(){ return false ; }
00109     std::string get_class(){ return class_name; }
00110                         
00111 private:
00112     GetMethod getter ;
00113     SetMethod setter ;
00114     std::string class_name ;                                
00115 } ;
00116 template <typename Class, typename PROP>
00117 class CppProperty_GetConstMethod_SetMethod : public CppProperty<Class> {
00118 public:         
00119     typedef PROP (Class::*GetMethod)(void) const ;
00120     typedef void (Class::*SetMethod)(PROP) ;
00121     typedef CppProperty<Class> prop_class ;
00122 
00123     CppProperty_GetConstMethod_SetMethod( GetMethod getter_, SetMethod setter_, const char* doc = 0) : 
00124         prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
00125                 
00126     SEXP get(Class* object) { 
00127         return Rcpp::wrap( (object->*getter)() ) ; 
00128     }
00129     void set(Class* object, SEXP value) { 
00130         (object->*setter)( 
00131                           Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
00132                            ) ;
00133     }               
00134     bool is_readonly(){ return false ; }
00135     std::string get_class(){ return class_name; }
00136                         
00137 private:
00138     GetMethod getter ;
00139     SetMethod setter ;
00140     std::string class_name ;
00141                                 
00142 } ;
00143 
00144 
00145 
00146 
00147 // getter though a member function, setter through a pointer function
00148 template <typename Class, typename PROP>
00149 class CppProperty_GetMethod_SetPointer : public CppProperty<Class> {
00150 public:         
00151     typedef PROP (Class::*GetMethod)(void) ;
00152     typedef void (*SetMethod)(Class*,PROP) ;
00153     typedef CppProperty<Class> prop_class ;
00154 
00155     CppProperty_GetMethod_SetPointer( GetMethod getter_, SetMethod setter_, const char* doc = 0) : 
00156         prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
00157                 
00158     SEXP get(Class* object) { 
00159         return Rcpp::wrap( (object->*getter)() ) ;
00160     }
00161     void set(Class* object, SEXP value) throw(std::range_error,Rcpp::not_compatible){ 
00162         setter( object, 
00163                 Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
00164                 ) ;
00165     }               
00166     bool is_readonly(){ return false ; }
00167     std::string get_class(){ return class_name; }
00168                         
00169 private:
00170     GetMethod getter ;
00171     SetMethod setter ;
00172     std::string class_name ;
00173                                 
00174 } ;
00175 template <typename Class, typename PROP>
00176 class CppProperty_GetConstMethod_SetPointer : public CppProperty<Class> {
00177 public:         
00178     typedef PROP (Class::*GetMethod)(void) const ;
00179     typedef void (*SetMethod)(Class*,PROP) ;
00180     typedef CppProperty<Class> prop_class ;
00181 
00182     CppProperty_GetConstMethod_SetPointer( GetMethod getter_, SetMethod setter_, const char* doc = 0) : 
00183         prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
00184                 
00185     SEXP get(Class* object) { 
00186         return Rcpp::wrap( (object->*getter)() ) ;
00187     }
00188     void set(Class* object, SEXP value) { 
00189         setter( object, 
00190                 Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
00191                 ) ;
00192     }               
00193     bool is_readonly(){ return false ; }
00194     std::string get_class(){ return class_name; }
00195                         
00196 private:
00197     GetMethod getter ;
00198     SetMethod setter ;
00199     std::string class_name ;
00200                                 
00201 } ;
00202 
00203 // getter through pointer function, setter through member function
00204 template <typename Class, typename PROP>
00205 class CppProperty_GetPointer_SetMethod : public CppProperty<Class> {
00206 public:         
00207     typedef PROP (*GetMethod)(Class*) ;
00208     typedef void (Class::*SetMethod)(PROP) ;
00209     typedef CppProperty<Class> prop_class ;
00210 
00211     CppProperty_GetPointer_SetMethod( GetMethod getter_, SetMethod setter_, const char* doc = 0) : 
00212         prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
00213                 
00214     SEXP get(Class* object) { 
00215         return Rcpp::wrap( getter(object) ) ;
00216     }
00217     void set(Class* object, SEXP value) { 
00218         (object->*setter)( 
00219                           Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
00220                            ) ;
00221     }               
00222     bool is_readonly(){ return false ; }
00223     std::string get_class(){ return class_name; }
00224                         
00225 private:
00226     GetMethod getter ;
00227     SetMethod setter ;
00228     std::string class_name ;
00229                                 
00230 } ;
00231 
00232 // getter and setter through pointer functions
00233 // getter through pointer function, setter through member function
00234 template <typename Class, typename PROP>
00235 class CppProperty_GetPointer_SetPointer : public CppProperty<Class> {
00236 public:         
00237     typedef PROP (*GetMethod)(Class*) ;
00238     typedef void (*SetMethod)(Class*,PROP) ;
00239     typedef CppProperty<Class> prop_class ;
00240 
00241     CppProperty_GetPointer_SetPointer( GetMethod getter_, SetMethod setter_, const char* doc = 0) : 
00242         prop_class(doc), getter(getter_), setter(setter_), class_name(DEMANGLE(PROP)){}
00243                 
00244     SEXP get(Class* object) { 
00245         return Rcpp::wrap( getter(object) ) ;
00246     }
00247     void set(Class* object, SEXP value) { 
00248         setter( object,
00249                 Rcpp::as< typename Rcpp::traits::remove_const_and_reference< PROP >::type >( value )
00250                 ) ;
00251     }               
00252     bool is_readonly(){ return false ; }
00253     std::string get_class(){ return class_name; }
00254                         
00255 private:
00256     GetMethod getter ;
00257     SetMethod setter ;
00258     std::string class_name ;
00259                 
00260 } ;
00261 
00262 
00263 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines