• 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
Advice on converting this C++ code to Objective-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Advice on converting this C++ code to Objective-C
  • From: Dave <email@hidden>
  • Date: Thu, 03 Nov 2011 09:29:24 +0000

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











 _______________________________________________
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

  • Follow-Ups:
    • Re: Advice on converting this C++ code to Objective-C
      • From: Andreas Grosam <email@hidden>
    • Re: Advice on converting this C++ code to Objective-C
      • From: Jean-Daniel Dupas <email@hidden>
    • Re: Advice on converting this C++ code to Objective-C
      • From: Jean-Denis MUYS <email@hidden>
  • Prev by Date: Re: Symbol Navigator
  • Next by Date: Re: Static Analyzer Problems
  • Previous by thread: Re: Xcode 4.2 Interface Builder can't rename objects?
  • Next by thread: Re: Advice on converting this C++ code to Objective-C
  • Index(es):
    • Date
    • Thread