class GenType { public: virtual const char* paramDecl() = 0; virtual const char* resultDecl() = 0; virtual const char* requiredLine() = 0; virtual const char* conversionLine(const char* argname) = 0; virtual const char* convertedParam(const char* argname) = 0; virtual const char* callAssignment() = 0; virtual const char* returnLine() = 0; };
For each type we want SG to support, we use a GenType object to specify all the information it needs to know about this type:
const char* paramDecl()
: paramDecl
returns the associated CORBA/C++ type used for function parameters. For instace, paramDecl()
of the GenType
for HxCorba.ImageRep
should return HxCorba::ImageRep_ptr
.
const char* resultDecl()
: resultDecl
returns the associated CORBA/C++ type used as result type. For instace, resultDecl()
of the GenType
for HxCorba.ImageRep
should return also HxCorba::ImageRep_ptr
.
const char* requiredLine()
: requiredLine
returns a line of code that has to be added to the implementation file before any function that uses the type. The GenType
for enumerators uses this feature.
const char* conversionLine(const char* argname)
: conversionLine
returns the line of code used to convert from the CORBA/C++ type to the HORUS related type. argname
is the name of the variable that contains the CORBA/C++ value. For instace, conversionLine("im")
of the GenType
for HxCorba.ImageRep
should return HxImageRep _im_arg = HxGetTiedObject<HxImageRepTiedSvt>(_server, im);
.
const char* convertedParam(const char* argname)
: convertedParam
returns the variable name used to retrieve the result of the conversion. Usualy, convertedParam("N")
returns "_N_arg"
. If there is no need of conversion, it returns "N"
itself.
const char* callAssignment()
: callAssignment
returns how to hold the value returned by the call to the HORUS global function. For instance, callAssignment()
of the GenType
for HxCorba.ImageRep
should return HxImageRep _result =
.
const char* returnLine()
: returnLine
returns the return statement of the generated function. It contains the conversion, if needed, from the HORUS value to the related CORBA/C++ type. For instance, returnLine()
of the GenType
for HxCorba.ImageRep
should return return HxRegisterTiedServant<HxImageRepTiedSvt>(_server, _result);
.
The class SampleGenType
can be used to easily create GenTypes. The idea is to build GenType objects just providing a pice of code like:
HxCorba::ImageRep_ptr HxGlobalOpsGenSvt::HxAbs(HxCorba::ImageRep_ptr im) { HxImageRep _im_arg = HxGetTiedObject<HxImageRepTiedSvt>(_server, im); HxImageRep _result = ::HxAbs(_im_arg); return HxRegisterTiedServant<HxImageRepTiedSvt>(_server, _result); }
SampleGenType extracts all the information it needs from this code.
SampleGenType takes the sample code in a TypeSample struct:
struct TypeSample { char* func_name; char* arg_name; char* header; char* conversionLine; char* callAssignment; char* returnLine; };
Here is an example that shows how to create a GenType for HxCorba.ImageRep using a SampleGenType:
char* head = "HxCorba::ImageRep_ptr ImageSample(HxCorba::ImageRep_ptr img)"; char* conv = "HxImageRep _img_arg = HxGetTiedObject<HxImageRepTiedSvt>(_server, img);"; char* call = "HxImageRep _result = ::ImageSample(_img_arg);"; char* retn = "return HxRegisterTiedServant<HxImageRepTiedSvt>(_server, _result);"; char* func = "ImageSample"; char* arg = "img"; TypeSample sample = {func, arg, head, conv, call, retn}; GenType* typeImageRep = new SampleGenType(sample);
func_name
and arg_name
help SampleGenType
to parse the code provided. paramDecl
and resultDecl
is implemented using the header
field. conversionLine
and convertedParam
is implemented using the conversionLine
field. callAssignment
is implemented using the callAssignment
field. returnLine
is implemented using the returnLine
field.
EnumGenType
is a class that can be used to implement the GenType for enumerators, but the enumerators should follow these rules:
If a GenType is not defined for a given enumeration type, SG instantiates a EnumGenType for it. No need to tell SG explicitly how to support this enum type.