Skip to content

Commit b20f886

Browse files
added StretchyList::(push_front,push_back,get)
1 parent e7fd179 commit b20f886

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

inst/include/Rcpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#include <Rcpp/Language.h>
4949
#include <Rcpp/DottedPair.h>
5050
#include <Rcpp/Pairlist.h>
51-
#include <Rcpp/StrechyList.h>
51+
#include <Rcpp/StretchyList.h>
5252

5353
#include <Rcpp/WeakReference.h>
5454
#include <Rcpp/StringTransformer.h>

inst/include/Rcpp/StretchyList.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,35 @@
2323
namespace Rcpp{
2424

2525
RCPP_API_CLASS(StretchyList_Impl),
26-
public DottedPairProxyPolicy<StretchyList_Impl<StoragePolicy> >,
27-
public DottedPairImpl<StretchyList_Impl<StoragePolicy> >{
26+
public DottedPairProxyPolicy<StretchyList_Impl<StoragePolicy> > {
2827
public:
2928

3029
RCPP_GENERATE_CTOR_ASSIGN(StretchyList_Impl)
3130

3231
typedef typename DottedPairProxyPolicy<StretchyList_Impl>::DottedPairProxy Proxy ;
3332
typedef typename DottedPairProxyPolicy<StretchyList_Impl>::const_DottedPairProxy const_Proxy ;
3433

35-
StretchyList_Impl(){}
34+
StretchyList_Impl(){
35+
SEXP s = Rf_cons(R_NilValue, R_NilValue);
36+
SETCAR(s, s);
37+
Storage::set__(s) ;
38+
}
3639
StretchyList_Impl(SEXP x){
3740
Storage::set__(r_cast<LISTSXP>(x)) ;
3841
}
3942

4043
void update(SEXP x){}
4144

45+
inline operator SEXP() const{
46+
return CDR(Storage::get__() );
47+
}
48+
49+
template <typename T>
50+
StretchyList_Impl& push_back(const T& obj ) ;
51+
52+
template <typename T>
53+
StretchyList_Impl& push_front(const T& obj ) ;
54+
4255
} ;
4356

4457
typedef StretchyList_Impl<PreserveStorage> StretchyList ;

inst/include/Rcpp/api/meat/DottedPairImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Copyright (C) 2013 Romain Francois
22
//
3-
// This file is part of Rcpp11.
3+
// This file is part of Rcpp.
44
//
5-
// Rcpp11 is free software: you can redistribute it and/or modify it
5+
// Rcpp is free software: you can redistribute it and/or modify it
66
// under the terms of the GNU General Public License as published by
77
// the Free Software Foundation, either version 2 of the License, or
88
// (at your option) any later version.
99
//
10-
// Rcpp11 is distributed in the hope that it will be useful, but
10+
// Rcpp is distributed in the hope that it will be useful, but
1111
// WITHOUT ANY WARRANTY; without even the implied warranty of
1212
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
// GNU General Public License for more details.
1414
//
1515
// You should have received a copy of the GNU General Public License
16-
// along with Rcpp11. If not, see <http://www.gnu.org/licenses/>.
16+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
1717

1818
#ifndef Rcpp_api_meat_DottedPairImpl_h
1919
#define Rcpp_api_meat_DottedPairImpl_h
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (C) 2013 Romain Francois
2+
//
3+
// This file is part of Rcpp.
4+
//
5+
// Rcpp is free software: you can redistribute it and/or modify it
6+
// under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 2 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Rcpp is distributed in the hope that it will be useful, but
11+
// WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#ifndef Rcpp_api_meat_StretchyList_h
19+
#define Rcpp_api_meat_StretchyList_h
20+
21+
namespace Rcpp{
22+
23+
template< template <class> class StoragePolicy>
24+
template< typename T>
25+
StretchyList_Impl<StoragePolicy>& StretchyList_Impl<StoragePolicy>::push_back( const T& obj){
26+
Shield<SEXP> s( wrap(obj) ) ;
27+
SEXP tmp = Rf_cons( s, R_NilValue );
28+
SEXP self = Storage::get__() ;
29+
SETCDR( CAR(self), tmp) ;
30+
SETCAR( self, tmp ) ;
31+
return *this ;
32+
}
33+
34+
template< template <class> class StoragePolicy>
35+
template< typename T>
36+
StretchyList_Impl<StoragePolicy>& StretchyList_Impl<StoragePolicy>::push_front( const T& obj){
37+
SEXP tmp ;
38+
SEXP self = Storage::get__() ;
39+
Shield<SEXP> s( wrap(obj) ) ;
40+
tmp = Rf_cons(s, CDR(self) ) ;
41+
SETCDR(self, tmp) ;
42+
return *this ;
43+
}
44+
45+
46+
}
47+
48+
#endif

inst/include/Rcpp/api/meat/meat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <Rcpp/api/meat/Environment.h>
4242

4343
#include <Rcpp/api/meat/DottedPairImpl.h>
44+
#include <Rcpp/api/meat/StretchyList.h>
4445
#include <Rcpp/api/meat/Vector.h>
4546
#include <Rcpp/api/meat/Matrix.h>
4647
#include <Rcpp/api/meat/is.h>

0 commit comments

Comments
 (0)