[Rcpp-commits] r783 - in pkg/Rcpp/src: . Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 24 13:24:30 CET 2010


Author: romain
Date: 2010-02-24 13:24:30 +0100 (Wed, 24 Feb 2010)
New Revision: 783

Added:
   pkg/Rcpp/src/Rcpp/exceptions.h
Modified:
   pkg/Rcpp/src/CharacterVector.cpp
   pkg/Rcpp/src/Rcpp.h
   pkg/Rcpp/src/Rcpp/CharacterVector.h
   pkg/Rcpp/src/Rcpp/MatrixColumn.h
   pkg/Rcpp/src/Rcpp/MatrixRow.h
   pkg/Rcpp/src/Rcpp/SEXP_Vector.h
   pkg/Rcpp/src/Rcpp/SimpleVector.h
   pkg/Rcpp/src/Rcpp/VectorBase.h
   pkg/Rcpp/src/VectorBase.cpp
Log:
factoring not_a_matrix exception class out of VectorBase

Modified: pkg/Rcpp/src/CharacterVector.cpp
===================================================================
--- pkg/Rcpp/src/CharacterVector.cpp	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/CharacterVector.cpp	2010-02-24 12:24:30 UTC (rev 783)
@@ -20,6 +20,7 @@
 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <Rcpp/CharacterVector.h>
+#include <Rcpp/exceptions.h>
 
 namespace Rcpp{
 

Modified: pkg/Rcpp/src/Rcpp/CharacterVector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/CharacterVector.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp/CharacterVector.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -23,6 +23,7 @@
 #define Rcpp_CharacterVector_h
 
 #include <RcppCommon.h>
+#include <Rcpp/exceptions.h>
 #include <Rcpp/VectorBase.h>
 #include <Rcpp/MatrixRow.h>
 #include <Rcpp/MatrixColumn.h>

Modified: pkg/Rcpp/src/Rcpp/MatrixColumn.h
===================================================================
--- pkg/Rcpp/src/Rcpp/MatrixColumn.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp/MatrixColumn.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -24,6 +24,7 @@
 
 #include <RcppCommon.h>
 #include <Rcpp/VectorBase.h>
+#include <Rcpp/exceptions.h>
 
 namespace Rcpp{
 
@@ -36,7 +37,7 @@
 	typedef typename VECTOR::iterator iterator ;
 	
 	MatrixColumn( VECTOR& object, int i ) : parent(object), index(i){
-		if( ! ::Rf_isMatrix(parent) ) throw VectorBase::not_a_matrix() ;
+		if( ! ::Rf_isMatrix(parent) ) throw not_a_matrix() ;
 		if( i < 0 || i >= parent.ncol() ) throw RObject::index_out_of_bounds() ;
 	}
 	

Modified: pkg/Rcpp/src/Rcpp/MatrixRow.h
===================================================================
--- pkg/Rcpp/src/Rcpp/MatrixRow.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp/MatrixRow.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -23,6 +23,7 @@
 #define Rcpp__MatrixRow_h
 
 #include <RcppCommon.h>
+#include <Rcpp/exceptions.h>
 #include <Rcpp/VectorBase.h>
 
 namespace Rcpp{
@@ -81,7 +82,7 @@
 	} ;
 	
 	MatrixRow( VECTOR& object, int i ) : parent(object), index(i){
-		if( ! ::Rf_isMatrix(parent) ) throw VectorBase::not_a_matrix() ;
+		if( ! ::Rf_isMatrix(parent) ) throw not_a_matrix() ;
 		if( i < 0 || i >= parent.nrow() ) throw RObject::index_out_of_bounds() ;
 	}
 	

Modified: pkg/Rcpp/src/Rcpp/SEXP_Vector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/SEXP_Vector.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp/SEXP_Vector.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -23,6 +23,7 @@
 #define Rcpp_SEXP_Vector_h
 
 #include <RcppCommon.h>
+#include <Rcpp/exceptions.h>
 #include <Rcpp/VectorBase.h>
 #include <Rcpp/MatrixRow.h>
 #include <Rcpp/MatrixColumn.h>

Modified: pkg/Rcpp/src/Rcpp/SimpleVector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/SimpleVector.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp/SimpleVector.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -99,7 +99,7 @@
 	inline reference operator()( const std::string& name) {
 		return start[ offset(name) ];
 	}
-	inline reference operator()( const size_t& i, const size_t& j) throw(VectorBase::not_a_matrix,RObject::index_out_of_bounds){
+	inline reference operator()( const size_t& i, const size_t& j) throw(not_a_matrix,RObject::index_out_of_bounds){
 		return start[ offset(i,j) ] ;
 	}
 	

Modified: pkg/Rcpp/src/Rcpp/VectorBase.h
===================================================================
--- pkg/Rcpp/src/Rcpp/VectorBase.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp/VectorBase.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -23,6 +23,7 @@
 #define Rcpp_VectorBase_h
 
 #include <RcppCommon.h>
+#include <Rcpp/exceptions.h>
 #include <Rcpp/RObject.h>
 #include <Rcpp/r_cast.h>
 
@@ -30,13 +31,7 @@
 
 class VectorBase : public RObject {     
 public:
-	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" ; };
-	} ;
-  
+	
     VectorBase() ;
     virtual ~VectorBase() ;
 
@@ -102,7 +97,7 @@
 private:
 		
 	inline int* dims(){
-		if( !::Rf_isMatrix(m_sexp) ) throw VectorBase::not_a_matrix() ;
+		if( !::Rf_isMatrix(m_sexp) ) throw not_a_matrix() ;
 		return INTEGER( ::Rf_getAttrib( m_sexp, ::Rf_install( "dim") ) ) ;
 	}
 	

Added: pkg/Rcpp/src/Rcpp/exceptions.h
===================================================================
--- pkg/Rcpp/src/Rcpp/exceptions.h	                        (rev 0)
+++ pkg/Rcpp/src/Rcpp/exceptions.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -0,0 +1,36 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// exceptions.h: Rcpp R/C++ interface class library -- exceptions
+//
+// 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__exceptions__h
+#define Rcpp__exceptions__h
+
+namespace Rcpp{
+
+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" ; };
+	} ;
+  
+} // namesapce Rcpp
+
+#endif

Modified: pkg/Rcpp/src/Rcpp.h
===================================================================
--- pkg/Rcpp/src/Rcpp.h	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/Rcpp.h	2010-02-24 12:24:30 UTC (rev 783)
@@ -49,6 +49,7 @@
 
 #include <Rcpp/RObject.h>
 
+#include <Rcpp/exceptions.h>
 #include <Rcpp/clone.h>
 #include <Rcpp/grow.h>
 #include <Rcpp/Dimension.h>

Modified: pkg/Rcpp/src/VectorBase.cpp
===================================================================
--- pkg/Rcpp/src/VectorBase.cpp	2010-02-24 12:15:16 UTC (rev 782)
+++ pkg/Rcpp/src/VectorBase.cpp	2010-02-24 12:24:30 UTC (rev 783)
@@ -20,6 +20,7 @@
 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <RcppCommon.h>
+#include <Rcpp/exceptions.h>
 #include <Rcpp/VectorBase.h>
 #include <Rcpp/CharacterVector.h>
 
@@ -29,7 +30,7 @@
 	VectorBase::~VectorBase(){}
 	
 	size_t VectorBase::offset( const size_t& i, const size_t& j) const throw(not_a_matrix,RObject::index_out_of_bounds) {
-		if( !Rf_isMatrix(m_sexp) ) throw VectorBase::not_a_matrix() ;
+		if( !Rf_isMatrix(m_sexp) ) throw not_a_matrix() ;
 		/* we need to extract the dimensions */
 		int *dim = INTEGER( Rf_getAttrib( m_sexp, R_DimSymbol ) ) ;
 		size_t nrow = static_cast<size_t>(dim[0]) ;



More information about the Rcpp-commits mailing list