1- # Copyright (C) 2010 - 2014 John Chambers, Dirk Eddelbuettel and Romain Francois
1+ # Copyright (C) 2010 - 2016 John Chambers, Dirk Eddelbuettel and Romain Francois
22#
33# This file is part of Rcpp.
44#
@@ -41,12 +41,12 @@ setMethod("$", "C++Class", function(x, name) {
4141
4242.getModulePointer <- function (module , mustStart = TRUE ) {
4343 pointer <- get(" pointer" , envir = as.environment(module ))
44- if (is.null(pointer ) && mustStart ) {
44+ if (is.null(pointer ) && mustStart ) { # #nocov start
4545 # # should be (except for bug noted in identical())
4646 # # if(identical(pointer, .badModulePointer) && mustStart) {
4747 Module(module , mustStart = TRUE ) # will either initialize pointer or throw error
4848 pointer <- get(" pointer" , envir = as.environment(module ))
49- }
49+ } # #nocov end
5050 pointer
5151}
5252
@@ -62,51 +62,51 @@ setMethod("initialize", "Module",
6262 assign(" packageName" , packageName , envir = env )
6363 assign(" moduleName" , moduleName , envir = env )
6464 if (length(list (... )) > 0 ) {
65- .Object <- callNextMethod(.Object , ... )
65+ .Object <- callNextMethod(.Object , ... ) # #nocov
6666 }
6767 .Object
6868 })
6969
7070.get_Module_function <- function (x , name , pointer = .getModulePointer(x ) ){
7171 pointer <- .getModulePointer(x )
72- info <- .Call( Module__get_function , pointer , name )
73- fun_ptr <- info [[1L ]]
74- is_void <- info [[2L ]]
75- doc <- info [[3L ]]
76- sign <- info [[4L ]]
77- formal_args <- info [[5L ]]
78- nargs <- info [[6L ]]
79- f <- function (... ) NULL
80- if ( nargs == 0L ) formals(f ) <- NULL
81- stuff <- list ( fun_pointer = fun_ptr , InternalFunction_invoke = InternalFunction_invoke )
82- body(f ) <- if ( nargs == 0L ){
83- if ( is_void ) {
84- substitute( {
85- .External( InternalFunction_invoke , fun_pointer )
86- invisible (NULL )
87- }, stuff )
88- } else {
89- substitute( {
90- .External( InternalFunction_invoke , fun_pointer )
91- }, stuff )
92- }
93- } else {
94- if ( is_void ) {
95- substitute( {
96- .External( InternalFunction_invoke , fun_pointer , ... )
97- invisible (NULL )
98- }, stuff )
99- } else {
100- substitute( {
101- .External( InternalFunction_invoke , fun_pointer , ... )
102- }, stuff )
103- }
104- }
105- out <- new( " C++Function" , f , pointer = fun_ptr , docstring = doc , signature = sign )
106- if ( ! is.null( formal_args ) ){
107- formals( out ) <- formal_args
108- }
109- out
72+ info <- .Call( Module__get_function , pointer , name )
73+ fun_ptr <- info [[1L ]]
74+ is_void <- info [[2L ]]
75+ doc <- info [[3L ]]
76+ sign <- info [[4L ]]
77+ formal_args <- info [[5L ]]
78+ nargs <- info [[6L ]]
79+ f <- function (... ) NULL
80+ if ( nargs == 0L ) formals(f ) <- NULL
81+ stuff <- list ( fun_pointer = fun_ptr , InternalFunction_invoke = InternalFunction_invoke )
82+ body(f ) <- if ( nargs == 0L ){
83+ if ( is_void ) {
84+ substitute( { # #nocov start
85+ .External( InternalFunction_invoke , fun_pointer )
86+ invisible (NULL )
87+ }, stuff ) # #nocov end
88+ } else {
89+ substitute( {
90+ .External( InternalFunction_invoke , fun_pointer )
91+ }, stuff )
92+ }
93+ } else {
94+ if ( is_void ) {
95+ substitute( { # #nocov start
96+ .External( InternalFunction_invoke , fun_pointer , ... )
97+ invisible (NULL )
98+ }, stuff ) # #nocov end
99+ } else {
100+ substitute( {
101+ .External( InternalFunction_invoke , fun_pointer , ... )
102+ }, stuff )
103+ }
104+ }
105+ out <- new( " C++Function" , f , pointer = fun_ptr , docstring = doc , signature = sign )
106+ if ( ! is.null( formal_args ) ){
107+ formals( out ) <- formal_args # #nocov
108+ }
109+ out
110110}
111111
112112.get_Module_Class <- function ( x , name , pointer = .getModulePointer(x ) ){
@@ -115,18 +115,18 @@ setMethod("initialize", "Module",
115115 value
116116}
117117
118- setMethod ( "$ ", "Module", function(x, name){
118+ setMethod ( "$ ", "Module", function(x, name){ # #nocov start
119119 pointer <- .getModulePointer(x )
120120 storage <- get( " storage" , envir = as.environment(x ) )
121121 storage [[ name ]]
122- } )
122+ } ) # #nocov end
123123
124124new_CppObject_xp <- function (module , pointer , ... ) {
125- .External( class__newInstance , module , pointer , ... )
125+ .External( class__newInstance , module , pointer , ... )
126126}
127127
128- new_dummyObject <- function (... )
129- .External( class__dummyInstance , ... )
128+ new_dummyObject <- function (... ) # #nocov
129+ .External( class__dummyInstance , ... ) # #nocov
130130
131131
132132# class method for $initialize
@@ -142,7 +142,7 @@ cpp_object_initializer <- function(.self, .refClassDef, ..., .object_pointer){
142142 .self
143143}
144144
145- cpp_object_dummy <- function (.self , .refClassDef ) {
145+ cpp_object_dummy <- function (.self , .refClassDef ) { # #nocov start
146146 selfEnv <- as.environment(.self )
147147 # # like initializer but a dummy for the case of no default
148148 # # constructor. Will throw an error if the object is used.
@@ -152,7 +152,7 @@ cpp_object_dummy <- function(.self, .refClassDef) {
152152 assign(" .pointer" , pointer , envir = selfEnv )
153153 assign(" .cppclass" , fields $ .pointer , envir = selfEnv )
154154 .self
155- }
155+ } # #nocov end
156156
157157cpp_object_maker <- function (typeid , pointer ){
158158 Class <- .classes_map [[ typeid ]]
@@ -178,10 +178,10 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
178178 # # perhaps keep a vector of all known module pointers
179179 # # [John] One technique is to initialize the pointer to a known value
180180 # # and just check whether it's been reset from that (bad) value
181- xp <- module
181+ xp <- module # #nocov start
182182 moduleName <- .Call( Module__name , xp )
183183 module <- methods :: new(" Module" , pointer = xp , packageName = PACKAGE ,
184- moduleName = moduleName )
184+ moduleName = moduleName ) # #nocov end
185185 } else if (is.character(module )) {
186186 moduleName <- module
187187 xp <- .badModulePointer
@@ -250,7 +250,7 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
250250
251251 # [romain] : should this be promoted to reference classes
252252 # perhaps with better handling of j and ... arguments
253- if ( any( grepl( " ^[[]" , names(CLASS @ methods ) ) ) ){
253+ if ( any( grepl( " ^[[]" , names(CLASS @ methods ) ) ) ){ # #nocov start
254254 if ( " [[" %in% names( CLASS @ methods ) ){
255255 methods :: setMethod ( "[[ ", clname, function(x, i, j, ..., exact = TRUE){
256256 x $ `[[`( i )
@@ -263,11 +263,11 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
263263 x
264264 } , where = where )
265265 }
266- }
266+ } # #nocov end
267267
268268 # promoting show to S4
269269 if ( any( grepl( " show" , names(CLASS @ methods ) ) ) ){
270- setMethod ( "show ", clname, function(object) object$show(), where = where )
270+ setMethod ( "show ", clname, function(object) object$show(), where = where ) # #nocov
271271 }
272272
273273 }
@@ -284,11 +284,11 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
284284 # exposing enums values as CLASS.VALUE
285285 # (should really be CLASS$value but I don't know how to do it)
286286 if ( length( CLASS @ enums ) ){
287- for ( enum in CLASS @ enums ){
287+ for ( enum in CLASS @ enums ){ # #nocov start
288288 for ( i in 1 : length(enum ) ){
289289 storage [[ paste( demangled_name , " ." , names(enum )[i ], sep = " " ) ]] <- enum [i ]
290290 }
291- }
291+ } # #nocov end
292292 }
293293
294294 }
@@ -300,7 +300,7 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
300300
301301 # register as(FROM, TO) methods
302302 converter_rx <- " ^[.]___converter___(.*)___(.*)$"
303- if ( length( matches <- grep( converter_rx , functions ) ) ){
303+ if ( length( matches <- grep( converter_rx , functions ) ) ){ # #nocov start
304304 for ( i in matches ){
305305 fun <- function s [i ]
306306 from <- sub( converter_rx , " \\ 1" , fun )
@@ -311,15 +311,15 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
311311 )
312312 setAs( from , to , converter , where = where )
313313 }
314- }
314+ } # #nocov end
315315
316316 }
317317
318318 assign( " storage" , storage , envir = as.environment(module ) )
319319 module
320320}
321321
322- dealWith <- function ( x ) if (isTRUE(x [[1 ]])) invisible (NULL ) else x [[2 ]]
322+ dealWith <- function ( x ) if (isTRUE(x [[1 ]])) invisible (NULL ) else x [[2 ]] # #nocov
323323
324324method_wrapper <- function ( METHOD , where ){
325325 noargs <- all( METHOD $ nargs == 0 )
@@ -357,11 +357,11 @@ method_wrapper <- function( METHOD, where ){
357357 } else {
358358 # some are void, some are not, so the voidness is part of the result
359359 # we get from internally and we need to deal with it
360- substitute(
361- {
362- docstring
363- dealWith( .External(CppMethod__invoke , class_pointer , pointer , .pointer ) )
364- } , stuff )
360+ substitute( # #nocov start
361+ {
362+ docstring
363+ dealWith( .External(CppMethod__invoke , class_pointer , pointer , .pointer ) )
364+ } , stuff ) # #nocov end
365365 }
366366 } else {
367367 if ( all( METHOD $ void ) ){
@@ -383,33 +383,33 @@ method_wrapper <- function( METHOD, where ){
383383 } else {
384384 # some are void, some are not, so the voidness is part of the result
385385 # we get from internally and we need to deal with it
386- substitute(
387- {
388- docstring
389- dealWith( .External(CppMethod__invoke , class_pointer , pointer , .pointer , ... ) )
390- } , stuff )
386+ substitute( # #nocov start
387+ {
388+ docstring
389+ dealWith( .External(CppMethod__invoke , class_pointer , pointer , .pointer , ... ) )
390+ } , stuff ) # #nocov end
391391 }
392392 }
393393 body(f , where ) <- extCall
394394 f
395- }
395+ }
396396# # create a named list of the R methods to invoke C++ methods
397397# # from the C++ class with pointer xp
398398cpp_refMethods <- function (CLASS , where ) {
399399 finalizer <- eval( substitute(
400- function (){
401- .Call( CppObject__finalize , class_pointer , .pointer )
402- },
403- list (
404- CLASS = CLASS @ pointer ,
405- CppObject__finalize = CppObject__finalize ,
406- class_pointer = CLASS @ pointer
407- )
408- ) )
409- mets <- c(
410- sapply( CLASS @ methods , method_wrapper , where = where ),
411- " finalize" = finalizer
412- )
400+ function (){
401+ .Call( CppObject__finalize , class_pointer , .pointer )
402+ },
403+ list (
404+ CLASS = CLASS @ pointer ,
405+ CppObject__finalize = CppObject__finalize ,
406+ class_pointer = CLASS @ pointer
407+ )
408+ ) )
409+ mets <- c(
410+ sapply( CLASS @ methods , method_wrapper , where = where ),
411+ " finalize" = finalizer
412+ )
413413 mets
414414}
415415
@@ -437,5 +437,5 @@ cpp_fields <- function( CLASS, where){
437437}
438438
439439.CppClassName <- function (name ) {
440- paste0(" Rcpp_" ,name )
440+ paste0(" Rcpp_" ,name ) # #nocov
441441}
0 commit comments