• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Advice on converting this C++ code to Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on converting this C++ code to Objective-C


  • Subject: Re: Advice on converting this C++ code to Objective-C
  • From: Dave <email@hidden>
  • Date: Thu, 03 Nov 2011 10:57:12 +0000

There are a number of reasons, but the main one is that they want to add new features to the App and it's very expensive to get engineers that do C++ and Objective-C. 

It isn't that it's C++ code as such it's that it is replacing OS level methods with something not as good, any speed increases etc. that the OS provides will be missed. Plus they want an iPad version and I know that there are OS level platform specific optimizations that we won't get using the C++ "core".

For Instance there is a CList class that is basically a poor mans NSArray/NSMutableArray. The code is inefficient compared to using the OS. Same goes for the Transformation stuff

Also, the C++ isn't documented very well and there are no NIB files. 

There are loads of reasons to convert it really. 

All the Best
Dave

On 3 Nov 2011, at 10:20, Jean-Daniel Dupas wrote:

Maybe this is a silly question, but what the point about converting it to Obj-C ? 
C++ is more suitable for some task (like abstracting matrix and vector), and Obj-C is more suitable for other tasks. 
Compilers support mixing both languages for ages, so just use C++ CMatrix and CVector in your ObjC classes when needed.

Le 3 nov. 2011 à 10:29, Dave a écrit :

Hi,

I've inherited a project that has a "core" of C++ files. Basically, it looks like some standard methods have been cut and pasted into the project.

I've been converting the higher level code to Objective-C and it's going quite well, but I'm at the point where I now need to address some of the low level classes in the core.

Here are the files in question:

sysplatform.h

sysafx.h
sysafx.cpp

syscore.h
syscore.cpp

sysgraphics.h
sysgraphics.cpp

sysmaths.h
sysmaths.cpp

sysstopwatch.h
sysstopwatch.cpp

sysxml.h
sysxml.cpp

Firstly, do the files mean anything to anyone or are they just the names chosen by the last programmer?

Secondly, the sysgraphics module is a class that interfaces to Core Graphics, when it's initialized a CGContextRef is passed in.

Here is a shortened version of the class definition:
class CGraphics
{
public:
    CGContextRef &FRef;
    CMatrix FMatrix;
    float FAlpha;
    
public:
    CGraphics(CGContextRef &ref, const CMatrix &m);
    CGContextRef GetContext() const { return FRef; }
         
    void WorldToScreen(float &x, float &y);
    void WorldToScreen(float &x, float &y, float &w, float &h);
     void DrawLine(float x1, float y1, float x2, float y2);
    void DrawBox(float x, float y, float w, float h); 
    void FillBox(float x, float y, float w, float h);
    void DrawTextInBox(float x, float y, float w, float h, const char *str);
    void DrawImage(CGImageRef image, const CGRect &rect);
};

And here is a sample method that uses CMatix:

void CGraphics::WorldToScreen(float &x, float &y)
{
    CVector3 a(x, y, 0);
    a = FMatrix.Transform(a);
    x = a.x;
    y = a.y;
}

Can anyone offer any ideas or suggestions on the best course of action to convert this?

My initial idea is to make a corresponding Objective-C for "CGraphics" and then change all references CGraphics to use the new class.

Does this sound like a good idea?

Once that was done, I'd have the CMatrix, CVector2 and CVector3 to remaining in C++, which I want gone!!! Also one thing that is going to make it difficult is that there operator overrides in operation which will mean expanding out loads of code in Objective-C. So I could either convert them to Objective-C but it strikes me that CoreGraphics has all this built in. 

Would it be better to use this? I'm a bit concerned that the results won't be the same and also I'm not sure what to do for the best.

Any suggestions or idea greatly appreciated.

All the Best
Dave


-- Jean-Daniel







 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Advice on converting this C++ code to Objective-C (From: Dave <email@hidden>)
 >Re: Advice on converting this C++ code to Objective-C (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: Advice on converting this C++ code to Objective-C
  • Next by Date: Re: Advice on converting this C++ code to Objective-C
  • Previous by thread: Re: Advice on converting this C++ code to Objective-C
  • Next by thread: Re: Advice on converting this C++ code to Objective-C
  • Index(es):
    • Date
    • Thread