From af9b8b78585f44166904e7a08c33dc01d8597ba0 Mon Sep 17 00:00:00 2001 From: cas Date: Fri, 5 Nov 1999 18:24:35 +0000 Subject: [PATCH] Initial revision --- src/CPPJini/CPPJini.cdl | 20 + src/CPPJini/CPPJini.cxx | 1558 +++++++++++++++++++++++++++++ src/CPPJini/CPPJini.hxx | 147 +++ src/CPPJini/CPPJini_Define.hxx | 98 ++ src/CPPJini/CPPJini_Enum.cxx | 59 ++ src/CPPJini/CPPJini_General.edl | 131 +++ src/CPPJini/CPPJini_MPV.cxx | 267 +++++ src/CPPJini/CPPJini_Package.cxx | 215 ++++ src/CPPJini/CPPJini_Template.edl | 542 ++++++++++ src/CPPJini/CPPJini_Transient.cxx | 257 +++++ src/CPPJini/FILES | 10 + 11 files changed, 3304 insertions(+) create mode 100755 src/CPPJini/CPPJini.cdl create mode 100755 src/CPPJini/CPPJini.cxx create mode 100755 src/CPPJini/CPPJini.hxx create mode 100755 src/CPPJini/CPPJini_Define.hxx create mode 100755 src/CPPJini/CPPJini_Enum.cxx create mode 100755 src/CPPJini/CPPJini_General.edl create mode 100755 src/CPPJini/CPPJini_MPV.cxx create mode 100755 src/CPPJini/CPPJini_Package.cxx create mode 100755 src/CPPJini/CPPJini_Template.edl create mode 100755 src/CPPJini/CPPJini_Transient.cxx create mode 100755 src/CPPJini/FILES diff --git a/src/CPPJini/CPPJini.cdl b/src/CPPJini/CPPJini.cdl new file mode 100755 index 0000000..ef685d1 --- /dev/null +++ b/src/CPPJini/CPPJini.cdl @@ -0,0 +1,20 @@ +-- File: CPPJini.cdl +-- Created: Wed Mar 24 11:22:00 1999 +-- Author: Arnaud BOUZY +-- +---Copyright: Matra Datavision 1999 + +package CPPJini + +uses TCollection + +is + + + class DataMapOfAsciiStringInteger + instantiates DataMap from TCollection(AsciiString from TCollection, + Integer, + AsciiString from TCollection); + +end CPPJini; + diff --git a/src/CPPJini/CPPJini.cxx b/src/CPPJini/CPPJini.cxx new file mode 100755 index 0000000..3ba67f4 --- /dev/null +++ b/src/CPPJini/CPPJini.cxx @@ -0,0 +1,1558 @@ +// CLE : Extracteur de stubs C++ pour CAS.CADE +// Matra-Datavision 1995 +// +// 10/1995 +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CPPJINI_BOOLEAN 1 +#define CPPJINI_CHARACTER 2 +#define CPPJINI_ENUMERATION 3 +#define CPPJINI_EXTCHARACTER 4 +#define CPPJINI_INTEGER 5 +#define CPPJINI_REAL 6 +#define CPPJINI_BYTE 7 +#define CPPJINI_SHORTREAL 8 + +Handle(MS_HSequenceOfMemberMet) SeqOfMemberMet = new MS_HSequenceOfMemberMet; +Handle(MS_HSequenceOfExternMet) SeqOfExternMet = new MS_HSequenceOfExternMet; + +Handle(TCollection_HAsciiString) CPPJini_InterfaceName; +Handle(TCollection_HAsciiString) CPPJini_ErrorArgument = new TCollection_HAsciiString("%error%"); + +// Standard Extractor API : list the EDL files used by this program +// +Handle(TColStd_HSequenceOfHAsciiString) CPPJini_TemplatesUsed() +{ + Handle(TColStd_HSequenceOfHAsciiString) result = new TColStd_HSequenceOfHAsciiString; + + result->Append(new TCollection_HAsciiString("CPPJini_Template.edl")); + result->Append(new TCollection_HAsciiString("CPPJini_General.edl")); + + return result; +} + +void CPPJini_Init(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aName, + const Handle(MS_HSequenceOfExternMet)& SeqOfEM, + const Handle(MS_HSequenceOfMemberMet)& SeqOfMM) +{ + Handle(MS_Client) client; + + SeqOfMemberMet = SeqOfMM; + SeqOfExternMet = SeqOfEM; + + if (aMeta->IsClient(aName)) { + CPPJini_InterfaceName = aName; + } + else { + ErrorMsg << "CPPJini" << "Init : Client " << aName << " not found..." << endm; + Standard_NoSuchObject::Raise(); + } +} + +Handle(TCollection_HAsciiString)& CPPJini_TransientRootName() +{ + static Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString("Standard_Transient"); + + return name; +} + +Handle(TCollection_HAsciiString)& CPPJini_MemoryRootName() +{ + static Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString("MMgt_TShared"); + + return name; +} + +Handle(TCollection_HAsciiString)& CPPJini_MPVRootName() +{ + static Handle(TCollection_HAsciiString) name = new TCollection_HAsciiString("jcas.Object"); + + return name; +} + +Handle(EDL_API)& CPPJini_LoadTemplate(const Handle(TColStd_HSequenceOfHAsciiString)& edlsfullpath, + const Handle(TCollection_HAsciiString)& outdir) +{ + static Handle(EDL_API) api = new EDL_API; + static Standard_Boolean alreadyLoaded = Standard_False; + + api->ClearVariables(); + + if (!alreadyLoaded) { + alreadyLoaded = Standard_True; + + for(Standard_Integer i = 1; i <= edlsfullpath->Length(); i++) { + api->AddIncludeDirectory(edlsfullpath->Value(i)->ToCString()); + } + + if (api->Execute("CPPJini_Template.edl") != EDL_NORMAL) { + ErrorMsg << "CPPJini" << "unable to load : CPPJini_Template.edl" << endm; + Standard_NoSuchObject::Raise(); + } + if (api->Execute("CPPJini_General.edl") != EDL_NORMAL) { + ErrorMsg << "CPPJini" << "unable to load : CPPJini_General.edl" << endm; + Standard_NoSuchObject::Raise(); + } + } + + // full path of the destination directory + // + api->AddVariable(VJFullPath,outdir->ToCString()); + + // templates for methods extraction + // + api->AddVariable(VJMethodHeader,"MethodHeader"); + api->AddVariable(VJConstructorHeader,"ConstructorHeader"); + api->AddVariable(VJInterface,CPPJini_InterfaceName->ToCString()); + + return api; +} + +// write the content of a variable into a file +// +void CPPJini_WriteFile(const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& aFileName, + const Standard_CString var) +{ + // ...now we write the result + // + api->OpenFile("HTFile",aFileName->ToCString()); + api->WriteFile("HTFile",var); + api->CloseFile("HTFile"); +} + +// we test the type and dispatch it in the different lists +// +void CPPJini_DispatchUsedType(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Type)& thetype, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp, + const Standard_Boolean notusedwithref) +{ + MS::AddOnce(List,thetype->FullName()); + MS::AddOnce(Incp,thetype->FullName()); +} + + +Handle(TCollection_HAsciiString) CPPJini_UnderScoreReplace(const Handle(TCollection_HAsciiString)& name) +{ + char str[5000]; + char* from = name->ToCString(); + int cur=0; + for (int i=0; i < name->Length(); i++) { + if (from[i] == '_') { + str[cur] = '_'; + cur++; + str[cur] = '1'; + cur++; + } + else { + str[cur] = from[i]; + cur++; + } + } + str[cur] = '\0'; + return new TCollection_HAsciiString(str); + +} + + +Standard_Boolean CPPJini_HaveEmptyConstructor(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aClass, + const Handle(MS_HSequenceOfMemberMet)& methods) +{ + if (methods.IsNull()) return Standard_False; + + for (int i = 1; i <= methods->Length(); i++) { + if (methods->Value(i)->IsKind(STANDARD_TYPE(MS_Construc))) { + if ((methods->Value(i)->Params().IsNull()) && !methods->Value(i)->Private() && !methods->Value(i)->IsProtected()) { + return Standard_True; + } + } + } + + return Standard_False; +} + + + +// sort the method used types : +// +// FullList : all the used types +// List : the types that must have a full definition +// Incp : the types that only have to be declared +// +void CPPJini_MethodUsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Method)& aMethod, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp) +{ + Standard_Integer i; + Handle(MS_Param) aParam; + Handle(MS_Type) thetype; + Handle(TCollection_HAsciiString) aName,aNameType,parname; + + if (aMethod->IsKind(STANDARD_TYPE(MS_MemberMet))) { + Handle(MS_MemberMet) aMM = *((Handle(MS_MemberMet)*)&aMethod); + + aName = aMM->Class(); + } + else if (aMethod->IsKind(STANDARD_TYPE(MS_ExternMet))) { + Handle(MS_ExternMet) aMM = *((Handle(MS_ExternMet)*)&aMethod); + + aName = aMM->Package(); + } + + aParam = aMethod->Returns(); + + if (!aParam.IsNull()) { + thetype = aParam->Type(); + parname = aParam->TypeName(); + + if (thetype->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&thetype); + + parname = analias->DeepType(); + + if (aMeta->IsDefined(parname)) { + thetype = aMeta->GetType(parname); + } + else { + ErrorMsg << "CPPJini" << "Type " << parname << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + } + + if (!parname->IsSameString(aName)) { + CPPJini_DispatchUsedType(aMeta,thetype,List,Incp,!aMethod->IsRefReturn()); + } + } + + Handle(MS_HArray1OfParam) seqparam = aMethod->Params(); + + if(!seqparam.IsNull()) { + for (i = 1; i <= seqparam->Length(); i++) { + thetype = seqparam->Value(i)->Type(); + parname = seqparam->Value(i)->TypeName(); + + if (thetype->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&thetype); + + parname = analias->DeepType(); + + if (aMeta->IsDefined(parname)) { + thetype = aMeta->GetType(parname); + } + else { + ErrorMsg << "CPPJini" << "Type " << parname << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + } + + if (!parname->IsSameString(aName)) { + CPPJini_DispatchUsedType(aMeta,thetype,List,Incp,Standard_False); + } + } + } +} + + +// sort the class used types : +// +// FullList : all the used types +// List : the types that must have a full definition +// Incp : the types that only have to be declared +// +void CPPJini_ClassUsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Class)& aClass, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp) +{ + Standard_Integer i; + Handle(TColStd_HSequenceOfHAsciiString) asciiseq; + Handle(TCollection_HAsciiString) str,aNameType; + + asciiseq = aClass->GetInheritsNames(); + + for (i = 1; i <= asciiseq->Length(); i++) { + aNameType = new TCollection_HAsciiString; + aNameType->AssignCat(CPPJini_InterfaceName); + aNameType->AssignCat("_"); + aNameType->AssignCat(asciiseq->Value(i)); + MS::AddOnce(List,aNameType); + } + + Handle(MS_HSequenceOfMemberMet) metseq = aClass->GetMethods(); + + for (i = 1; i <= metseq->Length(); i++) { + CPPJini_MethodUsedTypes(aMeta,metseq->Value(i),List,Incp); + } +} + + +// sort the used types : +// +// FullList : all the used types +// List : the types that must have a full definition +// Incp : the types that only have to be declared +// +void CPPJini_UsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Common)& aCommon, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp) +{ + if (aCommon->IsKind(STANDARD_TYPE(MS_Type))) { + if (aCommon->IsKind(STANDARD_TYPE(MS_Class))) { + Handle(MS_Class) aClass = *((Handle(MS_Class)*)&aCommon); + + CPPJini_ClassUsedTypes(aMeta,aClass,List,Incp); + } + } +} + +// build a return, parameter or field type in c++ +// return a or a Handle_ +// +Handle(TCollection_HAsciiString) CPPJini_BuildType(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aTypeName) +{ + Handle(TCollection_HAsciiString) result = new TCollection_HAsciiString(); + Handle(TCollection_HAsciiString) rTypeName; + Handle(TCollection_HAsciiString) parname; + Handle(MS_Type) aType; + + + if (aMeta->IsDefined(aTypeName)) { + aType = aMeta->GetType(aTypeName); + parname = aTypeName; + + if (aType->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&aType); + + parname = analias->DeepType(); + + if (aMeta->IsDefined(parname)) { + aType = aMeta->GetType(parname); + } + else { + ErrorMsg << "CPPJini" << "Type " << parname << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + } + + + if (aType->IsKind(STANDARD_TYPE(MS_Enum))) { + parname = new TCollection_HAsciiString("int"); + } + result->AssignCat(parname); + if (aType->IsKind(STANDARD_TYPE(MS_NatType))) { + if (aType->IsKind(STANDARD_TYPE(MS_Imported)) || aType->IsKind(STANDARD_TYPE(MS_Pointer))) { + result = CPPJini_ErrorArgument; + } + } + if (!strcmp(aType->FullName()->ToCString(),"Standard_Address")) { + result = CPPJini_ErrorArgument; + } + + } + else { + ErrorMsg << "CPPJini" << "Type " << aTypeName << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + + return result; +} + + +Standard_Boolean CPPJini_IsCasType(const Handle(TCollection_HAsciiString)& typname) +{ + char* typeName = typname->ToCString(); + + if (!strcmp(typeName,"Object")) { + return Standard_True; + } + + if (typeName[0] != 'S') return Standard_False; + + if (!strcmp(typeName,"Standard_CString")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_ExtString")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_Character")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_Integer")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_Real")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_Boolean")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_ExtCharacter")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_Byte")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_ShortReal")) { + return Standard_True; + } + + if (!strcmp(typeName,"Standard_Address")) { + return Standard_True; + } + + return Standard_False; +} + + + +Handle(TCollection_HAsciiString) CPPJini_CheckPrimParam(const Handle(TCollection_HAsciiString)& parname, + const Standard_Boolean isout) +{ + char* typeName = parname->ToCString(); + + + if (!strcmp(typeName,"Standard_Address")) { + return CPPJini_ErrorArgument; + } + if (!strcmp(typeName,"Standard_ExtString")) { + if (!isout) { + return new TCollection_HAsciiString("String"); + } + return new TCollection_HAsciiString("StringBuffer"); + } + + if (isout) { + return parname; + } + + if (!strcmp(typeName,"Standard_Integer")) { + return new TCollection_HAsciiString("int"); + } + + if (!strcmp(typeName,"Standard_Real")) { + return new TCollection_HAsciiString("double"); + } + + if (!strcmp(typeName,"Standard_Boolean")) { + return new TCollection_HAsciiString("boolean"); + } + + if (!strcmp(typeName,"Standard_ExtCharacter")) { + return new TCollection_HAsciiString("char"); + } + + if (!strcmp(typeName,"Standard_Byte")) { + return new TCollection_HAsciiString("byte"); + } + + if (!strcmp(typeName,"Standard_ShortReal")) { + return new TCollection_HAsciiString("float"); + } + + + return parname; +} + +Handle(TCollection_HAsciiString) CPPJini_GetFullJavaType(const Handle(TCollection_HAsciiString)& className) +{ + Handle(TCollection_HAsciiString) theret; + if (CPPJini_IsCasType(className)) { + theret = new TCollection_HAsciiString("jcas."); + } + else { + theret = new TCollection_HAsciiString(CPPJini_InterfaceName->ToCString()); + theret->AssignCat("."); + } + theret->AssignCat(className); + return theret; +} + + +// Build a parameter list for methods +// the output is in C++ +// +Handle(TCollection_HAsciiString) CPPJini_BuildParameterList(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_HArray1OfParam)& aSeq, + const Standard_Boolean withtype) +{ + Standard_Integer i; + Handle(TCollection_HAsciiString) result = new TCollection_HAsciiString; + Handle(MS_Type) aType; + Handle(MS_Class) aClass; + Handle(TCollection_HAsciiString) parname; + + if(!aSeq.IsNull()) { + for (i = 1; i <= aSeq->Length(); i++) { + if (i > 1) { + result->AssignCat(","); + } + + if (aMeta->IsDefined(aSeq->Value(i)->TypeName())) { + if (!withtype) { + result->AssignCat(aSeq->Value(i)->Name()); + } + else { + + parname = aSeq->Value(i)->TypeName(); + aType = aMeta->GetType(parname); + + if (aType->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&aType); + + parname = analias->DeepType(); + + if (aMeta->IsDefined(parname)) { + aType = aMeta->GetType(parname); + } + else { + ErrorMsg << "CPPJini" << "Type " << parname << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + } + + if (aType->IsKind(STANDARD_TYPE(MS_Imported)) || aType->IsKind(STANDARD_TYPE(MS_Pointer))) { + result = CPPJini_ErrorArgument; + return result; + } + if (aType->IsKind(STANDARD_TYPE(MS_Enum))) { + if (aSeq->Value(i)->IsOut()) { + parname = new TCollection_HAsciiString("Standard_Integer"); + } + else { + parname = new TCollection_HAsciiString("int"); + } + } + + if (aType->IsKind(STANDARD_TYPE(MS_PrimType))) { + parname = CPPJini_CheckPrimParam(parname,aSeq->Value(i)->IsOut()); + if (parname == CPPJini_ErrorArgument) return parname; + } + + result->AssignCat(parname); + result->AssignCat(" "); + result->AssignCat(aSeq->Value(i)->Name()); + } + } + } + } + return result; +} + + + +void CPPJini_CheckMethod(const Standard_Integer index, + const Handle(TCollection_HAsciiString)& thename, + CPPJini_DataMapOfAsciiStringInteger& themap, + TColStd_Array1OfInteger& theindexes) +{ + + TCollection_AsciiString name(thename->ToCString()); + + + if (themap.IsBound(name)) { + Standard_Integer curnb=0; + Standard_Integer theindex = themap.Find(name); + if (theindexes(theindex) == 0) { + theindexes(theindex) = 1; + } + curnb = theindexes(theindex) + 1; + theindexes(index) = curnb; + themap.UnBind(name); + } + themap.Bind(name,index); +} + + + +// build a c++ declaration method +// the result is in the EDL variable VJMethod +// +// template used : +// +// MethodTemplateDef +// ConstructorTemplateDef +// ConstructorTemplateDec +// +// the EDL variables : +// VJMethodHeader : must contains the name of the template used for +// methods construction +// VJConstructorHeader : must contains the name of the template used for +// constructors construction +// +// WARNING : if an error was found the result in the variable "%Method" will be "%error%" +// +void CPPJini_BuildMethod(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + const Handle(TCollection_HAsciiString)& methodName, + const Standard_Integer MethodNumber) +{ + + Handle(MS_InstMet) im; + Handle(MS_ClassMet) cm; + Handle(MS_Construc) ct; + Handle(MS_Param) retType; + Handle(TCollection_HAsciiString) MetTemplate,OverMetTemplate,theArgList,theArgVals, + ConTemplate; + + + MetTemplate = api->GetVariableValue(VJMethodHeader); + ConTemplate = api->GetVariableValue(VJConstructorHeader); + + if (MethodNumber != 0) { + OverMetTemplate = new TCollection_HAsciiString("Overload"); + OverMetTemplate->AssignCat(MetTemplate); + } + + // here we process all the common attributes of methods + // + api->AddVariable(VJMethodName,methodName->ToCString()); + api->AddVariable(VJVirtual,""); + + api->AddVariable("%NbMet",MethodNumber); + api->AddVariable("%RetMode",""); + api->AddVariable("%Class",className->ToCString()); + + theArgList = CPPJini_BuildParameterList(aMeta,m->Params(),Standard_True); + + if (theArgList == CPPJini_ErrorArgument) { + WarningMsg << "CPPJini" << "Bad argument type in method (pointer or imported type) " << m->FullName() << endm; + WarningMsg << "CPPJini" << "Method : " << m->FullName() << " not exported." << endm; + api->AddVariable(VJMethod,CPPJini_ErrorArgument->ToCString()); + return; + } + + api->AddVariable("%Arguments",theArgList->ToCString()); + + theArgVals = CPPJini_BuildParameterList(aMeta,m->Params(),Standard_False); + api->AddVariable("%ArgsInCall",theArgVals->ToCString()); + + // it s returning a type or void ? + // + retType = m->Returns(); + + if (!retType.IsNull()) { + Handle(TCollection_HAsciiString) returnT = CPPJini_BuildType(aMeta,retType->TypeName()); + + if (returnT == CPPJini_ErrorArgument) { + WarningMsg << "CPPJini" << "Return type (pointer or imported type) of " << m->FullName() << " not exportable." << endm; + WarningMsg << "CPPJini" << "Method : " << m->FullName() << " not exported." << endm; + api->AddVariable(VJMethod,CPPJini_ErrorArgument->ToCString()); + return; + } + else { + returnT = CPPJini_CheckPrimParam(returnT,Standard_False); + api->AddVariable(VJReturn,returnT->ToCString()); + api->AddVariable("%RetMode","return"); + } + } + else { + api->AddVariable(VJReturn,"void"); + } + + // now the specials attributes + // + // instance methods + // + api->AddVariable(VJVirtual,""); + + if (m->IsKind(STANDARD_TYPE(MS_InstMet))) { + im = *((Handle(MS_InstMet)*)&m); + + if (MethodNumber != 0) { + MetTemplate = OverMetTemplate; + } + if (im->IsStatic()) { + api->AddVariable(VJVirtual,"final"); + } + api->Apply(VJMethod,MetTemplate->ToCString()); + } + // + // class methods + // + else if (m->IsKind(STANDARD_TYPE(MS_ClassMet))) { + api->AddVariable(VJVirtual,"static"); + if (MethodNumber != 0) { + MetTemplate = OverMetTemplate; + } + + api->Apply(VJMethod,MetTemplate->ToCString()); + } + // + // constructors + // + else if (m->IsKind(STANDARD_TYPE(MS_Construc))) { + api->Apply(VJMethod,ConTemplate->ToCString()); + } + // + // package methods + // + else if (m->IsKind(STANDARD_TYPE(MS_ExternMet))) { + api->AddVariable(VJVirtual,"static"); + if (MethodNumber != 0) { + MetTemplate = OverMetTemplate; + } + + api->Apply(VJMethod,MetTemplate->ToCString()); + } +} + + +Handle(TCollection_HAsciiString) CPPJini_ConvertToJavaType(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aTypeName,Standard_Boolean isout,Standard_Integer& typeprim) +{ + Handle(TCollection_HAsciiString) result = new TCollection_HAsciiString(); + Handle(TCollection_HAsciiString) rTypeName; + Handle(TCollection_HAsciiString) parname; + Handle(MS_Type) aType; + + typeprim = 0; + + if (aMeta->IsDefined(aTypeName)) { + aType = aMeta->GetType(aTypeName); + parname = aTypeName; + + if (aType->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&aType); + + parname = analias->DeepType(); + + if (aMeta->IsDefined(parname)) { + aType = aMeta->GetType(parname); + } + else { + ErrorMsg << "CPPJini" << "Type " << parname << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + } + + + if (aType->IsKind(STANDARD_TYPE(MS_Enum))) { + typeprim = CPPJINI_ENUMERATION; + if (!isout) { + result->AssignCat("jint"); + } + else { + result->AssignCat("jobject"); + } + return result; + } + + + char* typeName = parname->ToCString(); + + if (!strcmp(typeName,"Standard_Address")) { + return CPPJini_ErrorArgument; + } + + if (!strcmp(typeName,"Standard_ExtString")) { + if (isout) { + return new TCollection_HAsciiString("jstringbuffer"); + } + return new TCollection_HAsciiString("jstring"); + } + + if (!strcmp(typeName,"Standard_CString")) { + return new TCollection_HAsciiString("cstring"); + } + + if (!strcmp(typeName,"Standard_Integer")) { + typeprim = CPPJINI_INTEGER; + if (isout) { + return new TCollection_HAsciiString("jobject"); + } + result->AssignCat("jint"); + } + else if (!strcmp(typeName,"Standard_Real")) { + typeprim = CPPJINI_REAL; + if (isout) { + return new TCollection_HAsciiString("jobject"); + } + result->AssignCat("jdouble"); + } + else if (!strcmp(typeName,"Standard_Boolean")) { + typeprim = CPPJINI_BOOLEAN; + if (isout) { + return new TCollection_HAsciiString("jobject"); + } + result->AssignCat("jboolean"); + } + else if (!strcmp(typeName,"Standard_ExtCharacter")) { + typeprim = CPPJINI_EXTCHARACTER; + if (isout) { + return new TCollection_HAsciiString("jobject"); + } + result->AssignCat("jchar"); + } + else if (!strcmp(typeName,"Standard_Byte")) { + typeprim = CPPJINI_BYTE; + if (isout) { + return new TCollection_HAsciiString("jobject"); + } + result->AssignCat("jbyte"); + } + else if (!strcmp(typeName,"Standard_ShortReal")) { + typeprim = CPPJINI_SHORTREAL; + if (isout) { + return new TCollection_HAsciiString("jobject"); + } + result->AssignCat("jfloat"); + } + else if (!strcmp(typeName,"Standard_Character")) { + typeprim = CPPJINI_CHARACTER; + result->AssignCat("jobject"); + } + else { + result->AssignCat("jobject"); + } + } + + return result; + +} + +void CPPJini_ArgumentBuilder(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + Handle(TCollection_HAsciiString)& ArgsInDecl, + Handle(TCollection_HAsciiString)& ArgsRetrieve, + Handle(TCollection_HAsciiString)& ArgsInCall, + Handle(TCollection_HAsciiString)& ArgsOut) +{ + Handle(MS_HArray1OfParam) aSeqP = m->Params(); + Standard_Integer i; + + if(!aSeqP.IsNull()) { + for (i = 1; i <= aSeqP->Length(); i++) { + int curprimtype = 0; + Handle(TCollection_HAsciiString) thety = CPPJini_ConvertToJavaType(aMeta,aSeqP->Value(i)->TypeName(),aSeqP->Value(i)->IsOut(),curprimtype); + + if (!strcmp(thety->ToCString(),"jstringbuffer")) { + api->AddVariable("%TypeName","jobject"); + } + else if (!strcmp(thety->ToCString(),"cstring")) { + api->AddVariable("%TypeName","jobject"); + } + else { + api->AddVariable("%TypeName",thety->ToCString()); + } + api->AddVariable("%ArgName",aSeqP->Value(i)->Name()->ToCString()); + + api->Apply("%Method","MethodArg"); + ArgsInDecl->AssignCat(api->GetVariableValue("%Method")); + + if (!strcmp("jobject",thety->ToCString())) { + Handle(MS_Type) curtype = aMeta->GetType(aSeqP->Value(i)->TypeName()); + + if (curtype->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&curtype); + + curtype = aMeta->GetType(analias->DeepType()); + } + + if (curtype->IsKind(STANDARD_TYPE(MS_StdClass))) { + Handle(MS_StdClass) aClass = *((Handle(MS_StdClass)*) &curtype); + api->AddVariable("%ClassName",aClass->FullName()->ToCString()); + if (aClass->IsTransient()) { + api->Apply("%Method","TransientGetValue"); + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + if (aSeqP->Value(i)->IsOut()) { + api->Apply("%MetOut","TransientSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + } + } + else { + api->Apply("%Method","ValueGetValue"); + ArgsInCall->AssignCat("*the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + } + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + + } + else { + // type primitif non converti en type java + switch (curprimtype) { + case CPPJINI_BOOLEAN : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","BooleanGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + api->Apply("%MetOut","BooleanSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + break; + } + + case CPPJINI_CHARACTER : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","CharacterGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + if (aSeqP->Value(i)->IsOut()) { + api->Apply("%MetOut","CharacterSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + } + break; + } + + case CPPJINI_ENUMERATION : + case CPPJINI_INTEGER : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","IntegerGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + api->Apply("%MetOut","IntegerSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + break; + } + + case CPPJINI_EXTCHARACTER : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","ExtCharacterGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + api->Apply("%MetOut","ExtCharacterSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + break; + } + + case CPPJINI_REAL : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","RealGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + api->Apply("%MetOut","RealSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + break; + } + + case CPPJINI_BYTE : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","ByteGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + api->Apply("%MetOut","ByteSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + break; + } + + case CPPJINI_SHORTREAL : + { + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%Method","ShortRealGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + api->Apply("%MetOut","ShortRealSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + break; + } + + default : + { + api->AddVariable("%ClassName",curtype->FullName()->ToCString()); + api->Apply("%Method","ValueGetValue"); + ArgsInCall->AssignCat("*the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + } + } + } + } + else if (!strcmp("cstring",thety->ToCString())) { + api->Apply("%Method","CStringGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + if (aSeqP->Value(i)->IsOut()) { + api->Apply("%MetOut","CStringSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + } + } + else if (!strcmp("jstring",thety->ToCString())) { + api->Apply("%Method","StringGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + } + else if (!strcmp("jstringbuffer",thety->ToCString())) { + api->Apply("%Method","StringBufferGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + ArgsInCall->AssignCat("the_"); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + api->Apply("%MetOut","StringBufferSetValue"); + ArgsOut->AssignCat(api->GetVariableValue("%MetOut")); + } + else { + ArgsInCall->AssignCat("("); + ArgsInCall->AssignCat(aSeqP->Value(i)->TypeName()); + ArgsInCall->AssignCat(") "); + ArgsInCall->AssignCat(aSeqP->Value(i)->Name()); + } + if (i < aSeqP->Length()) { + ArgsInCall->AssignCat(","); + } + } + } +} + +Standard_Boolean CPPJini_HasMagicConstructor(const Handle(MS_Type)& atyp) +{ + Handle(MS_Class) thecl = Handle(MS_Class)::DownCast(atyp); + if (thecl.IsNull()) return Standard_True; + Handle(MS_HSequenceOfMemberMet) methods = thecl->GetMethods(); + for (Standard_Integer i=1; i<= methods->Length(); i++) { + if (methods->Value(i)->IsKind(STANDARD_TYPE(MS_Construc))) { + Handle(MS_HArray1OfParam) parameters = methods->Value(i)->Params(); + if (!parameters.IsNull()) { + if (parameters->Length() == 1) { + if (parameters->Value(1)->Type() == atyp) { + if (methods->Value(i)->Private()) { + return Standard_False; + } + return Standard_True; + } + } + } + } + } + return Standard_True; +} + +Standard_Boolean CPPJini_HasEmptyConstructor(const Handle(MS_Type)& atyp) +{ + Handle(MS_Class) thecl = Handle(MS_Class)::DownCast(atyp); + if (thecl.IsNull()) return Standard_False; + Handle(MS_HSequenceOfMemberMet) methods = thecl->GetMethods(); + for (Standard_Integer i=1; i<= methods->Length(); i++) { + if (methods->Value(i)->IsKind(STANDARD_TYPE(MS_Construc))) { + Handle(MS_HArray1OfParam) parameters = methods->Value(i)->Params(); + if (parameters.IsNull()) { + if (methods->Value(i)->Private()) { + return Standard_False; + } + return Standard_True; + } + } + } + return Standard_False; +} + + +void CPPJini_ReturnBuilder(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + const Handle(TCollection_HAsciiString)& MethodCall, + Handle(TCollection_HAsciiString)& RetInDecl, + Handle(TCollection_HAsciiString)& RetInCall, + Handle(TCollection_HAsciiString)& RetOut) +{ + if (!m->Returns().IsNull()) { + Handle(MS_Type) rtype = aMeta->GetType(m->Returns()->TypeName()); + + if (rtype->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(TCollection_HAsciiString) parname; + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&rtype); + + parname = analias->DeepType(); + + if (aMeta->IsDefined(parname)) { + rtype = aMeta->GetType(parname); + } + else { + ErrorMsg << "CPPJini" << "Type " << parname << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + } + + int curprimtype = 0; + RetInDecl = CPPJini_ConvertToJavaType(aMeta,rtype->FullName(),Standard_False,curprimtype); + + if (strcmp(RetInDecl->ToCString(),"jobject")) { + // retour type basique + + if (!strcmp(RetInDecl->ToCString(),"jstring")) { + api->AddVariable("%MethodCall",MethodCall->ToCString()); + api->Apply("%Return","ReturnString"); + RetInCall->AssignCat(api->GetVariableValue("%Return")); + RetOut->AssignCat("return thejret;"); + } + else if (!strcmp(RetInDecl->ToCString(),"cstring")) { + RetInDecl = new TCollection_HAsciiString("jobject"); + api->AddVariable("%MethodCall",MethodCall->ToCString()); + api->Apply("%Return","ReturnCString"); + RetInCall->AssignCat(api->GetVariableValue("%Return")); + RetOut->AssignCat("return thejret;"); + } + else { + RetInCall->AssignCat(RetInDecl); + RetInCall->AssignCat(" thejret = "); + RetInCall->AssignCat(MethodCall); + RetInCall->AssignCat(";\n"); + RetOut->AssignCat("return thejret;"); + } + } + else { + if (rtype->IsKind(STANDARD_TYPE(MS_StdClass))) { + Handle(MS_StdClass) aClass = *((Handle(MS_StdClass)*)&rtype); + api->AddVariable("%ClassName",aClass->FullName()->ToCString()); + api->AddVariable("%MethodCall",MethodCall->ToCString()); + + if (CPPJini_IsCasType(rtype->FullName())) { + api->AddVariable("%FromInterface","jcas"); + } + else { + api->AddVariable("%FromInterface",CPPJini_InterfaceName->ToCString()); + } + if (aClass->IsTransient()) { + api->Apply("%Return","ReturnHandle"); + } + else { + if (m->IsRefReturn()) { + api->Apply("%Return","ReturnValueRef"); + } + else if (CPPJini_HasMagicConstructor(aClass)) { + api->Apply("%Return","ReturnValueMagic"); + } + else if (CPPJini_HasEmptyConstructor(aClass)) { + api->Apply("%Return","ReturnValueEmpty"); + } + else { + api->Apply("%Return","ReturnValueMalloc"); + } + } + RetInCall->AssignCat(api->GetVariableValue("%Return")); + RetOut->AssignCat("return thejret;"); + } + else { + // type primitif non converti en type java + api->AddVariable("%ClassName",rtype->FullName()->ToCString()); + api->AddVariable("%MethodCall",MethodCall->ToCString()); + if (CPPJini_IsCasType(rtype->FullName())) { + api->AddVariable("%FromInterface","jcas"); + } + else { + api->AddVariable("%FromInterface",CPPJini_InterfaceName->ToCString()); + } + if (m->IsRefReturn()) { + api->Apply("%Return","ReturnValueRef"); + } + else { + api->Apply("%Return","ReturnValueMalloc"); + } + RetInCall->AssignCat(api->GetVariableValue("%Return")); + RetOut->AssignCat("return thejret;"); + + } + + } + } + else { + // pas de return + RetInDecl->AssignCat("void"); + RetInCall->AssignCat(MethodCall); + RetInCall->AssignCat(";\n"); + } +} + +// build a method call for stub c++ +// +void CPPJini_MethodBuilder(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + const Handle(TCollection_HAsciiString)& methodName, + const Standard_Integer nummet) +{ + Handle(TCollection_HAsciiString) metname = new TCollection_HAsciiString("Java_"); + Handle(TCollection_HAsciiString) metbody = new TCollection_HAsciiString; + Handle(TCollection_HAsciiString) metcall = new TCollection_HAsciiString; + Handle(TCollection_HAsciiString) metstart = new TCollection_HAsciiString; + + Standard_CString headerTemplate = NULL; + + Handle(TCollection_HAsciiString) ArgsInDecl = new TCollection_HAsciiString(""); + Handle(TCollection_HAsciiString) ArgsRetrieve = new TCollection_HAsciiString(""); + Handle(TCollection_HAsciiString) ArgsInCall = new TCollection_HAsciiString(""); + Handle(TCollection_HAsciiString) ArgsOut = new TCollection_HAsciiString(""); + + Handle(TCollection_HAsciiString) RetInDecl = new TCollection_HAsciiString(""); + Handle(TCollection_HAsciiString) RetInCall = new TCollection_HAsciiString(""); + Handle(TCollection_HAsciiString) RetOut = new TCollection_HAsciiString(""); + + CPPJini_ArgumentBuilder(aMeta,api,className,m,ArgsInDecl,ArgsRetrieve,ArgsInCall,ArgsOut); + metname->AssignCat(CPPJini_InterfaceName); + metname->AssignCat("_"); + Handle(TCollection_HAsciiString) classunder = CPPJini_UnderScoreReplace(className); + if ((nummet != 0) || (m->IsKind(STANDARD_TYPE(MS_Construc)))) { + metname->AssignCat(classunder); + metname->AssignCat("_"); + } + metname->AssignCat(classunder); + metname->AssignCat("_"); + if ((nummet != 0) || (m->IsKind(STANDARD_TYPE(MS_Construc)))) { + metname->AssignCat("1"); + } + metname->AssignCat(CPPJini_UnderScoreReplace(methodName)); + + + if ((nummet != 0) || (m->IsKind(STANDARD_TYPE(MS_Construc)))) { + metname->AssignCat("_1"); + TCollection_AsciiString numb(nummet); + metname->AssignCat(numb.ToCString()); + } + + if (m->IsKind(STANDARD_TYPE(MS_InstMet))) { + headerTemplate = "InstMethodDec"; + } + else if (m->IsKind(STANDARD_TYPE(MS_ClassMet))) { + headerTemplate = "ClassMethodDec"; + } + else if (m->IsKind(STANDARD_TYPE(MS_Construc))) { + headerTemplate = "CreateMethodDec"; + } + else if (m->IsKind(STANDARD_TYPE(MS_ExternMet))) { + headerTemplate = "PackMethodDec"; + } + + // on calcule le call + + + api->AddVariable("%ClassName",className->ToCString()); + api->AddVariable("%MethodName",methodName->ToCString()); + + if ((m->IsKind(STANDARD_TYPE(MS_InstMet))) || + (m->IsKind(STANDARD_TYPE(MS_Construc)))) { + + Handle(MS_Type) objtype = aMeta->GetType(className); + + if (objtype->IsKind(STANDARD_TYPE(MS_Alias))) { + Handle(MS_Alias) analias = *((Handle(MS_Alias)*)&objtype); + + objtype = aMeta->GetType(analias->DeepType()); + } + + if (objtype->IsKind(STANDARD_TYPE(MS_StdClass))) { + Handle(MS_StdClass) aClass = *((Handle(MS_StdClass)*) &objtype); + + + if (m->IsKind(STANDARD_TYPE(MS_InstMet))) { + + if (aClass->IsTransient()) { + api->Apply("%Method","ThisTransientGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + } + else { + api->Apply("%Method","ThisValueGetValue"); + ArgsRetrieve->AssignCat(api->GetVariableValue("%Method")); + } + api->AddVariable("%ArgsInCall",ArgsInCall->ToCString()); + api->Apply("%MethodCall","InstMethodCall"); + metcall->AssignCat(api->GetVariableValue("%MethodCall")); + CPPJini_ReturnBuilder(aMeta,api,className,m,metcall,RetInDecl,RetInCall,RetOut); + } + else { + api->AddVariable("%ArgsInCall",ArgsInCall->ToCString()); + + if (aClass->IsTransient()) { + api->Apply("%MethodCall","TransientCreateMethodCall"); + RetInCall->AssignCat(api->GetVariableValue("%MethodCall")); + } + else { + api->Apply("%MethodCall","ValueCreateMethodCall"); + RetInCall->AssignCat(api->GetVariableValue("%MethodCall")); + } + + } + + } + } + else if (m->IsKind(STANDARD_TYPE(MS_ClassMet))) { + api->AddVariable("%ArgsInCall",ArgsInCall->ToCString()); + api->Apply("%MethodCall","ClassMethodCall"); + metcall->AssignCat(api->GetVariableValue("%MethodCall")); + CPPJini_ReturnBuilder(aMeta,api,className,m,metcall,RetInDecl,RetInCall,RetOut); + } + else if (m->IsKind(STANDARD_TYPE(MS_ExternMet))) { + api->AddVariable("%ArgsInCall",ArgsInCall->ToCString()); + api->Apply("%MethodCall","PackMethodCall"); + metcall->AssignCat(api->GetVariableValue("%MethodCall")); + CPPJini_ReturnBuilder(aMeta,api,className,m,metcall,RetInDecl,RetInCall,RetOut); + } + + + + api->AddVariable("%MethodName",metname->ToCString()); + api->AddVariable("%Return",RetInDecl->ToCString()); + + api->AddVariable("%ClassName",className->ToCString()); + + api->Apply("%Method",headerTemplate); + + metstart->AssignCat(api->GetVariableValue("%Method")); + + metstart->AssignCat(ArgsInDecl); + metstart->AssignCat(")"); + + + // ajout des parametres a recuperer + + + metbody->AssignCat(ArgsRetrieve); + + // call + + metbody->AssignCat(RetInCall); + + // Arguments Out + + metbody->AssignCat(ArgsOut); + + // return de la fonction + + metbody->AssignCat(RetOut); + + // c'est fini + + api->AddVariable("%Method",metstart->ToCString()); + api->AddVariable("%MBody",metbody->ToCString()); + + api -> Apply ( + "%Method", + !strcmp ( + api -> GetVariableValue ( "%CPPJiniEXTDBMS" ) -> ToCString (), "OBJS" + ) ? "MethodTemplateDefOBJS" : "MethodTemplateDef" + ); + +} + +// Standard extractor API : launch the extraction of C++ files +// from the type +// +void CPPJini_TypeExtract(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aName, + const Handle(TColStd_HSequenceOfHAsciiString)& edlsfullpath, + const Handle(TCollection_HAsciiString)& outdir, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const ExtractionType MustBeComplete, + const Standard_CString Mode) +{ + + InfoMsg << "CPPJini" << "Extract " << aName->ToCString() << endm; + Handle(MS_Type) srcType; + Handle(MS_Package) srcPackage; + + // before begining, we look if the entity has something to extract... + // + if (aMeta->IsDefined(aName)) { + srcType = aMeta->GetType(aName); + } + else if (aMeta->IsPackage(aName)) { + srcPackage = aMeta->GetPackage(aName); + } + else { + ErrorMsg << "CPPJini" << aName->ToCString() << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } + + // ... and we load the templates + // + Handle(EDL_API) api; + Handle(TCollection_HAsciiString) aHandleFile; + + // Package Extraction + // + if (!srcPackage.IsNull()) { + if (srcPackage->Methods()->Length() > 0) { + Handle(MS_HSequenceOfExternMet) aSeqMet = new MS_HSequenceOfExternMet; + + api = CPPJini_LoadTemplate(edlsfullpath,outdir); + api -> AddVariable ( "%CPPJiniEXTDBMS", Mode ); + + if (MustBeComplete == CPPJini_SEMICOMPLETE) { + Standard_Integer i; + + for (i = 1; i <= SeqOfExternMet->Length(); i++) { + if (aName->IsSameString(SeqOfExternMet->Value(i)->Package())) { + aSeqMet->Append(SeqOfExternMet->Value(i)); + } + } + } + + CPPJini_Package(aMeta,api,srcPackage,outfile,MustBeComplete,aSeqMet); + } + else { + return; + } + } + else if (aName->IsSameString(MS::GetTransientRootName())) { + + api = CPPJini_LoadTemplate(edlsfullpath,outdir); + api -> AddVariable ( "%CPPJiniEXTDBMS", Mode ); + + + aHandleFile = new TCollection_HAsciiString(outdir); + + aHandleFile->AssignCat(aName); + aHandleFile->AssignCat(".java"); + api->Apply("%outClass","TransientRootClientJAVA"); + outfile->Append(aHandleFile); + + // ...now we write the result + // + api->OpenFile("HTFile",aHandleFile->ToCString()); + api->WriteFile("HTFile","%outClass"); + api->CloseFile("HTFile"); + } + else if (aName->IsSameString(CPPJini_MemoryRootName())) { + Handle(TCollection_HAsciiString) aHandleFile = new TCollection_HAsciiString(outdir), + ancestorName; + api = CPPJini_LoadTemplate(edlsfullpath,outdir); + api -> AddVariable ( "%CPPJiniEXTDBMS", Mode ); + + aHandleFile = new TCollection_HAsciiString(outdir); + + aHandleFile->AssignCat(aName); + aHandleFile->AssignCat(".java"); + api->Apply("%outClass","MemoryRootClientJAVA"); + outfile->Append(aHandleFile); + + // ...now we write the result + // + api->OpenFile("HTFile",aHandleFile->ToCString()); + api->WriteFile("HTFile","%outClass"); + api->CloseFile("HTFile"); + } + else if (aName->IsSameString(MS::GetStorableRootName())) { + Handle(TCollection_HAsciiString) aHandleFile = new TCollection_HAsciiString(outdir); + + api = CPPJini_LoadTemplate(edlsfullpath,outdir); + api -> AddVariable ( "%CPPJiniEXTDBMS", Mode ); + + aHandleFile = new TCollection_HAsciiString(outdir); + + aHandleFile->AssignCat(aName); + aHandleFile->AssignCat(".java"); + api->Apply("%outClass","StorableRootClientJAVA"); + outfile->Append(aHandleFile); + + // ...now we write the result + // + api->OpenFile("HTFile",aHandleFile->ToCString()); + api->WriteFile("HTFile","%outClass"); + api->CloseFile("HTFile"); + } + // Extraction of Classes + // + else if (srcType->IsKind(STANDARD_TYPE(MS_StdClass)) && !srcType->IsKind(STANDARD_TYPE(MS_GenClass)) && !srcType->IsKind(STANDARD_TYPE(MS_InstClass))) { + Handle(MS_StdClass) aClass = *((Handle(MS_StdClass)*)&srcType); + + if (aClass->IsGeneric()) { + return; + } + + Handle(MS_HSequenceOfMemberMet) aSeqMet = new MS_HSequenceOfMemberMet; + + api = CPPJini_LoadTemplate(edlsfullpath,outdir); + api -> AddVariable ( "%CPPJiniEXTDBMS", Mode ); + + if (MustBeComplete == CPPJini_SEMICOMPLETE) { + Standard_Integer i; + + for (i = 1; i <= SeqOfMemberMet->Length(); i++) { + if (aName->IsSameString(SeqOfMemberMet->Value(i)->Class())) { + aSeqMet->Append(SeqOfMemberMet->Value(i)); + } + } + } + + // Transient classes + // + if (aClass->IsTransient()) { + Handle(TCollection_HAsciiString) aHandleFile = new TCollection_HAsciiString(outdir); + + CPPJini_TransientClass(aMeta,api,aClass,outfile,MustBeComplete,aSeqMet); + } + // MPV classes + // + else { + CPPJini_MPVClass(aMeta,api,aClass,outfile,MustBeComplete,aSeqMet); + } + } + else if (srcType->IsKind(STANDARD_TYPE(MS_Enum))) { + api = CPPJini_LoadTemplate(edlsfullpath,outdir); + api -> AddVariable ( "%CPPJiniEXTDBMS", Mode ); + + + Handle(MS_Enum) theEnum = *((Handle(MS_Enum)*)&srcType); + + CPPJini_Enum(aMeta,api,theEnum,outfile); + } +} + +void CPPJini_Extract(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aTypeName, + const Handle(TColStd_HSequenceOfHAsciiString)& edlsfullpath, + const Handle(TCollection_HAsciiString)& outdir, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const Standard_CString Mode) +{ + if (aMeta->IsDefined(aTypeName) || aMeta->IsPackage(aTypeName)) { + ExtractionType theMode = CPPJini_COMPLETE; + + if (strcmp(Mode,"CPPJini_COMPLETE") == 0) { + theMode = CPPJini_COMPLETE; + } + else if (strcmp(Mode,"CPPJini_INCOMPLETE") == 0) { + theMode = CPPJini_INCOMPLETE; + } + else if (strcmp(Mode,"CPPJini_SEMICOMPLETE") == 0) { + theMode = CPPJini_SEMICOMPLETE; + } + else { + ErrorMsg << "CPPJini" << "Unknown extraction mode:" << Mode << endm; + Standard_NoSuchObject::Raise(); + } + + CPPJini_TypeExtract(aMeta,aTypeName,edlsfullpath,outdir,outfile,theMode,Mode); + } + else { + ErrorMsg << "CPPJini" << "Type " << aTypeName << " not defined..." << endm; + Standard_NoSuchObject::Raise(); + } +} + diff --git a/src/CPPJini/CPPJini.hxx b/src/CPPJini/CPPJini.hxx new file mode 100755 index 0000000..d3b1e4f --- /dev/null +++ b/src/CPPJini/CPPJini.hxx @@ -0,0 +1,147 @@ +#ifndef _CPPJini_HeaderFile +#define _CPPJini_HeaderFile +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +extern "C" { + + Handle(TColStd_HSequenceOfHAsciiString) Standard_EXPORT CPPJini_TemplatesUsed(); + + void Standard_EXPORT CPPJini_Init(const Handle(MS_MetaSchema)&, + const Handle(TCollection_HAsciiString)&, + const Handle(MS_HSequenceOfExternMet)&, + const Handle(MS_HSequenceOfMemberMet)&); + + void Standard_EXPORT CPPJini_Extract(const Handle(MS_MetaSchema)& ams, + const Handle(TCollection_HAsciiString)& atypename, + const Handle(TColStd_HSequenceOfHAsciiString)& edlsfullpath, + const Handle(TCollection_HAsciiString)& outdir, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const Standard_CString Mode); + } + +enum ExtractionType {CPPJini_COMPLETE,CPPJini_INCOMPLETE,CPPJini_SEMICOMPLETE}; + +void CPPJini_TransientHandle(const Handle(EDL_API)&, + const Handle(TCollection_HAsciiString)&, + const Handle(TCollection_HAsciiString)&, + const Handle(TCollection_HAsciiString)&); + + +void CPPJini_TransientClass(const Handle(MS_MetaSchema)&, + const Handle(EDL_API)&, + const Handle(MS_Class)&, + const Handle(TColStd_HSequenceOfHAsciiString)&, + const ExtractionType, + const Handle(MS_HSequenceOfMemberMet)&); + +void CPPJini_MPVClass(const Handle(MS_MetaSchema)&, + const Handle(EDL_API)&, + const Handle(MS_Class)&, + const Handle(TColStd_HSequenceOfHAsciiString)&, + const ExtractionType, + const Handle(MS_HSequenceOfMemberMet)&); + +void CPPJini_Alias(const Handle(MS_MetaSchema)&, + const Handle(EDL_API)&, + const Handle(MS_Alias)&, + const Handle(TColStd_HSequenceOfHAsciiString)&); + +void CPPJini_Package(const Handle(MS_MetaSchema)&, + const Handle(EDL_API)&, + const Handle(MS_Package)&, + const Handle(TColStd_HSequenceOfHAsciiString)&, + const ExtractionType, + const Handle(MS_HSequenceOfExternMet)&); + +void CPPJini_BuildMethod(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + const Handle(TCollection_HAsciiString)& methodName, + const Standard_Integer nbmeth); + +void CPPJini_Enum(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Enum)& anEnum, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile); + +// EDL variables +// +Standard_CString +VJClass = "%Class", + VJTICIncludes = "%TICIncludes", + VJInherits = "%Inherits", + VJTICPublicmets = "%TICPublicmets", + VJTICPublicfriends = "%TICPublicfriends", + VJTICProtectedmets = "%TICProtectedmets", + VJTICProtectedfields = "%TICProtectedfields", + VJTICPrivatemets = "%TICPrivatemets", + VJTICPrivatefriends = "%TICPrivatefriends", + VJTICDefines = "%TICDefines", + VJTICUndefines = "%TICUndefines", + VJTICPrivatefields = "%TICPrivatefields", +VJVirtual = "%Virtual", +VJReturn = "%Return", +VJMethodName = "%MethodName", + VJArgument = "%Arguments", +VJMetSpec = "%MetSpec", +VJMethod = "%Method", + VJMBody = "%MBody", + VJDName = "%DName", + VJDValue = "%DValue", + VJIClass = "%IClass", + VJCxxFile = "CxxFile", + VJLxxFile = "LxxFile", + VJoutClass = "%outClass", +VJNb = "%Nb", + VJValues = "%Values", + VJSupplement = "%Supplement", + VJMethods = "%Methods", +VJAncestors = "%Ancestors", +VJFullPath = "%FullPath", +VJMethodHeader = "%MethodHeader", +VJConstructorHeader = "%ConstructorHeader", + VJTICSuppMethod = "%TICSuppMethod", +VJInterface = "%Interface", +VJNbConstr = "%NbConstr"; + + +#endif diff --git a/src/CPPJini/CPPJini_Define.hxx b/src/CPPJini/CPPJini_Define.hxx new file mode 100755 index 0000000..5635bee --- /dev/null +++ b/src/CPPJini/CPPJini_Define.hxx @@ -0,0 +1,98 @@ +#ifndef _CPPJini_Define_HeaderFile +#define _CPPJini_Define_HeaderFile + +extern Standard_CString +VJClass, + VJTICIncludes, + VJInherits, + VJTICPublicmets, + VJTICPublicfriends, + VJTICProtectedmets, + VJTICProtectedfields, + VJTICPrivatemets, + VJTICPrivatefriends, + VJTICDefines, + VJTICUndefines, + VJTICPrivatefields, + VJTICSuppMethod, + VJVirtual, + VJReturn, + VJMethodName, + VJArgument, + VJMetSpec, +VJMethod, + VJMBody, + VJDName, + VJDValue, + VJIClass, + VJCxxFile, + VJLxxFile, +VJoutClass, + VJNb, + VJValues, + VJSupplement, + VJMethods, + VJAncestors, +VJFullPath, + VJMethodHeader, + VJConstructorHeader; + +extern Handle(TCollection_HAsciiString) CPPJini_InterfaceName; + +Handle(TCollection_HAsciiString)& CPPJini_TransientRootName(); + +class CPPJini_DataMapOfAsciiStringInteger; +class TColStd_Array1OfInteger; + +void CPPJini_WriteFile(const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& aFileName, + const Standard_CString var); + +void CPPJini_UsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Common)& aCommon, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp); + +void CPPJini_BuildMethod(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + const Handle(TCollection_HAsciiString)& methodName, + const Standard_Integer MethodNumber); + +void CPPJini_Enum(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Enum)& anEnum, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile); + + +void CPPJini_CheckMethod(const Standard_Integer index, + const Handle(TCollection_HAsciiString)& thename, + CPPJini_DataMapOfAsciiStringInteger& themap, + TColStd_Array1OfInteger& theindexes); + + +Standard_Boolean CPPJini_IsCasType(const Handle(TCollection_HAsciiString)& typname); + +Handle(TCollection_HAsciiString) CPPJini_GetFullJavaType(const Handle(TCollection_HAsciiString)& className); + + +Standard_Boolean CPPJini_HaveEmptyConstructor(const Handle(MS_MetaSchema)& aMeta, + const Handle(TCollection_HAsciiString)& aClass, + const Handle(MS_HSequenceOfMemberMet)& methods); + +void CPPJini_MethodBuilder(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(TCollection_HAsciiString)& className, + const Handle(MS_Method)& m, + const Handle(TCollection_HAsciiString)& methodName, + const Standard_Integer nummet); + + +Handle(TCollection_HAsciiString) CPPJini_UnderScoreReplace(const Handle(TCollection_HAsciiString)& name); + + +extern Handle(TCollection_HAsciiString) CPPJini_ErrorArgument; + +enum ExtractionType {CPPJini_COMPLETE,CPPJini_INCOMPLETE,CPPJini_SEMICOMPLETE}; +#endif diff --git a/src/CPPJini/CPPJini_Enum.cxx b/src/CPPJini/CPPJini_Enum.cxx new file mode 100755 index 0000000..7fc2fa1 --- /dev/null +++ b/src/CPPJini/CPPJini_Enum.cxx @@ -0,0 +1,59 @@ +// CLE +// +// 10/1996 +// +#include + +#include + +#include +#include +#include +#include +#include + +#include + +// Extraction of a transient class (inst or std) +// +void CPPJini_Enum(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Enum)& anEnum, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile) +{ + if (anEnum.IsNull()) return; + + Handle(TColStd_HSequenceOfHAsciiString) EnumVal = anEnum->Enums(); + Handle(TCollection_HAsciiString) result, + aFileName; + Standard_Integer i; + + result = new TCollection_HAsciiString(EnumVal->Length()); + + // api->AddVariable("%Nb",result->ToCString()); + api->AddVariable("%Class",anEnum->FullName()->ToCString()); + + result->Clear(); + + for (i = 1; i <= EnumVal->Length(); i++) { + api->AddVariable("%Value",EnumVal->Value(i)->ToCString()); + Handle(TCollection_HAsciiString) number = new TCollection_HAsciiString(i-1); + api->AddVariable("%Number",number->ToCString()); + api->Apply("%aValue","EnumValueDef"); + result->AssignCat(api->GetVariableValue("%aValue")); + } + + api->AddVariable("%Values",result->ToCString()); + + api->Apply("%outClass","EnumJAVA"); + + aFileName = new TCollection_HAsciiString(api->GetVariableValue("%FullPath")); + aFileName->AssignCat(anEnum->FullName()); + aFileName->AssignCat(".java"); + + CPPJini_WriteFile(api,aFileName,"%outClass"); + outfile->Append(aFileName); +} + + + diff --git a/src/CPPJini/CPPJini_General.edl b/src/CPPJini/CPPJini_General.edl new file mode 100755 index 0000000..781fcd9 --- /dev/null +++ b/src/CPPJini/CPPJini_General.edl @@ -0,0 +1,131 @@ +-- File: CPPExt_Template.edl +-- Author: Kernel (CLE) +-- History: Tue Sep 19 17:25:59 1995 Kernel Creation +-- Copyright: Matra Datavision 1995 +-- Purpose: C++ extractor + +@verboseoff; + + +-- ============== +-- misc templates +-- ============== + +@template Include(%Interface,%IClass) is +$import %Interface.%IClass; +@end; + +@template IncludeJCas(%IClass) is +$import jcas.%IClass; +@end; + +@template IncludeCPlus(%IClass) is +$#include <%IClass.hxx> +@end; + +@template Define(%DName,%DValue) is +$#define %DName %DValue +@end; + +@template Undefine(%DName) is +$#undef %DName +@end; + +@template ShortDec(%Interface,%IClass) is +$import %Interface.%IClass; +@end; + +@template ShortDecJCas(%IClass) is +$import jcas.%IClass; +@end; + +-- ============================================== +-- Methods templates +-- ============================================== + +@template ConstructorHeader(%Class,%Arguments,%ArgsInCall,%NbMet) is +$public %Class(%Arguments) { +$ %Class_Create_%NbMet(%ArgsInCall); +$} +$ +$private final native void %Class_Create_%NbMet(%Arguments); +$ +@end; + +@template EmptyConstructorHeader(%Class) is +$public %Class() { +$} +$ +@end; + +@template MethodHeader(%Virtual,%Return,%MethodName,%Arguments) is +$native public %Virtual %Return %MethodName(%Arguments); +@end; + +@template OverloadMethodHeader(%Class,%Virtual,%Return,%MethodName,%Arguments,%ArgsInCall,%NbMet,%RetMode) is +$%Virtual public %Return %MethodName(%Arguments) { +$ %RetMode %Class_%MethodName_%NbMet(%ArgsInCall); +$} +$ +$private %Virtual native %Return %Class_%MethodName_%NbMet(%Arguments); +$ +@end; + +@template MethodTemplateDef(%Method,%MBody) is +$%Method +${ +$jcas_Locking alock(env); +${ +$try { +$%MBody +$} +$catch (Standard_Failure) { +$ Standard_SStream Err; +$ Err << Standard_Failure::Caught(); +$ Err << (char) 0; +$ jcas_ThrowException(env,Err.rdbuf()->str()); +$} +$} +$alock.Release(); +$} +$ +@end; + +@template MethodTemplateDefOBJS(%Method,%MBody) is +$%Method +${ +$jcas_Locking alock(env); +${ +$OS_ESTABLISH_FAULT_HANDLER; +$try { +$%MBody +$} +$catch (Standard_Failure) { +$ Standard_SStream Err; +$ Err << Standard_Failure::Caught(); +$ Err << (char) 0; +$ jcas_ThrowException(env,Err.rdbuf()->str()); +$} +$OS_END_FAULT_HANDLER; +$} +$alock.Release(); +$} +$ +@end; + +@template EmptyDestructorTemplate(%Class) is +$~%Class(); +@end; + +@template FullEmptyHandleDestructorTemplate(%Class) is +$Handle_%Class::~Handle_%Class() {} +@end; + +@template FullEmptyDestructorTemplate(%Class) is +$%Class::~%Class() {} +@end; + + +@template EnumValueDef(%Class,%Value,%Number) is +$public final static int %Value = %Number; +@end; diff --git a/src/CPPJini/CPPJini_MPV.cxx b/src/CPPJini/CPPJini_MPV.cxx new file mode 100755 index 0000000..19a371a --- /dev/null +++ b/src/CPPJini/CPPJini_MPV.cxx @@ -0,0 +1,267 @@ +// CLE +// +// 10/1995 +// +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +#include + +Handle(TCollection_HAsciiString)& CPPJini_MPVRootName(); + +void CPPJini_MethodUsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Method)& aMethod, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp); + +// Extraction of .cxx for handled object +// +void CPPJini_MPVDerivated(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Class)& aClass, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const Handle(TColStd_HSequenceOfHAsciiString)& inclist, + const Handle(TColStd_HSequenceOfHAsciiString)& supplement) +{ + Handle(TCollection_HAsciiString) publics = new TCollection_HAsciiString; + Standard_Integer i; + + api->AddVariable("%Class",aClass->FullName()->ToCString()); + + for (i = 1; i <= inclist->Length(); i++) { + if (!inclist->Value(i)->IsSameString(aClass->FullName())) { + api->AddVariable("%IClass",inclist->Value(i)->ToCString()); + api->Apply("%Includes","IncludeCPlus"); + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + + api->AddVariable("%Includes",publics->ToCString()); + publics->Clear(); + + + for (i = 1; i <= supplement->Length(); i++) { + publics->AssignCat(supplement->Value(i)); + } + + api->AddVariable("%Methods",publics->ToCString()); + publics->Clear(); + + + api->AddVariable("%Class",aClass->FullName()->ToCString()); + + api->Apply("%outClass","ValueClassClientCXX"); + + // we write the .cxx of this class + // + Handle(TCollection_HAsciiString) aFile = new TCollection_HAsciiString(api->GetVariableValue("%FullPath")); + + aFile->AssignCat(CPPJini_InterfaceName); + aFile->AssignCat("_"); + aFile->AssignCat(aClass->FullName()); + aFile->AssignCat("_java.cxx"); + + CPPJini_WriteFile(api,aFile,"%outClass"); + + outfile->Append(aFile); +} + + +// Extraction of a transient class (inst or std) +// +void CPPJini_MPVClass(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Class)& aClass, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const ExtractionType MustBeComplete, + const Handle(MS_HSequenceOfMemberMet)& theMetSeq) +{ + Handle(MS_StdClass) theClass = Handle(MS_StdClass)::DownCast(aClass); + Handle(TColStd_HSequenceOfHAsciiString) List = new TColStd_HSequenceOfHAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) incp = new TColStd_HSequenceOfHAsciiString; + + if (!theClass.IsNull()) { + Standard_Integer i; + Handle(MS_HSequenceOfMemberMet) methods; + Handle(TCollection_HAsciiString) publics = new TCollection_HAsciiString; + Handle(TCollection_HAsciiString) SuppMethod = new TCollection_HAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) Supplement = new TColStd_HSequenceOfHAsciiString; + + // we create the inheritance + // + if (theClass->GetInheritsNames()->Length() == 0) { + api->AddVariable("%Inherits",CPPJini_MPVRootName()->ToCString()); + } + else { + List->Append(theClass->GetInheritsNames()->Value(1)); + api->AddVariable("%Inherits",CPPJini_GetFullJavaType(theClass->GetInheritsNames()->Value(1))->ToCString()); + + } + + api->AddVariable("%Class",theClass->FullName()->ToCString()); + + if (MustBeComplete == CPPJini_SEMICOMPLETE) { + methods = theMetSeq; + } + else if (MustBeComplete == CPPJini_COMPLETE) { + methods = theClass->GetMethods(); + } + + + Standard_Boolean mustCreateEmptyConst = !CPPJini_HaveEmptyConstructor(aMeta,theClass->FullName(),methods); + + + if (MustBeComplete != CPPJini_INCOMPLETE) { + CPPJini_DataMapOfAsciiStringInteger mapnames; + + TColStd_Array1OfInteger theindexes(1,methods->Length()); + theindexes.Init(0); + + for (i = 1; i <= methods->Length(); i++) { + CPPJini_CheckMethod(i,methods->Value(i)->Name(),mapnames,theindexes); + } + + for (i = 1; i <= methods->Length(); i++) { + CPPJini_BuildMethod(aMeta,api,theClass->FullName(),methods->Value(i),methods->Value(i)->Name(),theindexes(i)); + if (!api->GetVariableValue("%Method")->IsSameString(CPPJini_ErrorArgument)) { + + if ((theClass->Deferred() && methods->Value(i)->IsKind(STANDARD_TYPE(MS_Construc))) + || methods->Value(i)->IsProtected() + || methods->Value(i)->Private()) { + // nothing + } + else { + CPPJini_MethodUsedTypes(aMeta,methods->Value(i),List,incp); + publics->AssignCat(api->GetVariableValue(VJMethod)); + CPPJini_MethodBuilder(aMeta,api,aClass->FullName(),methods->Value(i),methods->Value(i)->Name(),theindexes(i)); + Supplement->Append(api->GetVariableValue(VJMethod)); + } + } + } + } + + api->AddVariable("%Class",theClass->FullName()->ToCString()); + + if (mustCreateEmptyConst) { + api->Apply(VJMethod,"EmptyConstructorHeader"); + publics->AssignCat(api->GetVariableValue(VJMethod)); + } + + + Handle(TCollection_HAsciiString) namefinal = new TCollection_HAsciiString("Java_"); + namefinal->AssignCat(CPPJini_InterfaceName); + namefinal->AssignCat("_"); + namefinal->AssignCat(CPPJini_UnderScoreReplace(theClass->FullName())); + namefinal->AssignCat("_FinalizeValue"); + + api->AddVariable("%MethodName",namefinal->ToCString()); + + api->Apply(VJMethod,"FinalizeForValue"); + Supplement->Append(api->GetVariableValue(VJMethod)); + + api->AddVariable("%Methods",publics->ToCString()); + + publics->Clear(); + + if (MustBeComplete != CPPJini_INCOMPLETE) { + + for (i = 1; i <= List->Length(); i++) { + if (!List->Value(i)->IsSameString(theClass->FullName())) { + api->AddVariable("%IClass",List->Value(i)->ToCString()); + if (CPPJini_IsCasType(List->Value(i))) { + api->Apply("%Includes","IncludeJCas"); + } + else { + api->Apply("%Includes","Include"); + } + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + + + for (i = 1; i <= incp->Length(); i++) { + if (!incp->Value(i)->IsSameString(theClass->FullName())) { + api->AddVariable("%IClass",incp->Value(i)->ToCString()); + if (CPPJini_IsCasType(incp->Value(i))) { + api->Apply("%Includes","ShortDecJCas"); + } + else { + api->Apply("%Includes","ShortDec"); + } + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + } + + api->AddVariable("%Includes",publics->ToCString()); + + // we create the inheritance + // + if (theClass->GetInheritsNames()->Length() == 0) { + api->AddVariable("%Inherits",CPPJini_MPVRootName()->ToCString()); + } + else { + api->AddVariable("%Inherits",CPPJini_GetFullJavaType(theClass->GetInheritsNames()->Value(1))->ToCString()); + } + + api->AddVariable("%Class",theClass->FullName()->ToCString()); + + api->Apply("%outClass","ValueClassClientJAVA"); + + // we write the .hxx of this class + // + Handle(TCollection_HAsciiString) aFile = new TCollection_HAsciiString(api->GetVariableValue("%FullPath")); + + aFile->AssignCat(theClass->FullName()); + aFile->AssignCat(".java"); + + CPPJini_WriteFile(api,aFile,"%outClass"); + + outfile->Append(aFile); + + CPPJini_MPVDerivated(aMeta,api,aClass,outfile,incp,Supplement); + } + else { + ErrorMsg << "CPPJini" << "CPPJini_TransientClass - the class is NULL..." << endm; + Standard_NoSuchObject::Raise(); + } +} + diff --git a/src/CPPJini/CPPJini_Package.cxx b/src/CPPJini/CPPJini_Package.cxx new file mode 100755 index 0000000..ad62b45 --- /dev/null +++ b/src/CPPJini/CPPJini_Package.cxx @@ -0,0 +1,215 @@ +// CLE +// +// 10/1995 +// +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include + +void CPPJini_MethodUsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Method)& aMethod, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp); + +void CPPJini_PackageDerivated(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Package)& aPackage, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const Handle(TColStd_HSequenceOfHAsciiString)& inclist, + const Handle(TColStd_HSequenceOfHAsciiString)& supplement) +{ + Handle(TCollection_HAsciiString) publics = new TCollection_HAsciiString; + Standard_Integer i; + + // the name must be _ + // + api->AddVariable("%Class",aPackage->Name()->ToCString()); + + for (i = 1; i <= inclist->Length(); i++) { + if (!inclist->Value(i)->IsSameString(aPackage->Name())) { + api->AddVariable("%IClass",inclist->Value(i)->ToCString()); + api->Apply("%Includes","IncludeCPlus"); + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + + api->AddVariable("%Includes",publics->ToCString()); + publics->Clear(); + + for (i = 1; i <= supplement->Length(); i++) { + publics->AssignCat(supplement->Value(i)); + } + + api->AddVariable("%Methods",publics->ToCString()); + publics->Clear(); + + + api->AddVariable("%Class",aPackage->Name()->ToCString()); + + api->Apply("%outClass","PackageClientCXX"); + + // we write the .cxx of this class + // + Handle(TCollection_HAsciiString) aFile = new TCollection_HAsciiString(api->GetVariableValue("%FullPath")); + + aFile->AssignCat(CPPJini_InterfaceName); + aFile->AssignCat("_"); + aFile->AssignCat(aPackage->Name()); + aFile->AssignCat("_java.cxx"); + + CPPJini_WriteFile(api,aFile,"%outClass"); + + outfile->Append(aFile); + +} + + +// Extraction of a package +// +void CPPJini_Package(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Package)& aPackage, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const ExtractionType mustBeComplete, + const Handle(MS_HSequenceOfExternMet)& theMetSeq) +{ + if (!aPackage.IsNull()) { + Standard_Integer i; + + Handle(MS_HSequenceOfExternMet) methods; + Handle(TCollection_HAsciiString) publics = new TCollection_HAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) Supplement = new TColStd_HSequenceOfHAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) List = new TColStd_HSequenceOfHAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) incp = new TColStd_HSequenceOfHAsciiString; + + + // the name must be _ + // + api->AddVariable("%Class",aPackage->Name()->ToCString()); + + if (mustBeComplete == CPPJini_SEMICOMPLETE) { + methods = theMetSeq; + } + else if (mustBeComplete == CPPJini_COMPLETE) { + methods = aPackage->Methods(); + } + + // extraction of the methods + // + if (mustBeComplete != CPPJini_INCOMPLETE) { + if (methods->Length() > 0) { + CPPJini_DataMapOfAsciiStringInteger mapnames; + + TColStd_Array1OfInteger theindexes(1,methods->Length()); + theindexes.Init(0); + + + for (i = 1; i <= methods->Length(); i++) { + CPPJini_CheckMethod(i,methods->Value(i)->Name(),mapnames,theindexes); + } + + for (i = 1; i <= methods->Length(); i++) { + CPPJini_BuildMethod(aMeta,api,aPackage->Name(),methods->Value(i),methods->Value(i)->Name(),theindexes(i)); + + if (!api->GetVariableValue("%Method")->IsSameString(CPPJini_ErrorArgument)) { + + CPPJini_MethodUsedTypes(aMeta,methods->Value(i),List,incp); + publics->AssignCat(api->GetVariableValue(VJMethod)); + CPPJini_MethodBuilder(aMeta,api,aPackage->Name(),methods->Value(i),methods->Value(i)->Name(),theindexes(i)); + Supplement->Append(api->GetVariableValue(VJMethod)); + } + } + } + } + + api->AddVariable("%Methods",publics->ToCString()); + + publics->Clear(); + + + for (i = 1; i <= List->Length(); i++) { + if (!List->Value(i)->IsSameString(aPackage->Name())) { + api->AddVariable("%IClass",List->Value(i)->ToCString()); + if (CPPJini_IsCasType(List->Value(i))) { + api->Apply("%Includes","IncludeJCas"); + } + else { + api->Apply("%Includes","Include"); + } + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + + for (i = 1; i <= incp->Length(); i++) { + if (!incp->Value(i)->IsSameString(aPackage->Name())) { + api->AddVariable("%IClass",incp->Value(i)->ToCString()); + if (CPPJini_IsCasType(incp->Value(i))) { + api->Apply("%Includes","ShortDecJCas"); + } + else { + api->Apply("%Includes","ShortDec"); + } + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + + api->AddVariable("%Includes",publics->ToCString()); + + api->Apply(VJoutClass,"PackageClientJAVA"); + + // we write the .hxx of this class + // + Handle(TCollection_HAsciiString) aFile = new TCollection_HAsciiString(api->GetVariableValue(VJFullPath)); + + aFile->AssignCat(aPackage->Name()); + aFile->AssignCat(".java"); + + CPPJini_WriteFile(api,aFile,VJoutClass); + + outfile->Append(aFile); + + CPPJini_PackageDerivated(aMeta,api,aPackage,outfile,incp,Supplement); + } + else { + ErrorMsg << "CPPJini" << "CPPJini_Package - the package is NULL..." << endm; + Standard_NoSuchObject::Raise(); + } +} + diff --git a/src/CPPJini/CPPJini_Template.edl b/src/CPPJini/CPPJini_Template.edl new file mode 100755 index 0000000..5af2e8c --- /dev/null +++ b/src/CPPJini/CPPJini_Template.edl @@ -0,0 +1,542 @@ +-- File: CPPJini_Template.edl +-- Author: Kernel (CLE) +-- History: Tue Dec 19 08:22:43 1995 Kernel Creation +-- Copyright: Matra Datavision 1995 + + +@template TransientRootClientJAVA(%Interface) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$import jcas.Object; +$ +$public class Standard_Transient extends jcas.Object { +$ +$ static { +$ System.loadLibrary("%Interface"); +$ } +$ +$ +$} +@end; + +@template StorableRootClientJAVA(%Interface) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$import jcas.Object; +$ +$public class Standard_Storable extends jcas.Object { +$ +$ static { +$ System.loadLibrary("%Interface"); +$ } +$ +$} +@end; + +@template MemoryRootClientJAVA(%Interface) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$import jcas.Object; +$import %Interface.Standard_Transient; +$ +$public class MMgt_TShared extends %Interface.Standard_Transient { +$ +$ static { +$ System.loadLibrary("%Interface"); +$ } +$ +$} +@end; + +@template TransientClassClientJAVA(%Interface,%Class,%Inherits,%Includes,%Methods) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$import jcas.Object; +$import %Inherits; +$%Includes +$ +$public class %Class extends %Inherits { +$ +$ static { +$ System.loadLibrary("%Interface"); +$ } +$ +$%Methods +$ +$ +$} +@end; + +@template TransientClassClientCXX(%Interface,%Class,%Methods,%Includes) is +$// Copyright (C) 1991,1995 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$ +$#include <%Interface_%Class.h> +$#include <%Class.hxx> +$#include +$#include +$#include +$#include +$ +$%Includes +$ +$extern "C" { +$%Methods +$} +@end; + +@template ValueClassClientJAVA(%Interface,%Class,%Inherits,%Includes,%Methods) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$import jcas.Object; +$import %Inherits; +$%Includes +$ +$public class %Class extends %Inherits { +$ +$ static { +$ System.loadLibrary("%Interface"); +$ } +$ +$%Methods +$ +$native static void FinalizeValue(long anHID); +$ +$public void finalize() { +$ FinalizeValue(HID); +$} +$ +$} +@end; + +@template ValueClassClientCXX(%Interface,%Class,%Methods,%Includes) is +$// Copyright (C) 1991,1995 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$ +$#include <%Interface_%Class.h> +$#include <%Class.hxx> +$#include +$#include +$#include +$#include +$ +$%Includes +$ +$extern "C" { +$%Methods +$} +@end; + +@template PackageClientJAVA(%Interface,%Class,%Includes,%Methods) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$%Includes +$ +$public class %Class { +$ +$ static { +$ System.loadLibrary("%Interface"); +$ } +$ +$%Methods +$ +$ +$} +@end; + +@template PackageClientCXX(%Interface,%Class,%Methods,%Includes) is +$// Copyright (C) 1991,1995 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$ +$ +$#include <%Interface_%Class.h> +$#include <%Class.hxx> +$#include +$#include +$#include +$#include +$ +$%Includes +$ +$extern "C" { +$%Methods +$} +@end; + +@template EnumJAVA(%Interface,%Class,%Values) is +$// Java Native Class from Cas.Cade +$// Copyright (C) 1991,1999 by +$// +$// MATRA DATAVISION, FRANCE +$// +$// This software is furnished in accordance with the terms and conditions +$// of the contract and with the inclusion of the above copyright notice. +$// This software or any other copy thereof may not be provided or otherwise +$// be made available to any other person. No title to an ownership of the +$// software is hereby transferred. +$// +$// At the termination of the contract, the software and all copies of this +$// software must be deleted. +$// +$ +$ +$package %Interface; +$ +$ +$public class %Class extends jcas.Standard_Enumeration { +$ +$%Values +$ +$ +$} +@end; + +-- method header + +@template CreateMethodDec(%MethodName) is +$ +$ +$JNIEXPORT void JNICALL %MethodName (JNIEnv *env, jobject theobj\^ +@end; + +@template InstMethodDec(%MethodName,%Return) is +$ +$ +$JNIEXPORT %Return JNICALL %MethodName (JNIEnv *env, jobject theobj\^ +@end; + +@template ClassMethodDec(%MethodName,%ClassName,%Return) is +$ +$ +$JNIEXPORT %Return JNICALL %MethodName (JNIEnv *env, jclass\^ +@end; + +@template PackMethodDec(%MethodName,%ClassName,%Return) is +$ +$ +$JNIEXPORT %Return JNICALL %MethodName (JNIEnv *env, jclass\^ +@end; + + +@template MethodArg(%TypeName,%ArgName) is +$, %TypeName %ArgName\^ +@end; + + +-- argument transfert + +@template TransientGetValue(%ClassName,%ArgName) is +$Handle(%ClassName) the_%ArgName; +$ if ( %ArgName ) the_%ArgName = *((Handle(%ClassName)*) jcas_GetHandle(env,%ArgName)); +@end; + +@template ValueGetValue(%ClassName,%ArgName) is +$%ClassName* the_%ArgName = (%ClassName*) jcas_GetHandle(env,%ArgName); +@end; + +@template CStringGetValue(%ArgName) is +$Standard_CString the_%ArgName = jcas_ConvertToCString(env,%ArgName); +@end; + +@template StringGetValue(%ArgName) is +$Standard_ExtString the_%ArgName = jcas_ConvertToExtString(env,%ArgName); +@end; + +@template BooleanGetValue(%ArgName) is +$Standard_Boolean the_%ArgName = jcas_GetBoolean(env,%ArgName); +@end; + +@template RealGetValue(%ArgName) is +$Standard_Real the_%ArgName = jcas_GetReal(env,%ArgName); +@end; + +@template CharacterGetValue(%ArgName) is +$Standard_Character the_%ArgName = jcas_GetCharacter(env,%ArgName); +@end; + +@template IntegerGetValue(%ArgName) is +$Standard_Integer the_%ArgName = jcas_GetInteger(env,%ArgName); +@end; + +@template ExtCharacterGetValue(%ArgName) is +$Standard_ExtCharacter the_%ArgName = jcas_GetExtCharacter(env,%ArgName); +@end; + +@template ByteGetValue(%ArgName) is +$Standard_Byte the_%ArgName = jcas_GetByte(env,%ArgName); +@end; + +@template ShortRealGetValue(%ArgName) is +$Standard_ShortReal the_%ArgName = jcas_GetShortReal(env,%ArgName); +@end; + +@template StringBufferGetValue(%ArgName) is +$Standard_ExtString the_%ArgName = jcas_ConvertSBToExtString(env,%ArgName); +@end; + +@template ThisTransientGetValue(%ClassName) is +$Handle(%ClassName) the_this = *((Handle(%ClassName)*) jcas_GetHandle(env,theobj)); +@end; + +@template ThisValueGetValue(%ClassName) is +$%ClassName* the_this = (%ClassName*) jcas_GetHandle(env,theobj); +@end; + + +-- out argument + +@template TransientSetValue(%ClassName,%ArgName) is +$Handle(%ClassName)* theprevious_%ArgName = (Handle(%ClassName)*) jcas_GetHandle(env,%ArgName); +$if (theprevious_%ArgName) delete theprevious_%ArgName; +$Handle(%ClassName)* thenew_%ArgName = new Handle(%ClassName); +$(*thenew_%ArgName) = the_%ArgName; +$jcas_SetHandle(env,%ArgName,thenew_%ArgName); +@end; + +@template CStringSetValue(%ArgName) is +$jcas_SetCStringValue(env,%ArgName,the_%ArgName); +@end; + +@template BooleanSetValue(%ArgName) is +$jcas_SetBoolean(env,%ArgName,the_%ArgName); +@end; + +@template RealSetValue(%ArgName) is +$jcas_SetReal(env,%ArgName,the_%ArgName); +@end; + +@template CharacterSetValue(%ArgName) is +$jcas_SetCharacter(env,%ArgName,the_%ArgName); +@end; + +@template IntegerSetValue(%ArgName) is +$jcas_SetInteger(env,%ArgName,the_%ArgName); +@end; + +@template ExtCharacterSetValue(%ArgName) is +$jcas_SetExtCharacter(env,%ArgName,the_%ArgName); +@end; + +@template ByteSetValue(%ArgName) is +$jcas_SetByte(env,%ArgName,the_%ArgName); +@end; + +@template ShortRealSetValue(%ArgName) is +$jcas_SetShortReal(env,%ArgName,the_%ArgName); +@end; + +@template StringBufferSetValue(%ArgName) is +$jcas_SetExtStringToStringBuffer(env,%ArgName,the_%ArgName); +@end; + +-- templates for call + + +@template ClassMethodCall(%MethodName,%ClassName,%ArgsInCall) is +$%ClassName::%MethodName(%ArgsInCall)\^ +@end; + +@template PackMethodCall(%MethodName,%ClassName,%ArgsInCall) is +$%ClassName::%MethodName(%ArgsInCall)\^ +@end; + +@template InstMethodCall(%MethodName,%ClassName,%ArgsInCall) is +$the_this->%MethodName(%ArgsInCall)\^ +@end; + +-- constructors + +@template ValueCreateMethodCall(%ClassName,%ArgsInCall) is +$%ClassName* theret = new %ClassName(%ArgsInCall); +$jcas_SetHandle(env,theobj,theret); +@end; + +@template TransientCreateMethodCall(%ClassName,%ArgsInCall) is +$Handle(%ClassName)* theret = new Handle(%ClassName); +$*theret = new %ClassName(%ArgsInCall); +$jcas_SetHandle(env,theobj,theret); +@end; + +-- return type + +@template ReturnHandle(%ClassName,%MethodCall,%FromInterface) is +$Handle(%ClassName)* theret = new Handle(%ClassName); +$*theret = %MethodCall; +$jobject thejret = jcas_CreateObject(env,"%FromInterface/%ClassName",theret); +@end; + +@template ReturnValueMagic(%ClassName,%MethodCall,%FromInterface) is +$%ClassName* theret = new %ClassName(%MethodCall); +$jobject thejret = jcas_CreateObject(env,"%FromInterface/%ClassName",theret); +@end; + +@template ReturnValueRef(%ClassName,%MethodCall,%FromInterface) is +$const %ClassName& theret = %MethodCall; +$jobject thejret = jcas_CreateObject(env,"%FromInterface/%ClassName",&theret); +@end; + +@template ReturnValueEmpty(%ClassName,%MethodCall,%FromInterface) is +$%ClassName* theret = new %ClassName(); +$*theret = %MethodCall; +$jobject thejret = jcas_CreateObject(env,"%FromInterface/%ClassName",theret); +@end; + +@template ReturnValueMalloc(%ClassName,%MethodCall,%FromInterface) is +$%ClassName *theret = ((%ClassName *) malloc(sizeof(%ClassName))); +$*theret = %MethodCall; +$jobject thejret = jcas_CreateObject(env,"%FromInterface/%ClassName",theret); +@end; + +@template ReturnCString(%MethodCall) is +$Standard_CString sret = %MethodCall; +$jclass CLSret = env->FindClass("jcas/Standard_CString"); +$jobject thejret = env->AllocObject(CLSret); +$jcas_SetCStringValue(env,thejret,sret); +@end; + +@template ReturnString(%MethodCall) is +$Standard_ExtString sret = %MethodCall; +$jstring thejret = jcas_ConvertTojstring(env,sret); +@end; + +-- finalize for MPV types + +@template FinalizeForValue(%Class,%MethodName) is +$ +$ +$JNIEXPORT void JNICALL %MethodName(JNIEnv *, jclass, jlong theid) +${ +$if (theid) { +$ %Class* theobj = (%Class*) theid; +$ delete theobj; +$} +$} +$ +@end; + diff --git a/src/CPPJini/CPPJini_Transient.cxx b/src/CPPJini/CPPJini_Transient.cxx new file mode 100755 index 0000000..da7b38b --- /dev/null +++ b/src/CPPJini/CPPJini_Transient.cxx @@ -0,0 +1,257 @@ +// CLE +// +// 10/1995 +// +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include + +void CPPJini_MethodUsedTypes(const Handle(MS_MetaSchema)& aMeta, + const Handle(MS_Method)& aMethod, + const Handle(TColStd_HSequenceOfHAsciiString)& List, + const Handle(TColStd_HSequenceOfHAsciiString)& Incp); + +// Extraction of a transient handle +// + +// Extraction of .cxx for handled object +// +void CPPJini_TransientDerivated(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Class)& aClass, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const Handle(TColStd_HSequenceOfHAsciiString)& inclist, + const Handle(TColStd_HSequenceOfHAsciiString)& supplement, + const ExtractionType MustBeComplete) +{ + Handle(TCollection_HAsciiString) publics = new TCollection_HAsciiString; + Standard_Integer i; + + // the name must be __ + // + api->AddVariable("%Class",aClass->FullName()->ToCString()); + + if (MustBeComplete != CPPJini_INCOMPLETE) { + for (i = 1; i <= inclist->Length(); i++) { + if (!inclist->Value(i)->IsSameString(aClass->FullName())) { + api->AddVariable("%IClass",inclist->Value(i)->ToCString()); + api->Apply("%Includes","IncludeCPlus"); + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + } + + api->AddVariable("%Includes",publics->ToCString()); + publics->Clear(); + + if (MustBeComplete != CPPJini_INCOMPLETE) { + for (i = 1; i <= supplement->Length(); i++) { + publics->AssignCat(supplement->Value(i)); + } + } + + api->AddVariable("%Methods",publics->ToCString()); + publics->Clear(); + + // we create the inheritance + // + if (aClass->FullName()->IsSameString(MS::GetTransientRootName())) { + api->AddVariable("%Inherits",CPPJini_GetFullJavaType(CPPJini_TransientRootName())->ToCString()); + } + else { + api->AddVariable("%Inherits",CPPJini_GetFullJavaType(aClass->GetInheritsNames()->Value(1))->ToCString()); + } + + api->AddVariable("%Class",aClass->FullName()->ToCString()); + + api->Apply("%outClass","TransientClassClientCXX"); + + // we write the .cxx of this class + // + Handle(TCollection_HAsciiString) aFile = new TCollection_HAsciiString(api->GetVariableValue("%FullPath")); + + aFile->AssignCat(CPPJini_InterfaceName); + aFile->AssignCat("_"); + aFile->AssignCat(aClass->FullName()); + aFile->AssignCat("_java.cxx"); + + CPPJini_WriteFile(api,aFile,"%outClass"); + + outfile->Append(aFile); +} + + +// Extraction of a transient class (inst or std) +// +void CPPJini_TransientClass(const Handle(MS_MetaSchema)& aMeta, + const Handle(EDL_API)& api, + const Handle(MS_Class)& aClass, + const Handle(TColStd_HSequenceOfHAsciiString)& outfile, + const ExtractionType MustBeComplete, + const Handle(MS_HSequenceOfMemberMet)& theMetSeq) +{ + Handle(MS_StdClass) theClass = Handle(MS_StdClass)::DownCast(aClass); + + if (!theClass.IsNull()) { + Standard_Integer i; + Handle(MS_HSequenceOfMemberMet) methods; + Handle(TCollection_HAsciiString) publics = new TCollection_HAsciiString; + Handle(TCollection_HAsciiString) SuppMethod = new TCollection_HAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) Supplement = new TColStd_HSequenceOfHAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) List = new TColStd_HSequenceOfHAsciiString; + Handle(TColStd_HSequenceOfHAsciiString) incp = new TColStd_HSequenceOfHAsciiString; + + // we create the inheritance + // + if (theClass->FullName()->IsSameString(MS::GetTransientRootName())) return; + + api->AddVariable("%Class",theClass->FullName()->ToCString()); + + if (MustBeComplete == CPPJini_SEMICOMPLETE) { + methods = theMetSeq; + } + else if (MustBeComplete == CPPJini_COMPLETE){ + methods = theClass->GetMethods(); + } + + Standard_Boolean mustCreateEmptyConst = !CPPJini_HaveEmptyConstructor(aMeta,theClass->FullName(),methods); + + if (MustBeComplete != CPPJini_INCOMPLETE) { + if (methods->Length() > 0) { + CPPJini_DataMapOfAsciiStringInteger mapnames; + + TColStd_Array1OfInteger theindexes(1,methods->Length()); + theindexes.Init(0); + + + for (i = 1; i <= methods->Length(); i++) { + CPPJini_CheckMethod(i,methods->Value(i)->Name(),mapnames,theindexes); + } + + for (i = 1; i <= methods->Length(); i++) { + CPPJini_BuildMethod(aMeta,api,theClass->FullName(),methods->Value(i),methods->Value(i)->Name(),theindexes(i)); + if (!api->GetVariableValue("%Method")->IsSameString(CPPJini_ErrorArgument)) { + + if ((theClass->Deferred() && methods->Value(i)->IsKind(STANDARD_TYPE(MS_Construc))) + || methods->Value(i)->IsProtected() + || methods->Value(i)->Private()) { + // nothing + } + else { + CPPJini_MethodUsedTypes(aMeta,methods->Value(i),List,incp); + publics->AssignCat(api->GetVariableValue(VJMethod)); + CPPJini_MethodBuilder(aMeta,api,aClass->FullName(),methods->Value(i),methods->Value(i)->Name(),theindexes(i)); + Supplement->Append(api->GetVariableValue(VJMethod)); + } + } + } + } + } + + if (mustCreateEmptyConst) { + api->Apply(VJMethod,"EmptyConstructorHeader"); + publics->AssignCat(api->GetVariableValue(VJMethod)); + } + + api->AddVariable("%Methods",publics->ToCString()); + + publics->Clear(); + + if (MustBeComplete != CPPJini_INCOMPLETE) { + + for (i = 1; i <= List->Length(); i++) { + if (!List->Value(i)->IsSameString(theClass->FullName())) { + api->AddVariable("%IClass",List->Value(i)->ToCString()); + if (CPPJini_IsCasType(List->Value(i))) { + api->Apply("%Includes","IncludeJCas"); + } + else { + api->Apply("%Includes","Include"); + } + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + + + for (i = 1; i <= incp->Length(); i++) { + if (!incp->Value(i)->IsSameString(theClass->FullName())) { + api->AddVariable("%IClass",incp->Value(i)->ToCString()); + if (CPPJini_IsCasType(incp->Value(i))) { + api->Apply("%Includes","ShortDecJCas"); + } + else { + api->Apply("%Includes","ShortDec"); + } + publics->AssignCat(api->GetVariableValue("%Includes")); + } + } + } + + api->AddVariable("%Includes",publics->ToCString()); + + // we create the inheritance + // + api->AddVariable("%Inherits",CPPJini_GetFullJavaType(theClass->GetInheritsNames()->Value(1))->ToCString()); + + api->AddVariable("%Class",theClass->FullName()->ToCString()); + + api->Apply("%outClass","TransientClassClientJAVA"); + + // we write the .java of this class + // + Handle(TCollection_HAsciiString) aFile = new TCollection_HAsciiString(api->GetVariableValue("%FullPath")); + + aFile->AssignCat(theClass->FullName()); + aFile->AssignCat(".java"); + + CPPJini_WriteFile(api,aFile,"%outClass"); + + outfile->Append(aFile); + + + CPPJini_TransientDerivated(aMeta,api,aClass,outfile,incp,Supplement,MustBeComplete); + } + else { + ErrorMsg << "CPPJini" << "CPPJini_TransientClass - the class is NULL..." << endm; + Standard_NoSuchObject::Raise(); + } +} + diff --git a/src/CPPJini/FILES b/src/CPPJini/FILES new file mode 100755 index 0000000..f4eb812 --- /dev/null +++ b/src/CPPJini/FILES @@ -0,0 +1,10 @@ +CPPJini.cxx +CPPJini_Transient.cxx +CPPJini_Package.cxx +CPPJini_Enum.cxx +CPPJini_MPV.cxx +CPPJini_Template.edl +CPPJini_General.edl +CPPJini.hxx +CPPJini_Define.hxx +FILES -- 2.39.5