22 #ifndef Rcpp__vector__Vector_h
23 #define Rcpp__vector__Vector_h
28 template <
bool NA,
typename T>
class SingleLogicalResult ;
33 public VectorBase< RTYPE, true, Vector<RTYPE> >,
45 typedef typename traits::init_type<RTYPE>::type
init_type ;
47 typedef typename traits::storage_type<RTYPE>::type
stored_type ;
73 RCPP_DEBUG_2(
"Vector<%d>( const RObject::SlotProxy& proxy = <%p> )", RTYPE, m_sexp)
78 RCPP_DEBUG_2(
"Vector<%d>( const RObject::AttributeProxy& proxy = <%p> )", RTYPE, m_sexp)
82 RCPP_DEBUG_2(
"Vector<%d>( const int& size = %d, const stored_type& u )", RTYPE, size)
87 RCPP_DEBUG_2(
"Vector<%d>( const std::string& = %s )", RTYPE, st.c_str() )
91 RCPP_DEBUG_2(
"Vector<%d>( const int& siz = %s, stored_type (*gen)(void) )", RTYPE, siz )
94 while( first != last ) *first++ = gen() ;
99 template <
typename U>
Vector(
const Dimension&
dims,
const U& u) ;
101 template <
typename U>
Vector(
const int&
size,
const U& u) ;
102 template <
bool NA,
typename T>
Vector(
const sugar::SingleLogicalResult<NA,T>& obj ) ;
104 template <
typename U1>
107 template <
typename U1,
typename U2>
110 template <
typename U1,
typename U2,
typename U3>
111 Vector(
const int& siz,
stored_type (*gen)(U1,U2,U3),
const U1& u1,
const U2& u2,
const U3& u3) ;
113 template <
typename InputIterator>
114 Vector( InputIterator first, InputIterator last) ;
116 template <
typename InputIterator>
117 Vector( InputIterator first, InputIterator last,
int n) ;
119 template <
typename InputIterator,
typename Func>
120 Vector( InputIterator first, InputIterator last, Func func) ;
122 template <
typename InputIterator,
typename Func>
123 Vector( InputIterator first, InputIterator last, Func func,
int n) ;
125 #ifdef HAS_CXX0X_INITIALIZER_LIST
127 assign( list.begin() , list.end() ) ;
144 return internal::ListInitialization<iterator,init_type>( start + 1 ) ; ;
151 inline R_len_t
length()
const { return ::Rf_length( RObject::m_sexp ) ; }
156 inline R_len_t
size()
const { return ::Rf_length( RObject::m_sexp ) ; }
161 size_t offset(
const size_t&
i,
const size_t&
j)
const {
162 if( !::Rf_isMatrix(RObject::m_sexp) )
throw not_a_matrix() ;
165 size_t nrow =
static_cast<size_t>(dim[0]) ;
166 size_t ncol =
static_cast<size_t>(dim[1]) ;
167 if( i >= nrow || j >= ncol )
throw index_out_of_bounds() ;
176 if( static_cast<R_len_t>(i) >= ::Rf_length(RObject::m_sexp) )
throw index_out_of_bounds() ;
180 R_len_t
offset(
const std::string& name)
const {
182 if( names ==
R_NilValue )
throw index_out_of_bounds();
184 for( R_len_t
i=0;
i<
n; ++
i){
185 if( ! name.compare( CHAR(STRING_ELT(names,
i)) ) ){
189 throw index_out_of_bounds() ;
193 template <
typename U>
211 template <
typename T>
217 template <
typename T>
operator T()
const {
218 return Rcpp::as<T>(
get()) ;
228 void set(SEXP
x)
const {
231 if( TYPEOF(
x) == STRSXP &&
parent.
size() == Rf_length(
x) ){
233 Rf_setAttrib( y, R_NamesSymbol,
x ) ;
236 SEXP namesSym = Rf_install(
"names<-" );
249 return NamesProxy(*
this) ;
282 return NameProxy( const_cast<Vector&>(*
this), name ) ;
285 return NameProxy( const_cast<Vector&>(*
this), name ) ;
290 internal::r_vector_start<RTYPE>(m_sexp),
291 internal::r_vector_start<RTYPE>(m_sexp) +
size(),
292 typename traits::comparator_type<RTYPE>::type()
297 template <
typename InputIterator>
298 void assign( InputIterator first, InputIterator last){
302 SEXP
x =
PROTECT( r_cast<RTYPE>(
wrap( first, last ) ) );
303 RObject::setSEXP( x) ;
307 template <
typename InputIterator>
308 static Vector import( InputIterator first, InputIterator last){
310 v.
assign( first , last ) ;
314 template <
typename InputIterator,
typename F>
316 return Vector( first, last, f) ;
319 template <
typename T>
322 typename traits::same_type<stored_type,SEXP>()
326 template <
typename T>
327 void push_back(
const T&
object,
const std::string& name ){
329 typename traits::same_type<stored_type,SEXP>()
333 template <
typename T>
336 typename traits::same_type<stored_type,SEXP>() ) ;
339 template <
typename T>
342 typename traits::same_type<stored_type,SEXP>() ) ;
346 template <
typename T>
348 return insert__impl( position, converter_type::get(
object),
349 typename traits::same_type<stored_type,SEXP>()
353 template <
typename T>
356 typename traits::same_type<stored_type,SEXP>()
378 RCPP_DEBUG_2(
" update_vector( VECTOR = %s, SEXP = < %p > )",
DEMANGLE(
Vector), reinterpret_cast<void*>( RObject::asSexp() ) )
379 cache.update(*
this) ;
382 template <
typename U>
385 it, names, index, u ) ;
388 template <
typename U>
390 *it = converter_type::get(u);
393 template <
typename U>
398 template <
typename U>
400 RCPP_DEBUG_2(
" Vector::replace_element__dispatch<%s>(true, index= %d) ",
DEMANGLE(U), index ) ;
402 *it = converter_type::get(u.object ) ;
403 SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
406 template <
typename U>
408 RCPP_DEBUG_2(
" Vector::replace_element__dispatch<%s>(true, index= %d) ",
DEMANGLE(U), index ) ;
411 SET_STRING_ELT( names, index, ::Rf_mkChar( u.name.c_str() ) ) ;
415 RObject::setSEXP( x) ;
421 return Indexer( const_cast<Vector&>(*
this), range );
424 template <
typename EXPR_VEC>
427 template <
typename EXPR_VEC>
438 if( !::Rf_isMatrix(RObject::m_sexp) )
throw not_a_matrix() ;
439 return INTEGER( ::Rf_getAttrib( RObject::m_sexp, R_DimSymbol ) ) ;
442 RCPP_DEBUG_2(
"VECTOR<%d>::init( SEXP = <%p> )", RTYPE, RObject::m_sexp )
443 internal::r_init_vector<RTYPE>(RObject::m_sexp) ;
476 template <
bool NA,
typename VEC>
480 template <
bool NA,
typename VEC>
484 template <
typename T>
487 template <
typename T>
490 template <
typename T>
493 template <
typename T>
496 template <
typename U>
499 SEXP elem =
PROTECT( converter_type::get( u ) );
501 for(
int i=0;
i<
size() ;
i++, ++it){
502 *it = ::Rf_duplicate( elem ) ;
507 template <
typename U>
518 #include <Rcpp/generated/Vector__create.h>