@@ -252,17 +252,30 @@ cppFunction <- function(code,
252252 }
253253}
254254
255- # demangling a type
256- demangle <- function ( type = " int" , ... ){
257- code <- sprintf( '
258- String demangle_this_type(){
259- typedef %s type ;
260- return DEMANGLE(type) ;
261- }' , type )
262- dots <- list ( code , ... )
263- dots [[" env" ]] <- environment()
264- do.call( cppFunction , dots )
265- demangle_this_type()
255+ .type_manipulate <- function ( what = " DEMANGLE" , class = NULL ) {
256+ function ( type = " int" , ... ){
257+ code <- sprintf( '
258+ SEXP manipulate_this_type(){
259+ typedef %s type ;
260+ return wrap( %s(type) ) ;
261+ }' , type , what )
262+ dots <- list ( code , ... )
263+ dots [[" env" ]] <- environment()
264+ manipulate_this_type <- do.call( cppFunction , dots )
265+ res <- manipulate_this_type()
266+ if ( ! is.null(class ) ){
267+ class(res ) <- class
268+ }
269+ res
270+ }
271+ }
272+
273+ demangle <- .type_manipulate( " DEMANGLE" )
274+ sizeof <- .type_manipulate( " sizeof" , " bytes" )
275+
276+ print.bytes <- function ( x , ... ){
277+ writeLines( sprintf( " %d bytes (%d bits)" , x , 8 * x ) )
278+ invisible ( x )
266279}
267280
268281# Evaluate a simple c++ expression
0 commit comments