PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/r/srun.swg

#
Unknown | 150 lines | 108 code | 42 blank | 0 comment | 0 complexity | ce9e2d3e1ccfa6471828970707cf69ff MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # srun.swg #
  2. #
  3. # This is the basic code that is needed at run time within R to
  4. # provide and define the relevant classes. It is included
  5. # automatically in the generated code by copying the contents of
  6. # srun.swg into the newly created binding code.
  7. # This could be provided as a separate run-time library but this
  8. # approach allows the code to to be included directly into the
  9. # generated bindings and so removes the need to have and install an
  10. # additional library. We may however end up with multiple copies of
  11. # this and some confusion at run-time as to which class to use. This
  12. # is an issue when we use NAMESPACES as we may need to export certain
  13. # classes.
  14. ######################################################################
  15. if(length(getClassDef("RSWIGStruct")) == 0)
  16. setClass("RSWIGStruct", representation("VIRTUAL"))
  17. if(length(getClassDef("ExternalReference")) == 0)
  18. # Should be virtual but this means it loses its slots currently
  19. #representation("VIRTUAL")
  20. setClass("ExternalReference", representation( ref = "externalptr"))
  21. if(length(getClassDef("NativeRoutinePointer")) == 0)
  22. setClass("NativeRoutinePointer",
  23. representation(parameterTypes = "character",
  24. returnType = "character",
  25. "VIRTUAL"),
  26. contains = "ExternalReference")
  27. if(length(getClassDef("CRoutinePointer")) == 0)
  28. setClass("CRoutinePointer", contains = "NativeRoutinePointer")
  29. if(length(getClassDef("EnumerationValue")) == 0)
  30. setClass("EnumerationValue", contains = "integer")
  31. if(!isGeneric("copyToR"))
  32. setGeneric("copyToR",
  33. function(value, obj = new(gsub("Ref$", "", class(value))))
  34. standardGeneric("copyToR"
  35. ))
  36. setGeneric("delete", function(obj) standardGeneric("delete"))
  37. SWIG_createNewRef =
  38. function(className, ..., append = TRUE)
  39. {
  40. f = get(paste("new", className, sep = "_"), mode = "function")
  41. f(...)
  42. }
  43. if(!isGeneric("copyToC"))
  44. setGeneric("copyToC",
  45. function(value, obj = RSWIG_createNewRef(class(value)))
  46. standardGeneric("copyToC"
  47. ))
  48. #
  49. defineEnumeration =
  50. function(name, .values, where = topenv(parent.frame()), suffix = "Value")
  51. {
  52. # Mirror the class definitions via the E analogous to .__C__
  53. defName = paste(".__E__", name, sep = "")
  54. assign(defName, .values, envir = where)
  55. if(nchar(suffix))
  56. name = paste(name, suffix, sep = "")
  57. setClass(name, contains = "EnumerationValue", where = where)
  58. }
  59. enumToInteger <- function(name,type)
  60. {
  61. if (is.character(name)) {
  62. ans <- as.integer(get(paste(".__E__", type, sep = ""))[name])
  63. if (is.na(ans)) {warning("enum not found ", name, " ", type)}
  64. ans
  65. }
  66. }
  67. enumFromInteger =
  68. function(i,type)
  69. {
  70. itemlist <- get(paste(".__E__", type, sep=""))
  71. names(itemlist)[match(i, itemlist)]
  72. }
  73. coerceIfNotSubclass =
  74. function(obj, type)
  75. {
  76. if(!is(obj, type)) {as(obj, type)} else obj
  77. }
  78. setClass("SWIGArray", representation(dims = "integer"), contains = "ExternalReference")
  79. setMethod("length", "SWIGArray", function(x) x@dims[1])
  80. defineEnumeration("SCopyReferences",
  81. .values = c( "FALSE" = 0, "TRUE" = 1, "DEEP" = 2))
  82. assert =
  83. function(condition, message = "")
  84. {
  85. if(!condition)
  86. stop(message)
  87. TRUE
  88. }
  89. if(FALSE) {
  90. print.SWIGFunction =
  91. function(x, ...)
  92. {
  93. }
  94. }
  95. #######################################################################
  96. R_SWIG_getCallbackFunctionStack =
  97. function()
  98. {
  99. # No PACKAGE argument as we don't know what the DLL is.
  100. .Call("R_SWIG_debug_getCallbackFunctionData")
  101. }
  102. R_SWIG_addCallbackFunctionStack =
  103. function(fun, userData = NULL)
  104. {
  105. # No PACKAGE argument as we don't know what the DLL is.
  106. .Call("R_SWIG_R_pushCallbackFunctionData", fun, userData)
  107. }
  108. #######################################################################