Rcpp Version 0.12.12
wrap.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // wrap.h: Rcpp R/C++ interface class library -- wrap implementations
4 //
5 // Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp_api_meat_wrap_h
23 #define Rcpp_api_meat_wrap_h
24 
25 namespace Rcpp{
26 namespace internal{
27 
28 template <typename InputIterator, typename KEY, typename VALUE, int RTYPE>
29 inline SEXP range_wrap_dispatch___impl__pair( InputIterator first, InputIterator last, Rcpp::traits::true_type ){
30  RCPP_DEBUG_3( "range_wrap_dispatch___impl__pair<KEY = %s, VALUE = %s, RTYPE = %d>\n", DEMANGLE(KEY), DEMANGLE(VALUE), RTYPE)
31  R_xlen_t size = std::distance( first, last ) ;
32  //typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE ;
33 
34  CharacterVector names(size) ;
35  Vector<RTYPE> x(size) ;
36  Rcpp::String buffer ;
37  for( R_xlen_t i = 0; i < size ; i++, ++first){
38  buffer = first->first ;
39  x[i] = first->second ;
40  names[i] = buffer ;
41  }
42  x.attr( "names" ) = names ;
43  return x ;
44 }
45 
46 template <typename InputIterator, typename KEY, typename VALUE, int RTYPE>
47 inline SEXP range_wrap_dispatch___impl__pair( InputIterator first, InputIterator last, Rcpp::traits::false_type ){
48  R_xlen_t size = std::distance( first, last ) ;
49 
50  Shield<SEXP> names( Rf_allocVector(STRSXP, size) ) ;
51  Shield<SEXP> x( Rf_allocVector(VECSXP, size) ) ;
52  Rcpp::String buffer ;
53  for( R_xlen_t i = 0; i < size ; i++, ++first){
54  buffer = first->first ;
55  SET_VECTOR_ELT( x, i, Rcpp::wrap(first->second) );
56  SET_STRING_ELT( names, i, buffer.get_sexp() ) ;
57  }
58  ::Rf_setAttrib( x, R_NamesSymbol, names) ;
59  return x ;
60 }
61 
62 
63 } // namespace internal
64 } // namespace Rcpp
65 
66 #endif
AttributeProxy attr(const std::string &name)
SEXP get_sexp() const
Definition: String.h:367
#define DEMANGLE(__TYPE__)
Definition: exceptions.h:315
#define RCPP_DEBUG_3(fmt, M1, M2, M3)
Definition: debug.h:46
SEXP wrap(const Date &date)
Definition: Date.h:38
SEXP range_wrap_dispatch___impl__pair(InputIterator first, InputIterator last, Rcpp::traits::true_type)
Definition: wrap.h:29
Rcpp API.
Definition: algo.h:28