//TH-Header //***************************************************************************************** // Copyright (c) 2001 Michael Kurz // All rights reserved. // If you want to use this source in your applications conatct: // // $FileName : cCPPDataConverter.pkg // $ProjectName : Converts lines from C Structures or Classes to VDF TYPE-END_TYPE // $Author : Michael Kurz // $Created : 29.06.2001 09:09 // // Contents: // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd Use cSrcLineParser.pkg Use cTypeConverter.Pkg Class cCPPDataConverter Is a Array //Insert your Properties here. Procedure Construct_Object Forward Send Construct_Object Object oSrcLineParser Is a cSrcLineParser End_Object Property Integer piMaxNameLength 0 Property Integer piMaxTypeLength 0 // Name and type of a line. Property String psMemberName "" Property String psType "" // Name of the type Property String psName "" End_Procedure //Finish object construction Procedure End_Construct_Object Forward Send End_Construct_Object End_Procedure // Add a Line to the Converter. Procedure AddItem String sLine Set value Item (Item_Count(Self)) To sLine End_Procedure // Runs throuht the lines and catched the length of the parts. Procedure PrecalculateLenth Integer hoID hoArray iC isPointer String sLine String sNewLine Integer iMaxNameLen iMaxTypeLen iTmpLen Move (oSrcLineParser(Self)) To hoID For iC From 0 To (Item_Count(Self)-1) Get value Item iC To sLine // Get the value of the Line Move (LTrim(sLine)) To sLine // Trim it Move (Replace(";",sLine,"")) To sLine // now ";" needed in VDF. If "*" In sLine Begin // Check if the line is a pointer Move 1 To isPointer // ... Move (Replace("*",sLine,"")) To sLine End Else Move 0 To isPointer Send ParseLine To hoID sLine // Parse it. Send ConvertTypeEx (Value(hoID,0)) (Value(hoID,1)) // Convert type and name. // Check the max.length of the name. Move (Length(psMemberName(Self))) To iTmpLen If iTmpLen Gt iMaxNameLen Move iTmpLen To iMaxNameLen // Length until name // Check the max.length of the type. Move "" To sNewLine If isPointer Append sNewLine "Pointer" // Either its a Pointer of the normal Datatype. Else Append sNewLine (psType(Self)) // Append the Datatype of the Field Move (Length(sNewLine)) To iTmpLen If iTmpLen Gt iMaxTypeLen Move iTmpLen To iMaxTypeLen End Set piMaxNameLength To iMaxNameLen Set piMaxTypeLength To iMaxTypeLen End_Procedure // Gets the length of an Array out of the name of a member. Function GiveArrayLen String sName Returns String String sTmp If "[" In sName Begin Move (Left(sName,Pos("[",sName))) To sTmp Set psMemberName To (Left(sTmp,Length(sTmp)-1)) Move (Replace(sTmp,sName,"")) To sTmp Move (Left(sTmp,Pos("]",sTmp)-1)) To sTmp Function_Return sTmp End End_Function // Converts a Datatype-> If no conversion was possible // return the SRC value. Procedure ConvertTypeEx String sSrc String sName Returns String String sRet Move (ConvertCToDFType(sSrc)) To sRet Set psMemberName To sName If (Uppercase(sRet)) Eq "CHAR" If "[" In sName Begin // Only with charactertypes. Append sRet " " (GiveArrayLen(Self,sName)) End Set psType To sRet End_Procedure // Converts the contents of the Array to a specific Field Entries. Procedure Convert Integer iStruct hoID hoArray iC isPointer iMaxNameLen iMaxTypeLen String sLine sStruct sStructName String sNewLine Send PrecalculateLenth // Should calc the max lengths of Name and type. Get piMaxNameLength To iMaxNameLen Get piMaxTypeLength To iMaxTypeLen Set psName To "" Move (oSrcLineParser(Self)) To hoID For iC From 0 To (Item_Count(Self)-1) Get value Item iC To sLine // Get the value of the Line Move (LTrim(sLine)) To sLine // Trim it Move (Replace(";",sLine,"")) To sLine // now ";" needed in VDF. If "*" In sLine Begin // Check if the line is a pointer Move 1 To isPointer // ... Move (Replace("*",sLine,"")) To sLine End Else Move 0 To isPointer Send ParseLine To hoID sLine // Parse it. If (Uppercase(Value(hoID,0))) Eq "CLASS" Begin Set psName To (Value(hoID,1)) Move "TYPE " To sNewLine Append sNewLine (psName(Self)) Set value Item iC To sNewLine End Else If "TYPEDEF" In (Uppercase(sLine)) Begin Set Value Item iC To "TYPE @PH@" End Else If (Left(Trim(sLine),1)) Eq "}" Begin If (psName(Self)) Eq "" If (Value(hoID,1)) Ne "" ; Set psName To (Value(hoID,1)) Set Value Item iC To "END_TYPE" End Else Begin Move (Replace("{",sLine,"")) To sLine Move (Replace("}",sLine,"")) To sLine If (Trim(sLine)) Ne "" Begin Move "" To sNewLine // Reset the string Send ConvertTypeEx (Value(hoID,0)) (Value(hoID,1)) // Convert type and name. If (psMemberName(Self)) Ne "" If (psType(Self)) Ne "" Begin If isPointer Set psType To "Pointer" // If a Pointer -> type should be too. Append sNewLine " Field @PH@." // Everyline starts with an Indenttion and the Field... Append sNewLine (Pad(psMemberName(Self),iMaxNameLen)) " as " // Append the name of the Field Append sNewLine (Pad(psType(Self),iMaxTypeLen)) // Append the Datatype of the Field Append sNewLine " /" "/" (psComment(hoID)) // Append the comment Append sNewLine " (" (Value(hoID,0)) ")" // Append the original Datatype. Set value Item iC To sNewLine // Set the New line. End End Else Set value Item iC To "" End End // Inserts the name if one is found. If (psName(Self)) Ne "" Begin For iC From 0 To (Item_Count(Self)-1) Get value Item iC To sLine If "@PH@" In sLine Begin Move (Replace("@PH@",sLine,psName(Self))) To sLine Set value Item iC To sLine End End End End_Procedure End_Class