[Rcpp-commits] r1108 - in pkg/Rcpp: inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 22 11:15:20 CEST 2010


Author: romain
Date: 2010-04-22 11:15:20 +0200 (Thu, 22 Apr 2010)
New Revision: 1108

Modified:
   pkg/Rcpp/inst/include/Rcpp/RObject.h
   pkg/Rcpp/inst/include/Rcpp/exceptions.h
   pkg/Rcpp/src/RObject.cpp
Log:
RObject::slot was failing because of incomplete throw declaration

Modified: pkg/Rcpp/inst/include/Rcpp/RObject.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/RObject.h	2010-04-22 08:51:39 UTC (rev 1107)
+++ pkg/Rcpp/inst/include/Rcpp/RObject.h	2010-04-22 09:15:20 UTC (rev 1108)
@@ -28,28 +28,7 @@
 
 class RObject {
 public:
-
-	
-	/**
-   	 * Exception thrown when attempting to convert a SEXP
-   	 */
-   	class not_s4: public std::exception{
-   		public:
-   			not_s4() throw(){};
-   			virtual ~not_s4() throw(){} ;
-   			virtual const char* what() const throw() ; 
-   	} ;
    	
-   	/**
-   	 * Exception thrown when attempting to convert a SEXP
-   	 */
-   	class no_such_slot : public std::exception{
-   		public:
-   			no_such_slot() throw(){};
-   			virtual ~no_such_slot() throw(){} ;
-   			virtual const char* what() const throw() ;
-   	} ;
-   	
     /**
      * default constructor. uses R_NilValue
      */ 
@@ -169,7 +148,7 @@
 		 * @param v parent object of which we get/set a slot
 		 * @param name slot name
 		 */
-		SlotProxy( const RObject& v, const std::string& name) ;
+		SlotProxy( const RObject& v, const std::string& name) throw(no_such_slot) ;
 
 		/**
 		 * lhs use. Assigns the target slot using the current 
@@ -262,7 +241,7 @@
      *
      * @throw not_s4 if this is not an S4 object
      */
-    SlotProxy slot(const std::string& name) const throw(not_s4) ;
+    SlotProxy slot(const std::string& name) const throw(not_s4,no_such_slot) ;
     
 protected:
 

Modified: pkg/Rcpp/inst/include/Rcpp/exceptions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/exceptions.h	2010-04-22 08:51:39 UTC (rev 1107)
+++ pkg/Rcpp/inst/include/Rcpp/exceptions.h	2010-04-22 09:15:20 UTC (rev 1108)
@@ -24,76 +24,37 @@
 
 namespace Rcpp{
 
-/**
- * Exception thrown when attempting to convert a SEXP
- */
-class not_compatible: public std::exception{
-	public:
-		not_compatible(const std::string& message) throw() : message(message){};
-		virtual ~not_compatible() throw(){} ;
-		virtual const char* what() const throw(){ return message.c_str() ; } ; 
-	private:
-		std::string message ;
+#define RCPP_EXCEPTION_CLASS(__CLASS__,__WHAT__)                               \
+class __CLASS__ : public std::exception{                                       \
+public:                                                                        \
+	__CLASS__( const std::string& message ) throw() : message( __WHAT__ ){} ;  \
+	virtual ~__CLASS__() throw(){} ;                                           \
+	virtual const char* what() const throw(){ return message.c_str() ; } ;     \
+private:                                                                       \
+	std::string message ;                                                      \
 } ;
 
-class not_a_matrix : public std::exception{
-	public:
-		not_a_matrix(){} ;
-		virtual ~not_a_matrix() throw() {} ;
-		virtual const char* what() const throw() { return "not a matrix" ; };
-	} ;
-
-class index_out_of_bounds: public std::exception{
-   	public:
-   		index_out_of_bounds() throw(){};
-   		virtual ~index_out_of_bounds() throw(){};
-   		virtual const char* what() const throw(){ return "index out of bounds" ; } ;
-   	} ;
-   		
-class parse_error : public std::exception{
-	public:
-		parse_error() throw(){};
-		virtual ~parse_error() throw(){};
-		virtual const char* what() const throw(){ return "parse error" ; } ;
-	} ;
-
-class S4_creation_error : public std::exception{
-	public:
-		S4_creation_error(const std::string& klass) throw() : message("error creating object of S4 class : ") {
-			message += klass ;
-		} ;
-		virtual ~S4_creation_error() throw(){};
-		virtual const char* what() const throw(){ return "" ; } ;
-	private:
-		std::string message ;
+#define RCPP_SIMPLE_EXCEPTION_CLASS(__CLASS__,__MESSAGE__)                     \
+class __CLASS__ : public std::exception{                                       \
+public:                                                                        \
+	__CLASS__() throw() {} ;                                                   \
+	virtual ~__CLASS__() throw(){} ;                                           \
+	virtual const char* what() const throw(){ return __MESSAGE__ ; } ;         \
 } ;
 
+RCPP_SIMPLE_EXCEPTION_CLASS(not_a_matrix, "not a matrix" )
+RCPP_SIMPLE_EXCEPTION_CLASS(index_out_of_bounds, "index out of bounds" )
+RCPP_SIMPLE_EXCEPTION_CLASS(parse_error, "parse error") 
+RCPP_SIMPLE_EXCEPTION_CLASS(not_s4, "not an S4 object" )
+RCPP_SIMPLE_EXCEPTION_CLASS(no_such_slot, "no such slot" )
 
-/**
-  * Exception thrown when attempting to perform an operation on 
-  * a binding and there is no such binding
-  */
- class no_such_binding: public std::exception{
- 	public:
- 		
- 		/**
- 		 * @param binding name of the binding
- 		 */
- 		no_such_binding( const std::string& binding) throw() : 
- 		 	message( std::string("no such binding : '") + binding + "'" ) {};
- 		
- 		virtual ~no_such_binding() throw(){} ;
- 		
- 		/**
- 		 * The message: no such binding : '{binding}' 
- 		 */
- 		 virtual const char* what() const throw(){ return message.c_str() ; }
- 		
- 	private:
- 		std::string message ;
- } ;
-    
+RCPP_EXCEPTION_CLASS(not_compatible, message )
+RCPP_EXCEPTION_CLASS(S4_creation_error, std::string("error creating object of S4 class : ") + message )
+RCPP_EXCEPTION_CLASS(no_such_binding, std::string("no such binding : '") + message + "'" )
 
+#undef RCPP_EXCEPTION_CLASS
+#undef RCPP_SIMPLE_EXCEPTION_CLASS
+
 } // namesapce Rcpp
 
 #endif

Modified: pkg/Rcpp/src/RObject.cpp
===================================================================
--- pkg/Rcpp/src/RObject.cpp	2010-04-22 08:51:39 UTC (rev 1107)
+++ pkg/Rcpp/src/RObject.cpp	2010-04-22 09:15:20 UTC (rev 1108)
@@ -86,7 +86,7 @@
     return false; /* give up */
 }
 
-RObject::SlotProxy::SlotProxy( const RObject& v, const std::string& name) : 
+RObject::SlotProxy::SlotProxy( const RObject& v, const std::string& name) throw(no_such_slot) : 
 	parent(v), slot_name(name)
 {
 	if( !R_has_slot( v, Rf_install(name.c_str())) ){
@@ -99,9 +99,6 @@
 	return *this ;
 }
 
-const char* RObject::no_such_slot::what( ) const throw() {
-	return "no such slot" ;
-}
 
 SEXP RObject::SlotProxy::get() const {
 	return internal::try_catch( 
@@ -145,14 +142,10 @@
 	return R_has_slot( m_sexp, Rf_mkString(name.c_str()) ) ;
 }
 
-RObject::SlotProxy RObject::slot(const std::string& name) const throw(not_s4){
+RObject::SlotProxy RObject::slot(const std::string& name) const throw(not_s4,no_such_slot){
 	if( !Rf_isS4(m_sexp) ) throw not_s4() ;
 	return SlotProxy( *this, name ) ;
 }
 
-const char* RObject::not_s4::what( ) const throw() {
-	return "not an S4 object" ;
-}
-
 } // namespace Rcpp
 



More information about the Rcpp-commits mailing list