@@ -49,7 +49,7 @@ class Vector :
49
49
typedef typename traits::init_type<RTYPE>::type init_type ;
50
50
typedef typename traits::r_vector_element_converter<RTYPE>::type converter_type ;
51
51
typedef typename traits::storage_type<RTYPE>::type stored_type ;
52
-
52
+
53
53
/* *
54
54
* Default constructor. Creates a vector of the appropriate type
55
55
* and 0 length
@@ -96,7 +96,7 @@ class Vector :
96
96
RCPP_DEBUG_2 ( " Vector<%d>( const char* = %s )" , RTYPE, st )
97
97
Storage::set__ (internal::vector_from_string<RTYPE>(st) ) ;
98
98
}
99
-
99
+
100
100
Vector ( const int & siz, stored_type (*gen)(void ) ) {
101
101
RCPP_DEBUG_2 ( " Vector<%d>( const int& siz = %s, stored_type (*gen)(void) )" , RTYPE, siz )
102
102
Storage::set__ ( Rf_allocVector ( RTYPE, siz) ) ;
@@ -134,7 +134,7 @@ class Vector :
134
134
Vector ( const int & size, const U& u) {
135
135
RCPP_DEBUG_2 ( " Vector<%d>( const int& size, const U& u )" , RTYPE, size )
136
136
Storage::set__ ( Rf_allocVector ( RTYPE, size) ) ;
137
- fill_or_generate ( u ) ;
137
+ fill_or_generate ( u ) ;
138
138
}
139
139
template <bool NA, typename T>
140
140
Vector ( const sugar::SingleLogicalResult<NA,T>& obj ) {
@@ -199,13 +199,13 @@ class Vector :
199
199
assign ( list.begin () , list.end () ) ;
200
200
}
201
201
#endif
202
-
202
+
203
203
template <typename T>
204
204
Vector& operator =( const T& x) {
205
205
assign_object ( x, typename traits::is_sugar_expression<T>::type () ) ;
206
206
return *this ;
207
207
}
208
-
208
+
209
209
static inline stored_type get_na () {
210
210
return traits::get_na<RTYPE>();
211
211
}
@@ -279,7 +279,7 @@ class Vector :
279
279
inline iterator end () { return cache.get () + size () ; }
280
280
inline const_iterator begin () const { return cache.get_const () ; }
281
281
inline const_iterator end () const { return cache.get_const () + size () ; }
282
-
282
+
283
283
inline Proxy operator []( int i ){ return cache.ref (i) ; }
284
284
inline const_Proxy operator []( int i ) const { return cache.ref (i) ; }
285
285
@@ -296,14 +296,14 @@ class Vector :
296
296
inline const_Proxy operator ()( const size_t & i, const size_t & j) const {
297
297
return cache.ref ( offset (i,j) ) ;
298
298
}
299
-
299
+
300
300
inline NameProxy operator []( const std::string& name ){
301
301
return NameProxy ( *this , name ) ;
302
302
}
303
303
inline NameProxy operator ()( const std::string& name ){
304
304
return NameProxy ( *this , name ) ;
305
305
}
306
-
306
+
307
307
inline NameProxy operator []( const std::string& name ) const {
308
308
return NameProxy ( const_cast <Vector&>(*this ), name ) ;
309
309
}
@@ -349,8 +349,9 @@ class Vector :
349
349
/* FIXME: we can do better than this r_cast to avoid
350
350
allocating an unnecessary temporary object
351
351
*/
352
- Shield<SEXP> x ( r_cast<RTYPE>( wrap ( first, last ) ) );
353
- Storage::set__ ( x) ;
352
+ Shield<SEXP> wrapped (wrap (first, last));
353
+ Shield<SEXP> casted (r_cast<RTYPE>(wrapped));
354
+ Storage::set__ (casted) ;
354
355
}
355
356
356
357
template <typename InputIterator>
@@ -364,80 +365,80 @@ class Vector :
364
365
static Vector import_transform ( InputIterator first, InputIterator last, F f){
365
366
return Vector ( first, last, f) ;
366
367
}
367
-
368
+
368
369
template <typename T>
369
370
void push_back ( const T& object){
370
371
push_back__impl ( converter_type::get (object),
371
372
typename traits::same_type<stored_type,SEXP>()
372
373
) ;
373
374
}
374
-
375
+
375
376
template <typename T>
376
377
void push_back ( const T& object, const std::string& name ){
377
378
push_back_name__impl ( converter_type::get (object), name,
378
379
typename traits::same_type<stored_type,SEXP>()
379
380
) ;
380
381
}
381
-
382
+
382
383
template <typename T>
383
384
void push_front ( const T& object){
384
385
push_front__impl ( converter_type::get (object),
385
386
typename traits::same_type<stored_type,SEXP>() ) ;
386
387
}
387
-
388
+
388
389
template <typename T>
389
390
void push_front ( const T& object, const std::string& name){
390
391
push_front_name__impl ( converter_type::get (object), name,
391
392
typename traits::same_type<stored_type,SEXP>() ) ;
392
393
}
393
-
394
-
394
+
395
+
395
396
template <typename T>
396
397
iterator insert ( iterator position, const T& object){
397
398
return insert__impl ( position, converter_type::get (object),
398
399
typename traits::same_type<stored_type,SEXP>()
399
400
) ;
400
401
}
401
-
402
+
402
403
template <typename T>
403
404
iterator insert ( int position, const T& object){
404
405
return insert__impl ( cache.get () + position, converter_type::get (object),
405
406
typename traits::same_type<stored_type,SEXP>()
406
407
);
407
408
}
408
-
409
+
409
410
iterator erase ( int position){
410
411
return erase_single__impl ( cache.get () + position) ;
411
412
}
412
-
413
+
413
414
iterator erase ( iterator position){
414
415
return erase_single__impl ( position ) ;
415
416
}
416
-
417
+
417
418
iterator erase ( int first, int last){
418
419
iterator start = cache.get () ;
419
420
return erase_range__impl ( start + first, start + last ) ;
420
421
}
421
-
422
+
422
423
iterator erase ( iterator first, iterator last){
423
424
return erase_range__impl ( first, last ) ;
424
425
}
425
-
426
+
426
427
void update (SEXP){
427
428
cache.update (*this ) ;
428
429
}
429
-
430
+
430
431
template <typename U>
431
432
static void replace_element ( iterator it, SEXP names, int index, const U& u){
432
433
replace_element__dispatch ( typename traits::is_named<U>::type (),
433
434
it, names, index, u ) ;
434
435
}
435
-
436
+
436
437
template <typename U>
437
438
static void replace_element__dispatch ( traits::false_type, iterator it, SEXP names, int index, const U& u){
438
439
*it = converter_type::get (u);
439
440
}
440
-
441
+
441
442
template <typename U>
442
443
static void replace_element__dispatch ( traits::true_type, iterator it, SEXP names, int index, const U& u){
443
444
replace_element__dispatch__isArgument ( typename traits::same_type<U,Argument>(), it, names, index, u ) ;
@@ -446,21 +447,21 @@ class Vector :
446
447
template <typename U>
447
448
static void replace_element__dispatch__isArgument ( traits::false_type, iterator it, SEXP names, int index, const U& u){
448
449
RCPP_DEBUG_2 ( " Vector::replace_element__dispatch<%s>(true, index= %d) " , DEMANGLE (U), index ) ;
449
-
450
+
450
451
*it = converter_type::get (u.object ) ;
451
452
SET_STRING_ELT ( names, index, ::Rf_mkChar ( u.name .c_str () ) ) ;
452
453
}
453
-
454
+
454
455
template <typename U>
455
456
static void replace_element__dispatch__isArgument ( traits::true_type, iterator it, SEXP names, int index, const U& u){
456
457
RCPP_DEBUG_2 ( " Vector::replace_element__dispatch<%s>(true, index= %d) " , DEMANGLE (U), index ) ;
457
-
458
+
458
459
*it = R_MissingArg ;
459
460
SET_STRING_ELT ( names, index, ::Rf_mkChar ( u.name .c_str () ) ) ;
460
461
}
461
462
462
463
typedef internal::RangeIndexer<RTYPE,true ,Vector> Indexer ;
463
-
464
+
464
465
inline Indexer operator []( const Range& range ){
465
466
return Indexer ( const_cast <Vector&>(*this ), range );
466
467
}
@@ -589,7 +590,7 @@ class Vector :
589
590
*target_it = object;
590
591
Storage::set__ ( target.get__ () ) ;
591
592
}
592
-
593
+
593
594
void push_back_name__impl (const stored_type& object, const std::string& name, traits::true_type ) {
594
595
Shield<SEXP> object_sexp ( object ) ;
595
596
int n = size () ;
@@ -613,7 +614,7 @@ class Vector :
613
614
}
614
615
SET_STRING_ELT ( newnames, i, Rf_mkChar ( name.c_str () ) );
615
616
target.attr (" names" ) = newnames ;
616
-
617
+
617
618
*target_it = object_sexp;
618
619
Storage::set__ ( target.get__ () ) ;
619
620
}
@@ -640,11 +641,11 @@ class Vector :
640
641
}
641
642
SET_STRING_ELT ( newnames, i, Rf_mkChar ( name.c_str () ) );
642
643
target.attr (" names" ) = newnames ;
643
-
644
+
644
645
*target_it = object;
645
646
Storage::set__ ( target.get__ () ) ;
646
647
}
647
-
648
+
648
649
void push_front__impl (const stored_type& object, traits::true_type ) {
649
650
Shield<SEXP> object_sexp ( object ) ;
650
651
int n = size () ;
@@ -698,7 +699,7 @@ class Vector :
698
699
Storage::set__ ( target.get__ () ) ;
699
700
700
701
}
701
-
702
+
702
703
void push_front_name__impl (const stored_type& object, const std::string& name, traits::true_type ) {
703
704
Shield<SEXP> object_sexp (object) ;
704
705
int n = size () ;
@@ -712,7 +713,7 @@ class Vector :
712
713
SET_STRING_ELT ( newnames, 0 , Rf_mkChar ( name.c_str () ) );
713
714
*target_it = object_sexp;
714
715
++target_it ;
715
-
716
+
716
717
if ( Rf_isNull (names) ){
717
718
for ( ; it < this_end; ++it, ++target_it,i++ ){
718
719
*target_it = *it ;
@@ -740,7 +741,7 @@ class Vector :
740
741
SET_STRING_ELT ( newnames, 0 , Rf_mkChar ( name.c_str () ) );
741
742
*target_it = object;
742
743
++target_it ;
743
-
744
+
744
745
if ( Rf_isNull (names) ){
745
746
for ( ; it < this_end; ++it, ++target_it,i++ ){
746
747
*target_it = *it ;
@@ -753,11 +754,11 @@ class Vector :
753
754
}
754
755
}
755
756
target.attr (" names" ) = newnames ;
756
-
757
+
757
758
Storage::set__ ( target.get__ () ) ;
758
759
759
760
}
760
-
761
+
761
762
iterator insert__impl ( iterator position, const stored_type& object_, traits::true_type ) {
762
763
Shield<SEXP> object ( object_ ) ;
763
764
int n = size () ;
@@ -838,7 +839,7 @@ class Vector :
838
839
Storage::set__ ( target.get__ () ) ;
839
840
return result ;
840
841
}
841
-
842
+
842
843
iterator erase_single__impl ( iterator position ) {
843
844
if ( position < begin () || position > end () ) throw index_out_of_bounds ( ) ;
844
845
int n = size () ;
@@ -877,18 +878,18 @@ class Vector :
877
878
return begin ()+result ;
878
879
}
879
880
}
880
-
881
+
881
882
iterator erase_range__impl ( iterator first, iterator last ) {
882
883
if ( first > last ) throw std::range_error (" invalid range" ) ;
883
884
if ( last > end () || first < begin () ) throw index_out_of_bounds () ;
884
-
885
+
885
886
iterator it = begin () ;
886
887
iterator this_end = end () ;
887
888
int nremoved = std::distance (first,last) ;
888
889
int target_size = size () - nremoved ;
889
890
Vector target ( target_size ) ;
890
891
iterator target_it = target.begin () ;
891
-
892
+
892
893
SEXP names = RCPP_GET_NAMES (Storage::get__ ()) ;
893
894
iterator result ;
894
895
if ( Rf_isNull (names) ){
@@ -928,7 +929,9 @@ class Vector :
928
929
import_expression<T>(x, n ) ;
929
930
} else {
930
931
// different size, so we change the memory
931
- Storage::set__ ( r_cast<RTYPE>( wrap (x) ) );
932
+ Shield<SEXP> wrapped (wrap (x));
933
+ Shield<SEXP> casted (r_cast<RTYPE>(wrapped));
934
+ Storage::set__ (casted);
932
935
}
933
936
}
934
937
@@ -945,7 +948,7 @@ class Vector :
945
948
Shield<SEXP> casted (r_cast<RTYPE>(wrapped));
946
949
Storage::set__ (casted);
947
950
}
948
-
951
+
949
952
// we are importing a real sugar expression, i.e. not a vector
950
953
template <bool NA, typename VEC>
951
954
inline void import_sugar_expression ( const Rcpp::VectorBase<RTYPE,NA,VEC>& other, traits::false_type ) {
@@ -995,7 +998,7 @@ class Vector :
995
998
*it = ::Rf_duplicate ( elem ) ;
996
999
}
997
1000
}
998
-
1001
+
999
1002
template <typename U>
1000
1003
void fill__dispatch ( traits::true_type, const U& u){
1001
1004
std::fill ( begin (), end (), converter_type::get ( u ) ) ;
0 commit comments