Horus Doc || Corba Reference || Corba   Client Server   Stubs C++   Stubs Java   Servant Generator  

GenType Objects

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);.

SampleGenType

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);

GenType for enumerators

EnumGenType is a class that can be used to implement the GenType for enumerators, but the enumerators should follow these rules:

  1. For an enumeration named HxCorba::MyEnum, its HORUS type is HxMyEnum.
  2. Both the HORUS enumeration and the CORBA enumeration contain the same elements.
In case that the enumeration doesn't follow these rules, EnumGenType should not be used and a GenType has to be defined for that enumeration.

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.


Go to the next section or return to the index.


Generated on Mon Jan 27 15:20:57 2003 for CorbaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001