C++ to PB

Windows specific forum
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

C++ to PB

Post by chippy73 »

Anybody help with this ?

I need to convert this:- ***Array[] to PB. This is a pointer to a pointer to a pointer to an array.

Also this:- something->that This is something to do with objects.


Any help welcomed.

Alan
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

the first one would be something like PeekL(PeekL(PeekL(...)))

the second one... ain't got a clue
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Re: C++ to PB

Post by LarsG »

chippy73 wrote:Anybody help with this ?

I need to convert this:- ***Array[] to PB. This is a pointer to a pointer to a pointer to an array.
No.. that's just nasty!! :twisted:
chippy73 wrote: Also this:- something->that This is something to do with objects.
That's a way of accessing a field or procedure in a class (structure)... OO stuff..
PB is not able to do this stuff easily (yet), without mocking around like crazy with interfaces and stuff...
I guess you'll have to look up Interface in the help file..
Basically what you have to do is to make an interface with integer fields,
which in turn have to be used as pointers to a procedure, then to be used in a structure..
(I hope I got it right)

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: C++ to PB

Post by traumatic »

It's pretty much impossible to translate this without any further code.

something->that can be used as a reference to a pointer to a structure or to a class.
If it's not a pointer to a class it may simply be *something\that in PB.
Good programmers don't comment their code. It was hard to write, should be hard to read.
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post by chippy73 »

This is typical of the code that I am trying to convert to PB.....

Code: Select all

 Idx=0
    While Idx<SymbolsPerLine
      Idx=Idx+1
      Symbol[Idx]->ClearCorrection()
      Symbol[Idx]->Scan_Init()
    Wend
    For(Idx=0: Idx<SymbolsPerLine: Idx++)
        CorrectSymbol(Idx)
        Idx=0
        While Idx<SymbolsPerLine
          Idx=Idx+1
          Symbol[Idx]->AddCorrection(Weight);
          Symbol[Idx]->Decode()
        Wend
Hope that helps

Alan
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Ok, then it's like LarsG said => OOP :)
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

For ***Array use somthing like this:

Code: Select all

Structure StaticArray
  Values.l[5]
EndStructure

DefType.StaticArray SA
SA\Values[0] = 1
SA\Values[1] = 2
SA\Values[2] = 4
SA\Values[3] = 8
SA\Values[4] = 16

*ThirdPointer = @SA
*SecondPointer = @*ThirdPointer
*FirstPointer = @*SecondPointer

;Note that we are using a pointer (begins with *) so only two peeks are needed to go 3 pointers deep.
*ReferencingSA.StaticArray =  PeekL(PeekL(*FirstPointer)) 
Debug *ReferencingSA\Values[0]
Debug *ReferencingSA\Values[1]
Debug *ReferencingSA\Values[2]
Debug *ReferencingSA\Values[3]
Debug *ReferencingSA\Values[4]
Debug *ReferencingSA\Values[5]

Structure ThreePointersDeep
For something->that you'll want to use an Interface.

If you have the class declaration then converting this to an Interface isn't too difficult. Take a look at the following posts:

An example using interfaces.
viewtopic.php?t=9553&highlight=ipbfriendly

An example of converting some complex C++ classes to PB:
viewtopic.php?t=11827&highlight=winnie
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post by chippy73 »

Thanks everyone for your comments.

It's getting very complex for my poor ol' "grey cells". I need to sleep on it and take another look tomorrow.

Thanks again.

Alan
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
Post Reply