generateStructInterface: Generate R and C interface code to create, access and set...

Description Usage Arguments Value Author(s) References See Also

View source: R/struct.R

Description

This function is a high-level function that operates on the description of a single C level structure definition and generates the R and C code to interface to instances of that structure. It generates a parallel R class that has the same slot names as fields in the C structure with the equivalent types in R. Additionally, it creates a class that can be used to hold a pointer to a C-level instance of the C structure via an externalptr in R. Also, it generates R functions and corresponding C routines to create new instances of this C-level data type and to access the fields individually and also to copy an entire C-level instance to its R equivalent. In other words, it allows the R user to work with the structure either in R or in C and to access all parts of it.

Usage

1
2
3
generateStructInterface(type, classDefs, typeMap = list(),
                          defaultBaseClass = "RC++StructReference")
createCopyStruct(def, className = def@name, isClass = FALSE, typeMap = list())

Arguments

type

an object representing the resolved type definition of a C-level structure. In other words, it should be an object created by a call to resolveType (either implicitly or explicitly) and either a StructDefinition or a TypedefDefinition corresponding to a typedef in R which leads to a StructDefinition.

typeMap

an optional type mapping specifying the correspondence between the R and C-level data types and how they can be converted from one to another. This is used to define the types of the R slots corresponding to the fields in the C structure and how to convert between them. This is optional and the default mappings will work in pretty much all cases. This allows one to customize the mappings with contextual information/knowledge.

classDefs

the DefinitionContainer-class object associated with the translation unit parser. This stores the resolved types so they do not need to be resolved many times, each time they are encountered. This is obtained from the translation unit parser (of class GCCTUParserDynClass-class) via the DefinitionContainer function.

def

the description of the class/struct definition.

className

the name of the struct/C++ class

isClass

a logical value indicating wehther this is a C++ class or a regular C struct.

defaultBaseClass

the name of the R class which is used as the base class for the class that is a reference to this struct/C++ class. This allows the caller to use a different base class with a different representation or methods.

Value

A list of class CStructInterface which can be passed to writeCode. The list has the following components:

generic
rFunctions
cRoutines
clasDefs
coerce
newInst
freeInst

Author(s)

Duncan Temple Lang

References

The GCC Translation Unit

See Also

createInterface


omegahat/RGCCTranslationUnit documentation built on May 24, 2019, 1:53 p.m.