[Rcpp-commits] r4105 - in pkg/Rcpp: inst/include/Rcpp inst/include/Rcpp/api/meat inst/include/Rcpp/vector src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Dec 6 14:10:30 CET 2012


Author: romain
Date: 2012-12-06 14:10:29 +0100 (Thu, 06 Dec 2012)
New Revision: 4105

Added:
   pkg/Rcpp/inst/include/Rcpp/api/meat/Matrix.h
   pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h
   pkg/Rcpp/inst/include/Rcpp/vector/no_init.h
Removed:
   pkg/Rcpp/inst/include/Rcpp/vector/CharacterVectorExtractionIterator.h
Modified:
   pkg/Rcpp/inst/include/Rcpp/Dimension.h
   pkg/Rcpp/inst/include/Rcpp/Vector.h
   pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h
   pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h
   pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h
   pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
   pkg/Rcpp/inst/include/Rcpp/vector/proxy.h
   pkg/Rcpp/src/Dimension.cpp
Log:
moving headers

Modified: pkg/Rcpp/inst/include/Rcpp/Dimension.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Dimension.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/Dimension.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -2,7 +2,7 @@
 //
 // Dimension.h: Rcpp R/C++ interface class library -- dimensions
 //
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -22,32 +22,34 @@
 #ifndef Rcpp_Dimension_h
 #define Rcpp_Dimension_h
 
-#include <RcppCommon.h>
+#define R_NO_REMAP
+#include <Rinternals.h>
+#include <vector>
  
 namespace Rcpp{ 
 
     class Dimension {
     public:
-	typedef std::vector<int>::reference reference ;
-	typedef std::vector<int>::const_reference const_reference ;
-	
-	Dimension() ;
-	Dimension(SEXP dims);
-	Dimension( const Dimension& other ) ;
-	Dimension& operator=( const Dimension& other ) ;
-	Dimension(const size_t& n1) ;
-	Dimension(const size_t& n1, const size_t& n2) ;
-	Dimension(const size_t& n1, const size_t& n2, const size_t& n3) ;
-	operator SEXP() const ;
-	
-	int size() const ;
-	int prod() const ;
-	
-	reference operator[](int i);
-	const_reference operator[](int i) const;
-	
-    private:
-	std::vector<int> dims;
+	    typedef std::vector<int>::reference reference ;
+	    typedef std::vector<int>::const_reference const_reference ;
+	    
+	    Dimension() ;
+	    Dimension(SEXP dims);
+	    Dimension( const Dimension& other ) ;
+	    Dimension& operator=( const Dimension& other ) ;
+	    Dimension(const size_t& n1) ;
+	    Dimension(const size_t& n1, const size_t& n2) ;
+	    Dimension(const size_t& n1, const size_t& n2, const size_t& n3) ;
+	    operator SEXP() const ;
+	    
+	    int size() const ;
+	    int prod() const ;
+	    
+	    reference operator[](int i);
+	    const_reference operator[](int i) const;
+	    
+        private:
+	    std::vector<int> dims;
     };
 
 }

Modified: pkg/Rcpp/inst/include/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Vector.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/Vector.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -27,7 +27,6 @@
 #include <Rcpp/exceptions.h>
 #include <Rcpp/RObject.h>
 #include <Rcpp/r_cast.h>
-#include <Rcpp/Dimension.h>
 
 namespace Rcpp{
     namespace traits{
@@ -38,6 +37,9 @@
 namespace Rcpp{
 
 #include <Rcpp/vector/00_forward_Vector.h>
+}
+#include <Rcpp/vector/no_init.h>
+namespace Rcpp{
 #include <Rcpp/vector/00_forward_proxy.h>
 #include <Rcpp/vector/00_forward_eval_methods.h>
 
@@ -64,14 +66,7 @@
 }
 
 #include <Rcpp/String.h>
-
-namespace Rcpp{
 #include <Rcpp/vector/LazyVector.h>
-
-#include <Rcpp/vector/CharacterVectorExtractionIterator.h>
-
-}  // Rcpp
-
 #include <Rcpp/vector/swap.h>
 
 #endif 

Added: pkg/Rcpp/inst/include/Rcpp/api/meat/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/Matrix.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/Matrix.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -0,0 +1,54 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Matrix.h: Rcpp R/C++ interface class library -- Matrix meat 
+//
+// Copyright (C) 2012    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_api_meat_Matrix_h
+#define Rcpp_api_meat_Matrix_h
+
+namespace Rcpp{ 
+
+    template <int RTYPE>
+    Matrix<RTYPE>::Matrix( const Dimension& dims) : VECTOR(), nrows(dims[0]) {
+        if( dims.size() != 2 ) throw not_compatible("not a matrix") ;
+        VECTOR::setSEXP( Rf_allocMatrix( RTYPE, dims[0], dims[1] ) ) ;
+        VECTOR::init() ;
+    }
+    
+    template <int RTYPE>
+    Matrix<RTYPE>::Matrix( const int& nrows_, const int& ncols) : 
+        VECTOR( Dimension( nrows_, ncols ) ), 
+        nrows(nrows_)
+    {}
+     
+    template <int RTYPE>
+    template <typename Iterator>
+    Matrix<RTYPE>::Matrix( const int& nrows_, const int& ncols, Iterator start ) : 
+        VECTOR( start, start + (nrows_*ncols) ),
+        nrows(nrows_)
+    {
+        VECTOR::attr( "dim" ) = Dimension( nrows, ncols ) ; 
+    }
+    
+    template <int RTYPE>
+    Matrix<RTYPE>::Matrix( const int& n) : VECTOR( Dimension( n, n ) ), nrows(n) {}
+    
+} // namespace Rcpp
+
+#endif

Added: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -0,0 +1,127 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Vector.h: Rcpp R/C++ interface class library -- Vector meat 
+//
+// Copyright (C) 2012    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_api_meat_Vector_h
+#define Rcpp_api_meat_Vector_h
+
+namespace Rcpp{ 
+
+    template <int RTYPE>
+    Vector<RTYPE>::Vector() : RObject() {
+        RCPP_DEBUG( "Vector()" ) ;
+        RObject::setSEXP( Rf_allocVector( RTYPE, 0 ) ) ;
+        init() ;
+    } ;
+    
+    template <int RTYPE>
+    Vector<RTYPE>::~Vector(){
+         RCPP_DEBUG( "~Vector()" )   
+    }
+    
+    template <int RTYPE>
+    Vector<RTYPE>::Vector( const Vector& other) : RObject(){
+         RObject::setSEXP( other.asSexp() ) ;   
+    }
+    
+    template <int RTYPE>
+    Vector<RTYPE>& Vector<RTYPE>::operator=(const Vector& other){
+        RObject::setSEXP( other.asSexp() ) ;
+        return *this ;    
+    }
+    
+    template <int RTYPE>
+    Vector<RTYPE>::Vector( const int& size ) : RObject()  {
+    	RCPP_DEBUG_2( "Vector<%d>( int = %d )", RTYPE, size ) ;
+    	RObject::setSEXP( Rf_allocVector( RTYPE, size) ) ;
+        init() ;
+    }
+    
+    template <int RTYPE>
+    Vector<RTYPE>::Vector( const Dimension& dims ) : RObject(){
+        RObject::setSEXP( Rf_allocVector( RTYPE, dims.prod() ) ) ;
+        init() ;
+        if( dims.size() > 1 ){
+            RObject::attr( "dim" ) = dims;
+        }    
+    }
+    
+    template <int RTYPE>
+    template <typename U>
+    Vector<RTYPE>::Vector( const Dimension& dims, const U& u) : RObject() {
+    	RObject::setSEXP( Rf_allocVector( RTYPE, dims.prod() ) ) ;
+        fill(u) ;
+        if( dims.size() > 1 ){
+            RObject::attr( "dim" ) = dims;
+        }
+    }
+    
+    template <int RTYPE>
+    template <bool NA, typename VEC>
+    Vector<RTYPE>::Vector( const VectorBase<RTYPE,NA,VEC>& other ) : RObject() {
+    	import_sugar_expression( other, typename traits::same_type<Vector,VEC>::type() ) ;
+    }
+    
+    template <>
+    template <bool NA, typename T>
+    Vector<LGLSXP>::Vector( const sugar::SingleLogicalResult<NA,T>& obj ) : RObject() {
+    	RObject::setSEXP( const_cast<sugar::SingleLogicalResult<NA,T>&>( obj ) .get_sexp() ) ;
+    }
+    
+    
+    template <int RTYPE>
+    template <typename T> 
+    Vector<RTYPE>& Vector<RTYPE>::operator=( const T &x ){
+        assign_object( x, typename traits::is_sugar_expression<T>::type() ) ;
+        return *this ;
+    }
+    
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::assign_sugar_expression( const T& x ){
+        int n = size() ;
+        if( n == x.size() ){
+            // just copy the data 
+            import_expression<T>(x, n ) ;
+        } else{
+            // different size, so we change the memory
+            RObject::setSEXP( r_cast<RTYPE>( wrap(x) ) ); 
+        }
+    }
+    
+    // sugar
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::assign_object( const T& x, traits::true_type ){
+        assign_sugar_expression( x.get_ref() ) ;
+    }
+    
+    // anything else
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::assign_object( const T& x, traits::false_type ){
+        // TODO: maybe we already have the memory to host the results
+        RObject::setSEXP( r_cast<RTYPE>( wrap(x) ) ) ;
+    }
+    
+    
+} // namespace Rcpp
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/meat.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -25,5 +25,7 @@
 #include <Rcpp/api/meat/RObject.h>
 #include <Rcpp/api/meat/Environment.h>
 #include <Rcpp/api/meat/DottedPair.h>
+#include <Rcpp/api/meat/Vector.h>
+#include <Rcpp/api/meat/Matrix.h>
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/vector/00_forward_proxy.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -22,9 +22,6 @@
 #ifndef Rcpp__vector__forward_proxy_h
 #define Rcpp__vector__forward_proxy_h
 
-// const iterator for CharacterVector
-class CharacterVectorExtractionIterator ;
-
 namespace internal{
 	template <int RTYPE> class string_proxy ;
 	template <int RTYPE> class generic_proxy ;

Deleted: pkg/Rcpp/inst/include/Rcpp/vector/CharacterVectorExtractionIterator.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/CharacterVectorExtractionIterator.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/vector/CharacterVectorExtractionIterator.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -1,68 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
-//
-// CharacterVectorExtractionIterator.h: Rcpp R/C++ interface class library -- extract string from CharacterVector
-//
-// Copyright (C) 2012 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__vector__CharacterVectorExtractionIterator_h
-#define Rcpp__vector__CharacterVectorExtractionIterator_h
-
-// const iterator for CharacterVector
-// this is faster than the regular proxy iterator because it works directly 
-// on a SEXP*. 
-class CharacterVectorExtractionIterator {
-public:
-    typedef int difference_type;
-    typedef const char* value_type;
-    typedef const char** pointer;
-    typedef const char*& reference;
-    typedef std::input_iterator_tag iterator_category;
-    
-    CharacterVectorExtractionIterator( const CharacterVector& vec) : ptr( get_string_ptr(vec) ){}
-    
-    CharacterVectorExtractionIterator( const CharacterVectorExtractionIterator& other) : ptr(other.ptr){}
-    CharacterVectorExtractionIterator& operator=(const CharacterVectorExtractionIterator& other){ ptr = other.ptr ; return *this ;}
-    
-    int operator-( const CharacterVectorExtractionIterator& other){ return ptr - other.ptr ; }
-    
-    CharacterVectorExtractionIterator operator+( int n){ return CharacterVectorExtractionIterator(ptr+n); }
-    CharacterVectorExtractionIterator operator-( int n){ return CharacterVectorExtractionIterator(ptr-n); }
-    
-    CharacterVectorExtractionIterator& operator++(){ ptr++ ; return *this ; }
-    CharacterVectorExtractionIterator& operator--(){ ptr-- ; return *this ; }
-    CharacterVectorExtractionIterator& operator+=(int n){ ptr += n; return *this ; }
-    CharacterVectorExtractionIterator& operator-=(int n){ ptr -= n; return *this ; }
-    
-    bool operator<( const CharacterVectorExtractionIterator& other ){ return ptr < other.ptr ; }
-    bool operator>( const CharacterVectorExtractionIterator& other ){ return ptr > other.ptr ; }
-    bool operator<=( const CharacterVectorExtractionIterator& other ){ return ptr <= other.ptr ; }
-    bool operator>=( const CharacterVectorExtractionIterator& other ){ return ptr >= other.ptr ; }
-    
-    value_type  operator*(){ return char_nocheck(*ptr) ; }
-    value_type  operator[](int n){ return char_nocheck(ptr[n]) ; }
-    bool operator==(const CharacterVectorExtractionIterator& other) const { return ptr == other.ptr ;}
-    bool operator!=(const CharacterVectorExtractionIterator& other) const { return ptr != other.ptr ;}    
-      
-        
-private:
-    SEXP* ptr ; 
-    CharacterVectorExtractionIterator( SEXP* ptr_ ) : ptr(ptr_){}
-    
-};
-
-#endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/vector/LazyVector.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -2,7 +2,7 @@
 //
 // LazyVector.h: Rcpp R/C++ interface class library -- lazy vectors
 //
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -22,6 +22,7 @@
 #ifndef Rcpp__vector__LazyVector_h
 #define Rcpp__vector__LazyVector_h
 
+namespace Rcpp{
 namespace internal{
         
 template <typename VECTOR>
@@ -65,5 +66,5 @@
 
         
 } // internal
-
+} // Rcpp 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Matrix.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -22,6 +22,8 @@
 #ifndef Rcpp__vector__Matrix_h
 #define Rcpp__vector__Matrix_h
 
+class Dimension ;
+
 template <int RTYPE> 
 class Matrix : public Vector<RTYPE>, public MatrixBase<RTYPE,true, Matrix<RTYPE> > {
 public:
@@ -45,26 +47,14 @@
         nrows = VECTOR::dims()[0] ;
     }
         
-    Matrix( const Dimension& dims) : VECTOR(), nrows(dims[0]) {
-        if( dims.size() != 2 ) throw not_compatible("not a matrix") ;
-        VECTOR::setSEXP( Rf_allocMatrix( RTYPE, dims[0], dims[1] ) ) ;
-        VECTOR::init() ;
-    }
+    Matrix( const Dimension& dims)  ;
         
-    Matrix( const int& nrows_, const int& ncols) : 
-        VECTOR( Dimension( nrows_, ncols ) ), 
-        nrows(nrows_)
-    {}
+    Matrix( const int& nrows_, const int& ncols)  ;
         
     template <typename Iterator>
-    Matrix( const int& nrows_, const int& ncols, Iterator start ) : 
-        VECTOR( start, start + (nrows_*ncols) ),
-        nrows(nrows_)
-    {
-        VECTOR::attr( "dim" ) = Dimension( nrows, ncols ) ; 
-    }
+    Matrix( const int& nrows_, const int& ncols, Iterator start ) ;
         
-    Matrix( const int& n) : VECTOR( Dimension( n, n ) ), nrows(n) {}
+    Matrix( const int& n) ; 
         
     Matrix( const Matrix& other) : VECTOR(), nrows(other.nrows) {
         SEXP x = other.asSexp() ;

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -22,18 +22,11 @@
 #ifndef Rcpp__vector__Vector_h
 #define Rcpp__vector__Vector_h
 
-class no_init {
-public:
-    no_init(int size_): size(size_){}
-    inline int get() const { return size; }
-    
-    template <int RTYPE>
-    operator Vector<RTYPE>(){ return Rf_allocVector(RTYPE, size) ; }
-    
-private:
-    int size ;
-} ;
+// forward declarations
+class Dimension ;
 
+template <bool NA,typename T> class SingleLogicalResult ;
+
 template <int RTYPE>
 class Vector :
     public RObject,       
@@ -51,67 +44,61 @@
     typedef typename traits::r_vector_element_converter<RTYPE>::type converter_type ;
     typedef typename traits::storage_type<RTYPE>::type stored_type ;
 	
-    Vector() : RObject() {
-        RCPP_DEBUG( "Vector()" ) ;
-        RObject::setSEXP( Rf_allocVector( RTYPE, 0 ) ) ;
-        init() ;
-    } ;
-    ~Vector(){
-    	RCPP_DEBUG( "~Vector()" ) ;
-    };
+    /** 
+     * Default constructor. Creates a vector of the appropriate type
+     * and 0 length
+     */
+    Vector() ;
     
-    Vector( const Vector& other) : RObject() {
-        set_sexp( other.asSexp() ) ;
-    }
+    /**
+     * Destructor. Prints some information id debugging is enabled
+     */
+    ~Vector() ;
+    
+    /**
+     * copy constructor. shallow copy of the SEXP
+     */
+    Vector( const Vector& other) ;
 	
-    Vector& operator=( const Vector& other ){
-        set_sexp( other.asSexp() ) ;
-        return *this ;
-    }
+    /**
+     * Assignment operator. Grab the SEXP of the other vector
+     */
+    Vector& operator=( const Vector& other ) ;
 	
+    Vector( SEXP x ) : RObject() {
+    	RCPP_DEBUG_2( "Vector<%d>( SEXP = <%p> )", RTYPE, x)
+    	RObject::setSEXP( r_cast<RTYPE>( x ) ) ;
+    }
+    Vector( const int& size )  ;
+    Vector( const Dimension& dims)  ;
+    template <typename U> Vector( const Dimension& dims, const U& u) ;
+    template <bool NA, typename VEC> Vector( const VectorBase<RTYPE,NA,VEC>& other )  ;
+    
     Vector( const RObject::SlotProxy& proxy ) {
         RObject::setSEXP( r_cast<RTYPE>( (SEXP)proxy ) ) ;
     }
-	
+    
     Vector( const RObject::AttributeProxy& proxy ) {
         RObject::setSEXP( r_cast<RTYPE>( (SEXP)proxy ) ) ;
     }
 		
-    template <typename T>
-    Vector& operator=( const T& x){
-        assign_object( x, typename traits::is_sugar_expression<T>::type() ) ;
-        return *this ;
-    }
+    template <typename T> Vector& operator=( const T& x) ;
 	
+    // only defined for LogicalVectors
+    template <bool NA, typename T> Vector( const sugar::SingleLogicalResult<NA,T>& obj ) ;  ;
+    
     static inline stored_type get_na() { return traits::get_na<RTYPE>(); }
     static inline bool is_na( stored_type x){ return traits::is_na<RTYPE>(x); }
     
 private:
     
-    template <typename T>
-    inline void assign_sugar_expression( const T& x ){
-        int n = size() ;
-        if( n == x.size() ){
-            // just copy the data 
-            import_expression<T>(x, n ) ;
-        } else{
-            // different size, so we change the memory
-            set_sexp( r_cast<RTYPE>( wrap(x) ) ); 
-        }
-    }
+    template <typename T> inline void assign_sugar_expression( const T& x ) ;
     
     // sugar
-    template <typename T>
-    inline void assign_object( const T& x, traits::true_type ){
-        assign_sugar_expression( x.get_ref() ) ;
-    }
+    template <typename T> inline void assign_object( const T& x, traits::true_type )  ;
     
     // anything else
-    template <typename T>
-    inline void assign_object( const T& x, traits::false_type ){
-        // TODO: maybe we already have the memory to host the results
-        set_sexp( r_cast<RTYPE>( wrap(x) ) ) ;
-    }
+    template <typename T> inline void assign_object( const T& x, traits::false_type ) ;
     
 public:
 	
@@ -120,29 +107,7 @@
         return internal::ListInitialization<iterator,init_type>( start + 1 ) ; ;
     }
 	
-    Vector( SEXP x ) : RObject() {
-    	RCPP_DEBUG_2( "Vector<%d>( SEXP = <%p> )", RTYPE, x) ;
-    	RObject::setSEXP( r_cast<RTYPE>( x ) ) ;
-    	RCPP_DEBUG( "===========" ) ;
-    }
     
-    Vector( const int& size ) : RObject()  {
-    	RCPP_DEBUG_2( "Vector<%d>( int = %d )", RTYPE, size ) ;
-    	RObject::setSEXP( Rf_allocVector( RTYPE, size) ) ;
-        init() ;
-    }
-    
-    template <bool NA, typename VEC>
-    Vector( const VectorBase<RTYPE,NA,VEC>& other ) : RObject() {
-    	import_sugar_expression( other, typename traits::same_type<Vector,VEC>::type() ) ;
-    }
-    
-    // should eally onlu be used for LogicalVector. 
-    template <bool NA, typename T>
-    Vector( const sugar::SingleLogicalResult<NA,T>& obj ) : RObject() {
-    	RObject::setSEXP( r_cast<RTYPE>( const_cast<sugar::SingleLogicalResult<NA,T>&>( obj ) .get_sexp() ) ) ;
-    }
-    
 private:
 	  
     // we are importing a real sugar expression, i.e. not a vector
@@ -227,24 +192,6 @@
     	while( first != last ) *first++ = gen(u1,u2,u3) ;
     }
 
-    Vector( const Dimension& dims) : RObject() {
-    	RObject::setSEXP( Rf_allocVector( RTYPE, dims.prod() ) ) ;
-        init() ;
-        if( dims.size() > 1 ){
-            RObject::attr( "dim" ) = dims;
-        }
-    }
-    
-    template <typename U>
-    Vector( const Dimension& dims, const U& u) : RObject() {
-    	RObject::setSEXP( Rf_allocVector( RTYPE, dims.prod() ) ) ;
-        fill(u) ;
-        if( dims.size() > 1 ){
-            RObject::attr( "dim" ) = dims;
-        }
-    }
-    
-   
     template <typename InputIterator>
     Vector( InputIterator first, InputIterator last) : RObject( ){
         int n = std::distance(first, last) ;
@@ -525,7 +472,7 @@
     }
 	
     void update_vector(){
-        RCPP_DEBUG_2(  " update_vector( VECTOR = %s, SEXP = < %p > )", DEMANGLE(Vector), reinterpret_cast<void*>( RObject::asSexp() ) ) ;
+        RCPP_DEBUG_2(  " update_vector( VECTOR = %s, SEXP = < %p > )", DEMANGLE(Vector), reinterpret_cast<void*>( RObject::asSexp() ) )
         cache.update(*this) ;
     }
 		

Added: pkg/Rcpp/inst/include/Rcpp/vector/no_init.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/no_init.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/vector/no_init.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -0,0 +1,40 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// Vector.h: Rcpp R/C++ interface class library -- vectors
+//
+// Copyright (C) 2010 - 2012 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__vector__no_init_h
+#define Rcpp__vector__no_init_h
+  
+namespace Rcpp{
+    
+class no_init {
+public:
+    no_init(int size_): size(size_){}
+    inline int get() const { return size; }
+    
+    template <int RTYPE>
+    operator Vector<RTYPE>(){ return Rf_allocVector(RTYPE, size) ; }
+    
+private:
+    int size ;
+} ;
+  
+}
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/vector/proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/proxy.h	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/inst/include/Rcpp/vector/proxy.h	2012-12-06 13:10:29 UTC (rev 4105)
@@ -229,15 +229,6 @@
 	struct r_vector_const_proxy{
 		typedef const typename storage_type<RTYPE>::type& type ;
 	} ;                                            
-	// template<> struct r_vector_const_proxy<STRSXP> {
-	// 	typedef ::Rcpp::internal::string_proxy<STRSXP> type ;
-	// } ;
-	// template<> struct r_vector_const_proxy<EXPRSXP> {
-	// 	typedef ::Rcpp::internal::generic_proxy<EXPRSXP> type ;
-	// } ;
-	// template<> struct r_vector_const_proxy<VECSXP> {
-	// 	typedef ::Rcpp::internal::generic_proxy<VECSXP> type ;
-	// } ;
 
 	template <int RTYPE>
 	struct r_vector_iterator {
@@ -255,15 +246,6 @@
 	template<> struct r_vector_iterator<EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
 	template<> struct r_vector_iterator<STRSXP> : proxy_based_iterator<STRSXP>{} ;
 
-	// template <int RTYPE> struct proxy_based_const_iterator{
-	// 	typedef ::Rcpp::internal::SEXP_Iterator<RTYPE, Vector<RTYPE> > type ;
-	// } ;
-	// template<> struct r_vector_const_iterator<VECSXP> : proxy_based_const_iterator<VECSXP>{} ;
-	// template<> struct r_vector_const_iterator<EXPRSXP> : proxy_based_const_iterator<EXPRSXP>{} ;
-	// template<> struct r_vector_const_iterator<STRSXP> {
-	//     typedef CharacterVectorExtractionIterator type ;
-	// } ;
-
 }  // traits
 
 

Modified: pkg/Rcpp/src/Dimension.cpp
===================================================================
--- pkg/Rcpp/src/Dimension.cpp	2012-12-06 13:03:01 UTC (rev 4104)
+++ pkg/Rcpp/src/Dimension.cpp	2012-12-06 13:10:29 UTC (rev 4105)
@@ -19,6 +19,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
 
+#include <RcppCommon.h>
 #include <Rcpp/Dimension.h>
 
 namespace Rcpp{



More information about the Rcpp-commits mailing list